feat(install): add --keepsrc to keep pkg/ and src/ directories (#2272)

* feat(install): add --nocleanbuild to keep pkg/ and src/ directories for
AUR packages

Providing this flag during installation of AUR packages allows for keeping
the src/ and pkg/ directories produced my makepkg. If the user wants to
delete the directories, they can either select to cleanBuild in the
cleanmenu or run the installation without the --nocleanbuild flag (yay
will only remove the directories if the package is rebuilt)

* fix(completion): simplify description for --nocleanbuild in fish

This makes the description consistent with the descriptions in the
man page, --help, and zsh completion.

* refactor(install): Rename --nocleanbuild to --keepsrc

This naming scheme is more familiar to users since it is the name of the
flag in Paru.

---------

Co-authored-by: jguer <me@jguer.space>
This commit is contained in:
Joey Holtzmanandjguer authored and GitHub committed 2023-09-18 09:21:42 +02:00
1 parent e60ccdf8b7
commit 04c76a404e
16 files changed
+248 -70

No files matched your search

+5 -1
View File
@@ -32,7 +32,11 @@ func (e *ErrDownloadSource) Unwrap() error {
func downloadPKGBUILDSource(ctx context.Context,
cmdBuilder exe.ICmdBuilder, pkgBuildDir string, installIncompatible bool,
) error {
args := []string{"--verifysource", "--skippgpcheck", "-Ccf"}
args := []string{"--verifysource", "--skippgpcheck", "-f"}
if !cmdBuilder.GetKeepSrc() {
args = append(args, "-Cc")
}
if installIncompatible {
args = append(args, "--ignorearch")
+47 -9
View File
@@ -33,6 +33,10 @@ func (z *TestMakepkgBuilder) BuildMakepkgCmd(ctx context.Context, dir string, ex
assert.Contains(z.test, cmd.String(), z.want)
}
if z.GetKeepSrc() {
assert.NotContains(z.test, cmd.String(), "-Cc")
}
if z.wantDir != "" {
assert.Equal(z.test, z.wantDir, cmd.Dir)
}
@@ -46,20 +50,54 @@ func (z *TestMakepkgBuilder) Show(cmd *exec.Cmd) error {
return z.showError
}
func (z *TestMakepkgBuilder) GetKeepSrc() bool {
return z.parentBuilder.KeepSrc
}
// GIVEN 1 package
// WHEN downloadPKGBUILDSource is called
// THEN 1 call should be made to makepkg with the specified parameters and dir
func Test_downloadPKGBUILDSource(t *testing.T) {
t.Parallel()
cmdBuilder := &TestMakepkgBuilder{
parentBuilder: &exe.CmdBuilder{MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg"},
test: t,
want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -Ccf",
wantDir: "/tmp/yay-bin",
type testCase struct {
desc string
keepSrc bool
want string
}
testCases := []testCase{
{
desc: "keepsrc",
keepSrc: true,
want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -f",
},
{
desc: "nokeepsrc",
keepSrc: false,
want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -f -Cc",
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.desc, func(td *testing.T) {
cmdBuilder := &TestMakepkgBuilder{
parentBuilder: &exe.CmdBuilder{
MakepkgConfPath: "/etc/not.conf",
MakepkgFlags: []string{"--nocheck"},
MakepkgBin: "makepkg",
KeepSrc: tc.keepSrc,
},
test: t,
want: tc.want,
wantDir: "/tmp/yay-bin",
}
err := downloadPKGBUILDSource(context.Background(), cmdBuilder, filepath.Join("/tmp", "yay-bin"), false)
assert.NoError(t, err)
assert.Equal(t, 1, int(cmdBuilder.passes))
})
}
err := downloadPKGBUILDSource(context.Background(), cmdBuilder, filepath.Join("/tmp", "yay-bin"), false)
assert.NoError(t, err)
assert.Equal(t, 1, int(cmdBuilder.passes))
}
// GIVEN 1 package
@@ -70,7 +108,7 @@ func Test_downloadPKGBUILDSourceError(t *testing.T) {
cmdBuilder := &TestMakepkgBuilder{
parentBuilder: &exe.CmdBuilder{MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg"},
test: t,
want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -Ccf",
want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -f -Cc",
wantDir: "/tmp/yay-bin",
showError: &exec.ExitError{},
}