From ea7367ec08167ccc61fccc48844512b30d7ed177 Mon Sep 17 00:00:00 2001 From: Ryan D McGuire Date: Fri, 1 Mar 2024 12:53:13 -0500 Subject: [PATCH] Don't die for bad aliases --- README.md | 1 + cmd/util_fzf.go | 2 +- go.mod | 4 ++-- go.sum | 2 -- internal/cache/projects_alias.go | 11 ++++++++--- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3fc593d..10d9a55 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,7 @@ Use "gitlab-project-manager cache [command] --help" for more information about a ## TODO +- [ ] Don't check remote up unless necessary (project list shouldn't require it) - [ ] Rename to git-project-manager - [ ] Move module from gitlab.sweetwater.com to github.com/rdmcguire - [ ] Add flag for clone timeout for large repos diff --git a/cmd/util_fzf.go b/cmd/util_fzf.go index 7462caa..9c26afb 100644 --- a/cmd/util_fzf.go +++ b/cmd/util_fzf.go @@ -111,7 +111,7 @@ ALIASES: for _, a := range aliases { for _, p := range projects { // Already have it - if a.ProjectID == p.ID && a.Remote == p.Remote { + if p == nil || (a.ProjectID == p.ID && a.Remote == p.Remote) { continue ALIASES } } diff --git a/go.mod b/go.mod index a9c588a..77d96e8 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( atomicgo.dev/cursor v0.2.0 // indirect atomicgo.dev/keyboard v0.2.9 // indirect atomicgo.dev/schedule v0.1.0 // indirect - code.gitea.io/sdk/gitea v0.17.1 // indirect + code.gitea.io/sdk/gitea v0.17.1 // direct dario.cat/mergo v1.0.0 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect @@ -37,7 +37,7 @@ require ( github.com/go-git/go-billy/v5 v5.5.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/google/go-github/v58 v58.0.0 // indirect + github.com/google/go-github/v58 v58.0.0 // direct github.com/google/go-querystring v1.1.0 // indirect github.com/gookit/color v1.5.4 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect diff --git a/go.sum b/go.sum index f1e7be5..f71004d 100644 --- a/go.sum +++ b/go.sum @@ -360,8 +360,6 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= diff --git a/internal/cache/projects_alias.go b/internal/cache/projects_alias.go index 3eacb4c..6ce3954 100644 --- a/internal/cache/projects_alias.go +++ b/internal/cache/projects_alias.go @@ -27,6 +27,9 @@ func (c *Cache) GetProjectAliasStrings(project *projects.Project) []string { } func (c *Cache) GetProjectStringWithAliases(project *projects.Project) string { + if project == nil { + return "" + } aliases := c.GetProjectAliasStrings(project) return fmt.Sprintf("%s (%s) -> %s", project.Name, @@ -102,9 +105,11 @@ func (c *Cache) GetProjectByAlias(alias *ProjectAlias) *projects.Project { func (c *Cache) GetProjectAliases(project *projects.Project) []*ProjectAlias { aliases := make([]*ProjectAlias, 0) - for _, alias := range c.Aliases { - if alias.ProjectID == project.ID { - aliases = append(aliases, alias) + if project != nil { + for _, alias := range c.Aliases { + if alias.ProjectID == project.ID { + aliases = append(aliases, alias) + } } } return aliases