diff --git a/lfsapi/endpoint_finder.go b/lfsapi/endpoint_finder.go index efdd1e80..5861d79f 100644 --- a/lfsapi/endpoint_finder.go +++ b/lfsapi/endpoint_finder.go @@ -335,10 +335,11 @@ func initAliases(e *endpointGitFinder, git config.Environment) { func storeAlias(aliases map[string]string, key string, values []string, suffix string) { for _, value := range values { - if _, ok := aliases[value]; ok { + url := key[len(aliasPrefix) : len(key)-len(suffix)] + if v, ok := aliases[value]; ok && v != url { fmt.Fprintf(os.Stderr, "WARNING: Multiple 'url.*.%s' keys with the same alias: %q\n", suffix, value) } - aliases[value] = key[len(aliasPrefix) : len(key)-len(suffix)] + aliases[value] = url } } diff --git a/t/t-env.sh b/t/t-env.sh index 6347002b..b41e4a30 100755 --- a/t/t-env.sh +++ b/t/t-env.sh @@ -1040,3 +1040,41 @@ UploadTransfers=basic,lfs-standalone-file contains_same_elements "$expected" "$actual" ) end_test + +begin_test "env with duplicate endpoints" +( + set -e + reponame="env-duplicate-endpoints" + unset_vars + mkdir $reponame + cd $reponame + git init + git remote add origin "$GITSERVER/env-origin-remote" + git remote add other "$GITSERVER/env-other-remote" + + touch a.txt + git add a.txt + git commit -m "initial commit" + + cat <>.git/config +[url "https://host.example/domain/"] + insteadOf = git@host.example:domain/ +[url "https://host.example/domain/"] + insteadOf = git@host.example:domain/ +EOF + + git lfs env 2>&1 | tee test.log + if grep 'WARNING.*same alias' test.log + then + exit 1 + fi + + cat <>.git/config +[url "https://somewhere-else.example/domain/"] + insteadOf = git@host.example:domain/ +EOF + + git lfs env 2>&1 | tee test.log + grep 'WARNING.*same alias' test.log +) +end_test