2015-10-20 16:31:56 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-07-10 18:48:02 +00:00
|
|
|
. "$(dirname "$0")/testlib.sh"
|
2015-10-20 16:31:56 +00:00
|
|
|
|
|
|
|
begin_test "default config"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
reponame="default-config"
|
|
|
|
mkdir $reponame
|
|
|
|
cd $reponame
|
|
|
|
git init
|
|
|
|
git remote add origin "$GITSERVER/$reponame"
|
|
|
|
git lfs env | tee env.log
|
|
|
|
grep "Endpoint=$GITSERVER/$reponame.git/info/lfs (auth=none)" env.log
|
|
|
|
|
2015-11-16 19:53:01 +00:00
|
|
|
git config --file=.gitconfig lfs.url http://gitconfig-file-ignored
|
|
|
|
git config --file=.lfsconfig lfs.url http://lfsconfig-file
|
2016-04-04 22:38:17 +00:00
|
|
|
git config --file=.lfsconfig lfs.http://lfsconfig-file.access lfsconfig
|
2015-11-16 19:53:01 +00:00
|
|
|
git lfs env | tee env.log
|
2016-04-04 22:38:17 +00:00
|
|
|
grep "Endpoint=http://lfsconfig-file (auth=lfsconfig)" env.log
|
2015-11-16 19:53:01 +00:00
|
|
|
|
2017-04-12 21:29:11 +00:00
|
|
|
git config --file=.lfsconfig --unset lfs.url
|
|
|
|
git config --file=.lfsconfig --unset lfs.http://lfsconfig-file.access
|
|
|
|
|
2016-04-04 22:38:17 +00:00
|
|
|
# new endpoint url from local git config
|
|
|
|
# access setting no longer applied
|
2015-11-16 19:53:01 +00:00
|
|
|
git config lfs.url http://local-lfsconfig
|
|
|
|
git lfs env | tee env.log
|
|
|
|
grep "Endpoint=http://local-lfsconfig (auth=none)" env.log
|
2016-04-04 22:38:17 +00:00
|
|
|
|
|
|
|
# add the access setting to lfsconfig
|
|
|
|
git config --file=.lfsconfig lfs.http://local-lfsconfig.access lfsconfig
|
|
|
|
git lfs env | tee env.log
|
|
|
|
grep "Endpoint=http://local-lfsconfig (auth=lfsconfig)" env.log
|
|
|
|
|
2017-04-12 21:29:11 +00:00
|
|
|
git config --file=.lfsconfig --unset lfs.http://local-lfsconfig.access
|
|
|
|
|
2016-04-04 22:38:17 +00:00
|
|
|
# add the access setting to git config
|
|
|
|
git config lfs.http://local-lfsconfig.access gitconfig
|
|
|
|
git lfs env | tee env.log
|
|
|
|
grep "Endpoint=http://local-lfsconfig (auth=gitconfig)" env.log
|
2015-11-16 19:53:01 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
config: optionally read .lfsconfig from the repository
Currently we only read .lfsconfig from the working tree. This is better
than nothing, but it means that if there's an LFS file that starts with
a name earlier than .lfsconfig, we won't read the proper config file,
and we won't use any LFS remote URLs that are located in that file.
If the file is missing, let's additionally read from the index, if
there's a working tree, and then from HEAD. If the repository is bare,
let's just read from HEAD. This is very similar to what Git does for
.gitmodules.
It does, however, differ in one significant way: Git will read from the
index first if it's doing a checkout, since that might have newer
information. We don't do that here, since it's not totally clear that
we can articulate all the cases where that occurs in Git LFS, but we
explicitly allow for the possibility of changing the behavior in the
future and document the feature accordingly.
We no longer read the file .lfsconfig from a bare repository, but that
we did this in the first place was very questionable and pretty clearly
a bug, so it's intentional that we no longer do.
2020-07-28 19:58:15 +00:00
|
|
|
begin_test "config reads from repository"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
reponame="repository-config"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
mkdir $reponame
|
|
|
|
cd $reponame
|
|
|
|
git init
|
|
|
|
git remote add origin "$GITSERVER/$reponame"
|
|
|
|
git lfs env | tee env.log
|
|
|
|
grep "Endpoint=$GITSERVER/$reponame.git/info/lfs (auth=none)" env.log
|
|
|
|
|
|
|
|
git config --file=.lfsconfig lfs.url http://lfsconfig-file
|
|
|
|
git config --file=.lfsconfig lfs.http://lfsconfig-file.access lfsconfig
|
|
|
|
git add .lfsconfig
|
|
|
|
git commit -m 'Add file'
|
|
|
|
git push origin HEAD
|
|
|
|
|
|
|
|
git checkout -b side
|
|
|
|
git config --file=.lfsconfig lfs.url http://lfsconfig-file-side
|
|
|
|
git config --file=.lfsconfig lfs.http://lfsconfig-file-side.access lfsconfig
|
|
|
|
git add .lfsconfig
|
|
|
|
git commit -m 'Add file for side'
|
|
|
|
git push origin HEAD
|
|
|
|
|
|
|
|
mkdir "../$reponame-2"
|
|
|
|
cd "../$reponame-2"
|
|
|
|
git init
|
|
|
|
git remote add origin "$GITSERVER/$reponame"
|
|
|
|
|
|
|
|
git lfs env | tee env.log
|
|
|
|
grep "Endpoint=$GITSERVER/$reponame.git/info/lfs (auth=none)" env.log
|
|
|
|
|
|
|
|
git fetch origin
|
|
|
|
git symbolic-ref HEAD refs/remotes/origin/side
|
|
|
|
git show "HEAD:.lfsconfig"
|
|
|
|
git lfs env | tee env.log
|
|
|
|
grep "Endpoint=http://lfsconfig-file-side (auth=lfsconfig)" env.log
|
|
|
|
|
|
|
|
git read-tree refs/remotes/origin/main
|
|
|
|
git lfs env | tee env.log
|
|
|
|
grep "Endpoint=http://lfsconfig-file (auth=lfsconfig)" env.log
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "can read LFS file with name before .lfsconfig"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
reponame="early-file-config"
|
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
mkdir $reponame
|
|
|
|
cd $reponame
|
|
|
|
git init
|
|
|
|
git remote add origin "$GITSERVER/$reponame"
|
|
|
|
|
|
|
|
git lfs track "*.bin"
|
|
|
|
git config --file=.lfsconfig lfs.url "$GITSERVER/$reponame.git/info/lfs"
|
|
|
|
|
|
|
|
echo "abc" > .bin
|
|
|
|
echo "def" > a.bin
|
|
|
|
|
|
|
|
git add .
|
|
|
|
git commit -m "Add files"
|
|
|
|
git push origin HEAD
|
|
|
|
rm -fr .git/lfs/objects
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
git clone "$reponame" "$reponame-2"
|
|
|
|
cd "$reponame-2"
|
|
|
|
grep abc .bin
|
|
|
|
grep def a.bin
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2015-11-16 19:53:01 +00:00
|
|
|
begin_test "extension config"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
git config --global lfs.extension.env-test.clean "env-test-clean"
|
|
|
|
git config --global lfs.extension.env-test.smudge "env-test-smudge"
|
|
|
|
git config --global lfs.extension.env-test.priority 0
|
|
|
|
|
|
|
|
reponame="extension-config"
|
|
|
|
mkdir $reponame
|
|
|
|
cd $reponame
|
|
|
|
git init
|
|
|
|
|
|
|
|
expected0="Extension: env-test
|
|
|
|
clean = env-test-clean
|
|
|
|
smudge = env-test-smudge
|
|
|
|
priority = 0"
|
|
|
|
|
|
|
|
[ "$expected0" = "$(git lfs ext)" ]
|
|
|
|
|
|
|
|
# any git config takes precedence over .lfsconfig
|
|
|
|
git config --global --unset lfs.extension.env-test.priority
|
|
|
|
|
|
|
|
git config --file=.lfsconfig lfs.extension.env-test.clean "file-env-test-clean"
|
|
|
|
git config --file=.lfsconfig lfs.extension.env-test.smudge "file-env-test-smudge"
|
|
|
|
git config --file=.lfsconfig lfs.extension.env-test.priority 1
|
|
|
|
cat .lfsconfig
|
|
|
|
expected1="Extension: env-test
|
|
|
|
clean = env-test-clean
|
|
|
|
smudge = env-test-smudge
|
|
|
|
priority = 1"
|
|
|
|
|
|
|
|
[ "$expected1" = "$(GIT_TRACE=5 git lfs ext)" ]
|
|
|
|
|
|
|
|
git config lfs.extension.env-test.clean "local-env-test-clean"
|
|
|
|
git config lfs.extension.env-test.smudge "local-env-test-smudge"
|
|
|
|
git config lfs.extension.env-test.priority 2
|
|
|
|
expected2="Extension: env-test
|
|
|
|
clean = local-env-test-clean
|
|
|
|
smudge = local-env-test-smudge
|
|
|
|
priority = 2"
|
|
|
|
|
|
|
|
[ "$expected2" = "$(git lfs ext)" ]
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2016-08-12 21:20:46 +00:00
|
|
|
begin_test "url alias config"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
mkdir url-alias
|
|
|
|
cd url-alias
|
|
|
|
|
|
|
|
git init
|
2016-08-12 21:33:54 +00:00
|
|
|
|
|
|
|
# When more than one insteadOf strings match a given URL, the longest match is used.
|
|
|
|
git config url."http://wrong-url/".insteadOf alias
|
2016-08-12 21:20:46 +00:00
|
|
|
git config url."http://actual-url/".insteadOf alias:
|
|
|
|
git config lfs.url alias:rest
|
|
|
|
git lfs env | tee env.log
|
|
|
|
grep "Endpoint=http://actual-url/rest (auth=none)" env.log
|
2016-08-12 22:30:43 +00:00
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
begin_test "ambiguous url alias"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
mkdir url-alias-ambiguous
|
|
|
|
cd url-alias-ambiguous
|
|
|
|
|
|
|
|
git init
|
|
|
|
|
|
|
|
git config url."http://actual-url/".insteadOf alias:
|
|
|
|
git config url."http://dupe-url".insteadOf alias:
|
|
|
|
git config lfs.url alias:rest
|
|
|
|
git config -l | grep url
|
2016-08-12 21:20:46 +00:00
|
|
|
|
2016-08-12 22:30:43 +00:00
|
|
|
git lfs env 2>&1 | tee env2.log
|
|
|
|
grep "WARNING: Multiple 'url.*.insteadof'" env2.log
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
2019-03-01 19:31:45 +00:00
|
|
|
begin_test "multiple config"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
mkdir url-alias-multiple
|
|
|
|
cd url-alias-multiple
|
|
|
|
|
|
|
|
git init
|
|
|
|
|
|
|
|
# When more than one insteadOf strings match a given URL, the longest match is used.
|
|
|
|
git config url."http://wrong-url/".insteadOf alias
|
|
|
|
git config url."http://actual-url/".insteadOf alias:
|
|
|
|
git config --add url."http://actual-url/".insteadOf alias2:
|
|
|
|
git config lfs.url alias:rest
|
|
|
|
git lfs env | tee env.log
|
|
|
|
grep "Endpoint=http://actual-url/rest (auth=none)" env.log
|
|
|
|
|
|
|
|
git config lfs.url alias2:rest
|
|
|
|
git lfs env | tee env.log
|
|
|
|
grep "Endpoint=http://actual-url/rest (auth=none)" env.log
|
|
|
|
)
|
|
|
|
end_test
|
|
|
|
|
|
|
|
|
2016-08-12 22:30:43 +00:00
|
|
|
begin_test "url alias must be prefix"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
mkdir url-alias-bad
|
|
|
|
cd url-alias-bad
|
|
|
|
|
|
|
|
git init
|
|
|
|
|
|
|
|
git config url."http://actual-url/".insteadOf alias:
|
2016-08-12 21:20:46 +00:00
|
|
|
git config lfs.url badalias:rest
|
|
|
|
git lfs env | tee env.log
|
lfsapi: handle SSH hostnames and aliases without users
It's very common for a user to specify an SSH remote that refers to an
alias in their gitconfig file. For example, if a user must use
different SSH keys when pushing to different remotes, setting different
aliases that use those different keys is the simplest and easiest way to
accomplish that goal.
Unfortunately, our parsing logic was broken for SSH remotes that used
bare SSH URLs (that is, without “ssh://”) with a hostname or alias, but
without a username component. The URL parser we used saw the hostname
portion as the scheme of a URL, and we passed through any URLs with
unknown schemes. This led to a failure to push, since we misparsed the
URL as a non-SSH URL and gave up when it also didn't look like an
HTTP(S) URL.
If we get an unknown “scheme” when parsing a URL, check if the URL uses
a remote helper (that is, it contains a double colon), and pass it
through. Otherwise, do what Git does, and assume the URL is in fact an
SSH URL, and handle it accordingly.
We already handle the url.insteadof syntax properly, even if it looks
like a scheme. Add tests that we continue to do so, and for the new
code and all the various permutations mentioned above, and update the
existing integration test to reflect our new parsing strategy.
2018-09-05 21:23:12 +00:00
|
|
|
grep "SSH=badalias:rest" env.log
|
2016-08-12 21:20:46 +00:00
|
|
|
)
|
|
|
|
end_test
|
2017-08-10 23:56:28 +00:00
|
|
|
|
|
|
|
begin_test "config: ignoring unsafe lfsconfig keys"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
reponame="config-unsafe-lfsconfig-keys"
|
|
|
|
git init "$reponame"
|
|
|
|
cd "$reponame"
|
|
|
|
|
|
|
|
# Insert an 'unsafe' key into this repository's '.lfsconfig'.
|
2017-08-11 05:18:00 +00:00
|
|
|
git config --file=.lfsconfig core.askpass unsafe
|
2017-08-10 23:56:28 +00:00
|
|
|
|
2017-10-25 19:23:12 +00:00
|
|
|
git lfs env 2>&1 | tee status.log
|
2017-08-10 23:56:28 +00:00
|
|
|
|
|
|
|
grep "WARNING: These unsafe lfsconfig keys were ignored:" status.log
|
|
|
|
grep " core.askpass" status.log
|
|
|
|
)
|
|
|
|
end_test
|
2021-03-03 19:25:04 +00:00
|
|
|
|
|
|
|
begin_test "config respects include.* directives when GIT_CONFIG is set"
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
|
|
|
mkdir include-directives
|
|
|
|
cd include-directives
|
|
|
|
|
|
|
|
git init
|
|
|
|
|
|
|
|
git config lfs.url "http://some-url/rest"
|
|
|
|
GIT_CONFIG="$(pwd)/.git/config" git lfs env | tee env.log
|
|
|
|
grep "Endpoint=http://some-url/rest (auth=none)" env.log
|
|
|
|
|
|
|
|
git config --file ./.git/b.config url."http://other-url/".insteadOf "http://some-url/"
|
|
|
|
git config include.path "$(pwd)/.git/b.config"
|
|
|
|
GIT_CONFIG="$(pwd)/.git/config" git lfs env | tee env.log
|
|
|
|
grep "Endpoint=http://other-url/rest (auth=none)" env.log
|
|
|
|
)
|
|
|
|
end_test
|