Skip to content

Commit

Permalink
Re-add functionality for Installed and NotInstalled options in the me…
Browse files Browse the repository at this point in the history
…nus (#2233)

* fix(menus): Handle Installed and NotInstalled options correctly in the
menus

This functionality was temporarily removed. This commit adds that
functionality back.

* fix(tests): Mock InstalledRemotePackageNamesFn when necessary
  • Loading branch information
jdholtz committed Jul 6, 2023
1 parent 6dd7933 commit dadc8c0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
11 changes: 8 additions & 3 deletions local_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func TestIntegrationLocalInstall(t *testing.T) {

return nil
},
LocalPackageFn: func(s string) mock.IPackage { return nil },
LocalPackageFn: func(s string) mock.IPackage { return nil },
InstalledRemotePackageNamesFn: func() []string { return []string{} },
}

config := &settings.Configuration{
Expand Down Expand Up @@ -417,6 +418,7 @@ func TestIntegrationLocalInstallNeeded(t *testing.T) {

return nil
},
InstalledRemotePackageNamesFn: func() []string { return []string{} },
}

config := &settings.Configuration{
Expand Down Expand Up @@ -580,6 +582,7 @@ func TestIntegrationLocalInstallGenerateSRCINFO(t *testing.T) {

return nil
},
InstalledRemotePackageNamesFn: func() []string { return []string{} },
}

config := &settings.Configuration{
Expand Down Expand Up @@ -841,7 +844,8 @@ func TestIntegrationLocalInstallWithDepsProvides(t *testing.T) {
SyncSatisfierFn: func(s string) mock.IPackage {
return nil
},
LocalPackageFn: func(s string) mock.IPackage { return nil },
LocalPackageFn: func(s string) mock.IPackage { return nil },
InstalledRemotePackageNamesFn: func() []string { return []string{} },
}

config := &settings.Configuration{
Expand Down Expand Up @@ -980,7 +984,8 @@ func TestIntegrationLocalInstallTwoSrcInfosWithDeps(t *testing.T) {
SyncSatisfierFn: func(s string) mock.IPackage {
return nil
},
LocalPackageFn: func(s string) mock.IPackage { return nil },
LocalPackageFn: func(s string) mock.IPackage { return nil },
InstalledRemotePackageNamesFn: func() []string { return []string{} },
}

config := &settings.Configuration{
Expand Down
7 changes: 4 additions & 3 deletions pkg/menus/clean_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ func anyExistInCache(pkgbuildDirs map[string]string) bool {
return false
}

func CleanFn(ctx context.Context, config *settings.Configuration, w io.Writer, pkgbuildDirsByBase map[string]string) error {
func CleanFn(ctx context.Context, config *settings.Configuration, w io.Writer,
pkgbuildDirsByBase map[string]string, installed mapset.Set[string],
) error {
if len(pkgbuildDirsByBase) == 0 {
return nil // no work to do
}
Expand All @@ -47,8 +49,7 @@ func CleanFn(ctx context.Context, config *settings.Configuration, w io.Writer, p
bases = append(bases, pkg)
}

// TOFIX: empty installed slice means installed filter is disabled
toClean, errClean := selectionMenu(w, pkgbuildDirsByBase, bases, mapset.NewSet[string](),
toClean, errClean := selectionMenu(w, pkgbuildDirsByBase, bases, installed,
gotext.Get("Packages to cleanBuild?"),
settings.NoConfirm, config.AnswerClean, skipFunc)
if errClean != nil {
Expand Down
8 changes: 5 additions & 3 deletions pkg/menus/diff_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func gitHasDiff(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) (bo
return true, nil
}

// Return wether or not we have reviewed a diff yet. It checks for the existence of
// Return whether or not we have reviewed a diff yet. It checks for the existence of
// YAY_DIFF_REVIEW in the git ref-list.
func gitHasLastSeenRef(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) bool {
_, _, err := cmdBuilder.Capture(
Expand Down Expand Up @@ -145,7 +145,9 @@ func updatePkgbuildSeenRef(ctx context.Context, cmdBuilder exe.ICmdBuilder, pkgb
return errMulti.Return()
}

func DiffFn(ctx context.Context, config *settings.Configuration, w io.Writer, pkgbuildDirsByBase map[string]string) error {
func DiffFn(ctx context.Context, config *settings.Configuration, w io.Writer,
pkgbuildDirsByBase map[string]string, installed mapset.Set[string],
) error {
if len(pkgbuildDirsByBase) == 0 {
return nil // no work to do
}
Expand All @@ -155,7 +157,7 @@ func DiffFn(ctx context.Context, config *settings.Configuration, w io.Writer, pk
bases = append(bases, base)
}

toDiff, errMenu := selectionMenu(w, pkgbuildDirsByBase, bases, mapset.NewThreadUnsafeSet[string](), gotext.Get("Diffs to show?"),
toDiff, errMenu := selectionMenu(w, pkgbuildDirsByBase, bases, installed, gotext.Get("Diffs to show?"),
settings.NoConfirm, config.AnswerDiff, nil)
if errMenu != nil || len(toDiff) == 0 {
return errMenu
Expand Down
5 changes: 2 additions & 3 deletions pkg/menus/edit_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func editPkgbuilds(log *text.Logger, pkgbuildDirs map[string]string, bases []str
}

func EditFn(ctx context.Context, cfg *settings.Configuration, w io.Writer,
pkgbuildDirsByBase map[string]string,
pkgbuildDirsByBase map[string]string, installed mapset.Set[string],
) error {
if len(pkgbuildDirsByBase) == 0 {
return nil // no work to do
Expand All @@ -125,8 +125,7 @@ func EditFn(ctx context.Context, cfg *settings.Configuration, w io.Writer,
bases = append(bases, pkg)
}

toEdit, errMenu := selectionMenu(w, pkgbuildDirsByBase, bases,
mapset.NewThreadUnsafeSet[string](),
toEdit, errMenu := selectionMenu(w, pkgbuildDirsByBase, bases, installed,
gotext.Get("PKGBUILDs to edit?"), settings.NoConfirm, cfg.AnswerEdit, nil)
if errMenu != nil || len(toEdit) == 0 {
return errMenu
Expand Down
8 changes: 6 additions & 2 deletions preparer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const (
PreDownloadSourcesHook HookType = "pre-download-sources"
)

type HookFn func(ctx context.Context, config *settings.Configuration, w io.Writer, pkgbuildDirsByBase map[string]string) error
type HookFn func(ctx context.Context, config *settings.Configuration, w io.Writer,
pkgbuildDirsByBase map[string]string, installed mapset.Set[string],
) error

type Hook struct {
Name string
Expand Down Expand Up @@ -214,9 +216,11 @@ func (preper *Preparer) PrepareWorkspace(ctx context.Context, targets []map[stri
return nil, err
}

remoteNames := preper.dbExecutor.InstalledRemotePackageNames()
remoteNamesCache := mapset.NewThreadUnsafeSet(remoteNames...)
for _, hookFn := range preper.hooks {
if hookFn.Type == PreDownloadSourcesHook {
if err := hookFn.Hookfn(ctx, preper.cfg, os.Stdout, pkgBuildDirsByBase); err != nil {
if err := hookFn.Hookfn(ctx, preper.cfg, os.Stdout, pkgBuildDirsByBase, remoteNamesCache); err != nil {
return nil, err
}
}
Expand Down

0 comments on commit dadc8c0

Please sign in to comment.