lfsapi: don't warn about duplicate but identical aliases
Currently, we warn about aliases (e.g., url.*.insteadOf) when there's already an alias for the same URL; that is, when the insteadOf entry matches an existing one. However, in some environments, multiple aliases are defined, but all to the same root URL (the one in the key). In such a case, don't warn, since these aliases are already identical. Do continue to warn if the root URL is different at all, since these are different aliases for the same URL, and add a test for both of these cases.
This commit is contained in:
parent
c3bdc050a1
commit
45511006e3
@ -335,10 +335,11 @@ func initAliases(e *endpointGitFinder, git config.Environment) {
|
|||||||
|
|
||||||
func storeAlias(aliases map[string]string, key string, values []string, suffix string) {
|
func storeAlias(aliases map[string]string, key string, values []string, suffix string) {
|
||||||
for _, value := range values {
|
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)
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
t/t-env.sh
38
t/t-env.sh
@ -1040,3 +1040,41 @@ UploadTransfers=basic,lfs-standalone-file
|
|||||||
contains_same_elements "$expected" "$actual"
|
contains_same_elements "$expected" "$actual"
|
||||||
)
|
)
|
||||||
end_test
|
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 <<EOF >>.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 <<EOF >>.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
|
||||||
|
Loading…
Reference in New Issue
Block a user