Imported Upstream version 2.4.2
[scm/test.git] / test / test-config.sh
1 #!/usr/bin/env bash
2
3 . "test/testlib.sh"
4
5 begin_test "default config"
6 (
7   set -e
8   reponame="default-config"
9   mkdir $reponame
10   cd $reponame
11   git init
12   git remote add origin "$GITSERVER/$reponame"
13   git lfs env | tee env.log
14   grep "Endpoint=$GITSERVER/$reponame.git/info/lfs (auth=none)" env.log
15
16   git config --file=.gitconfig lfs.url http://gitconfig-file-ignored
17   git config --file=.lfsconfig lfs.url http://lfsconfig-file
18   git config --file=.lfsconfig lfs.http://lfsconfig-file.access lfsconfig
19   git lfs env | tee env.log
20   grep "Endpoint=http://lfsconfig-file (auth=lfsconfig)" env.log
21
22   git config --file=.lfsconfig --unset lfs.url
23   git config --file=.lfsconfig --unset lfs.http://lfsconfig-file.access
24
25   # new endpoint url from local git config
26   # access setting no longer applied
27   git config lfs.url http://local-lfsconfig
28   git lfs env | tee env.log
29   grep "Endpoint=http://local-lfsconfig (auth=none)" env.log
30
31   # add the access setting to lfsconfig
32   git config --file=.lfsconfig lfs.http://local-lfsconfig.access lfsconfig
33   git lfs env | tee env.log
34   grep "Endpoint=http://local-lfsconfig (auth=lfsconfig)" env.log
35
36   git config --file=.lfsconfig --unset lfs.http://local-lfsconfig.access
37
38   # add the access setting to git config
39   git config lfs.http://local-lfsconfig.access gitconfig
40   git lfs env | tee env.log
41   grep "Endpoint=http://local-lfsconfig (auth=gitconfig)" env.log
42 )
43 end_test
44
45 begin_test "extension config"
46 (
47   set -e
48
49   git config --global lfs.extension.env-test.clean "env-test-clean"
50   git config --global lfs.extension.env-test.smudge "env-test-smudge"
51   git config --global lfs.extension.env-test.priority 0
52
53   reponame="extension-config"
54   mkdir $reponame
55   cd $reponame
56   git init
57
58   expected0="Extension: env-test
59     clean = env-test-clean
60     smudge = env-test-smudge
61     priority = 0"
62
63   [ "$expected0" = "$(git lfs ext)" ]
64
65   # any git config takes precedence over .lfsconfig
66   git config --global --unset lfs.extension.env-test.priority
67
68   git config --file=.lfsconfig lfs.extension.env-test.clean "file-env-test-clean"
69   git config --file=.lfsconfig lfs.extension.env-test.smudge "file-env-test-smudge"
70   git config --file=.lfsconfig lfs.extension.env-test.priority 1
71   cat .lfsconfig
72   expected1="Extension: env-test
73     clean = env-test-clean
74     smudge = env-test-smudge
75     priority = 1"
76
77   [ "$expected1" = "$(GIT_TRACE=5 git lfs ext)" ]
78
79   git config lfs.extension.env-test.clean "local-env-test-clean"
80   git config lfs.extension.env-test.smudge "local-env-test-smudge"
81   git config lfs.extension.env-test.priority 2
82   expected2="Extension: env-test
83     clean = local-env-test-clean
84     smudge = local-env-test-smudge
85     priority = 2"
86
87   [ "$expected2" = "$(git lfs ext)" ]
88 )
89 end_test
90
91 begin_test "url alias config"
92 (
93   set -e
94
95   mkdir url-alias
96   cd url-alias
97
98   git init
99
100   # When more than one insteadOf strings match a given URL, the longest match is used.
101   git config url."http://wrong-url/".insteadOf alias
102   git config url."http://actual-url/".insteadOf alias:
103   git config lfs.url alias:rest
104   git lfs env | tee env.log
105   grep "Endpoint=http://actual-url/rest (auth=none)" env.log
106 )
107 end_test
108
109 begin_test "ambiguous url alias"
110 (
111   set -e
112
113   mkdir url-alias-ambiguous
114   cd url-alias-ambiguous
115
116   git init
117
118   git config url."http://actual-url/".insteadOf alias:
119   git config url."http://dupe-url".insteadOf alias:
120   git config lfs.url alias:rest
121   git config -l | grep url
122
123   git lfs env 2>&1 | tee env2.log
124   grep "WARNING: Multiple 'url.*.insteadof'" env2.log
125 )
126 end_test
127
128 begin_test "url alias must be prefix"
129 (
130   set -e
131
132   mkdir url-alias-bad
133   cd url-alias-bad
134
135   git init
136
137   git config url."http://actual-url/".insteadOf alias:
138   git config lfs.url badalias:rest
139   git lfs env | tee env.log
140   grep "Endpoint=badalias:rest (auth=none)" env.log
141 )
142 end_test
143
144 begin_test "config: ignoring unsafe lfsconfig keys"
145 (
146   set -e
147
148   reponame="config-unsafe-lfsconfig-keys"
149   git init "$reponame"
150   cd "$reponame"
151
152   # Insert an 'unsafe' key into this repository's '.lfsconfig'.
153   git config --file=.lfsconfig core.askpass unsafe
154
155   git lfs env 2>&1 | tee status.log
156
157   grep "WARNING: These unsafe lfsconfig keys were ignored:" status.log
158   grep "  core.askpass" status.log
159 )
160 end_test