Fix git remote normalization for empty remotes

pull/184/head
Simon Let 3 years ago
parent b3a45c8d47
commit cd611e9ac4
  1. 3
      internal/normalize/normailze.go
  2. 7
      internal/normalize/normalize_test.go
  3. 2
      internal/searchapp/item.go

@ -11,6 +11,9 @@ import (
// GitRemote helper // GitRemote helper
// Returns normalized git remote - valid even on error // Returns normalized git remote - valid even on error
func GitRemote(sugar *zap.SugaredLogger, gitRemote string) string { func GitRemote(sugar *zap.SugaredLogger, gitRemote string) string {
if len(gitRemote) == 0 {
return ""
}
gitRemote = strings.TrimSuffix(gitRemote, ".git") gitRemote = strings.TrimSuffix(gitRemote, ".git")
parsedURL, err := giturls.Parse(gitRemote) parsedURL, err := giturls.Parse(gitRemote)
if err != nil { if err != nil {

@ -37,10 +37,15 @@ func TestGitRemote(t *testing.T) {
one := normalize.GitRemote(sugar, arr[i]) one := normalize.GitRemote(sugar, arr[i])
two := normalize.GitRemote(sugar, arr[j]) two := normalize.GitRemote(sugar, arr[j])
if one != two { if one != two {
t.Fatalf("Normalized git remotes should match for '%s' and '%s'\n -> got: '%s' != '%s'", t.Fatalf("Normalized git remotes should match for '%s' and '%s'\n -> got '%s' != '%s'",
arr[i], arr[j], one, two) arr[i], arr[j], one, two)
} }
} }
} }
} }
empty := normalize.GitRemote(sugar, "")
if len(empty) != 0 {
t.Fatalf("Normalized git remotes for '' should be ''\n -> got '%s'", empty)
}
} }

@ -402,7 +402,7 @@ func NewItemFromRecordForQuery(record recordint.SearchApp, query Query, debug bo
// -> N matches against the command // -> N matches against the command
// -> 1 extra match for the actual directory match // -> 1 extra match for the actual directory match
sameGitRepo := false sameGitRepo := false
if query.gitOriginRemote != "" && query.gitOriginRemote == record.GitOriginRemote { if len(query.gitOriginRemote) != 0 && query.gitOriginRemote == record.GitOriginRemote {
sameGitRepo = true sameGitRepo = true
} }

Loading…
Cancel
Save