@@ -11,16 +11,25 @@ test_description='Test reference backend URIs'
1111# <backend> is the original ref storage of the repo.
1212# <uri> is the new URI to be set for the ref storage.
1313# <cmd> is the git subcommand to be run in the repository.
14+ # <via> if 'config', set the backend via the 'extensions.refStorage' config.
15+ # if 'env', set the backend via the 'GIT_REFERENCE_BACKEND' env.
1416run_with_uri () {
1517 repo=$1 &&
1618 backend=$2 &&
1719 uri=$3 &&
1820 cmd=$4 &&
21+ via=$5 &&
1922
20- git -C " $repo " config set core.repositoryformatversion 1
21- git -C " $repo " config set extensions.refStorage " $uri " &&
22- git -C " $repo " $cmd &&
23- git -C " $repo " config set extensions.refStorage " $backend "
23+ git -C " $repo " config set core.repositoryformatversion 1 &&
24+ if test " $via " = " env"
25+ then
26+ test_env GIT_REFERENCE_BACKEND=" $uri " git -C " $repo " $cmd
27+ elif test " $via " = " config"
28+ then
29+ git -C " $repo " config set extensions.refStorage " $uri " &&
30+ git -C " $repo " $cmd &&
31+ git -C " $repo " config set extensions.refStorage " $backend "
32+ fi
2433}
2534
2635# Test a repository with a given reference storage by running and comparing
@@ -30,44 +39,57 @@ run_with_uri() {
3039# <repo> is the relative path to the repo to run the command in.
3140# <backend> is the original ref storage of the repo.
3241# <uri> is the new URI to be set for the ref storage.
42+ # <via> if 'config', set the backend via the 'extensions.refStorage' config.
43+ # if 'env', set the backend via the 'GIT_REFERENCE_BACKEND' env.
3344# <err_msg> (optional) if set, check if 'git-refs(1)' failed with the provided msg.
3445test_refs_backend () {
3546 repo=$1 &&
3647 backend=$2 &&
3748 uri=$3 &&
38- err_msg=$4 &&
49+ via=$4 &&
50+ err_msg=$5 &&
51+
3952
40- git -C " $repo " config set core.repositoryformatversion 1 &&
4153 if test -n " $err_msg " ;
4254 then
43- git -C " $repo " config set extensions.refStorage " $uri " &&
44- test_must_fail git -C " $repo " refs list 2> err &&
45- test_grep " $err_msg " err
55+ if test " $via " = " env"
56+ then
57+ test_env GIT_REFERENCE_BACKEND=" $uri " test_must_fail git -C " $repo " refs list 2> err
58+ elif test " $via " = " config"
59+ then
60+ git -C " $repo " config set extensions.refStorage " $uri " &&
61+ test_must_fail git -C " $repo " refs list 2> err &&
62+ test_grep " $err_msg " err
63+ fi
4664 else
4765 git -C " $repo " refs list > expect &&
48- run_with_uri " $repo " " $backend " " $uri " " refs list" > actual &&
66+ run_with_uri " $repo " " $backend " " $uri " " refs list" " $via " > actual &&
4967 test_cmp expect actual
5068 fi
5169}
5270
53- test_expect_success ' URI is invalid' '
71+ methods=" config"
72+ for method in $methods
73+ do
74+
75+ test_expect_success " $method : URI is invalid" '
5476 test_when_finished "rm -rf repo" &&
5577 git init repo &&
56- test_refs_backend repo files "reftable@/home/reftable" \
78+ test_refs_backend repo files "reftable@/home/reftable" "$method" \
5779 "invalid value for ${SQ}extensions.refstorage${SQ}"
5880'
5981
60- test_expect_success ' URI ends with colon' '
82+ test_expect_success " $method : URI ends with colon" '
6183 test_when_finished "rm -rf repo" &&
6284 git init repo &&
63- test_refs_backend repo files "reftable:" \
85+ test_refs_backend repo files "reftable:" "$method" \
6486 "invalid value for ${SQ}extensions.refstorage${SQ}"
6587'
6688
67- test_expect_success ' unknown reference backend' '
89+ test_expect_success " $method : unknown reference backend" '
6890 test_when_finished "rm -rf repo" &&
6991 git init repo &&
70- test_refs_backend repo files "db://.git" \
92+ test_refs_backend repo files "db://.git" "$method" \
7193 "invalid value for ${SQ}extensions.refstorage${SQ}"
7294'
7395
86108 for dir in " $( pwd) /repo/.git" " ./"
87109 do
88110
89- test_expect_success " $read from $to_format backend, $dir dir" '
111+ test_expect_success " $method : $ read from $to_format backend, $dir dir" '
90112 test_when_finished "rm -rf repo" &&
91113 git init --ref-format=$from_format repo &&
92114 (
101123 )
102124 '
103125
104- test_expect_success " $write to $to_format backend, $dir dir" '
126+ test_expect_success " $method : $ write to $to_format backend, $dir dir" '
105127 test_when_finished "rm -rf repo" &&
106128 git init --ref-format=$from_format repo &&
107129 (
113135 git refs migrate --dry-run --ref-format=$to_format >out &&
114136 BACKEND_PATH="$dir/$(sed "s/.* ${SQ}.git\/\(.*\)${SQ}/\1/" out)" &&
115137
116- test_refs_backend . $from_format "$to_format://$BACKEND_PATH" &&
138+ test_refs_backend . $from_format "$to_format://$BACKEND_PATH" "$method" &&
117139
118140 git refs list >expect &&
119- run_with_uri . "$from_format" "$to_format://$BACKEND_PATH" "tag -d 1" &&
141+ run_with_uri . "$from_format" "$to_format://$BACKEND_PATH" \
142+ "tag -d 1" "$method" &&
120143 git refs list >actual &&
121144 test_cmp expect actual &&
122145
123146 git refs list | grep -v "refs/tags/1" >expect &&
124- run_with_uri . "$from_format" "$to_format://$BACKEND_PATH" "refs list" >actual &&
147+ run_with_uri . "$from_format" "$to_format://$BACKEND_PATH" \
148+ "refs list" "$method" >actual &&
125149 test_cmp expect actual
126150 )
127151 '
128152
129- test_expect_success " with worktree and $to_format backend, $dir dir" '
153+ test_expect_success " $method : with worktree and $to_format backend, $dir dir" '
130154 test_when_finished "rm -rf repo wt" &&
131155 git init --ref-format=$from_format repo &&
132156 (
138162 git refs migrate --dry-run --ref-format=$to_format >out &&
139163 BACKEND_PATH="$dir/$(sed "s/.* ${SQ}.git\/\(.*\)${SQ}/\1/" out)" &&
140164
141- git config set core.repositoryformatversion 1 &&
142- git config set extensions.refStorage "$to_format://$BACKEND_PATH " &&
165+ run_with_uri . "$from_format" "$to_format://$BACKEND_PATH" \
166+ "worktree add ../wt 2" "$method " &&
143167
144- git worktree add ../wt 2
145- ) &&
168+ run_with_uri . "$from_format" "$to_format://$BACKEND_PATH" \
169+ "for-each-ref --include-root-refs" "$method" >actual &&
170+ run_with_uri ../wt "$from_format" "$to_format://$BACKEND_PATH" \
171+ "for-each-ref --include-root-refs" "$method" >expect &&
172+ ! test_cmp expect actual &&
146173
147- git -C repo for-each-ref --include-root-refs >expect &&
148- git -C wt for-each-ref --include-root-refs >expect &&
149- ! test_cmp expect actual &&
150-
151- git -C wt rev-parse 2 >expect &&
152- git -C wt rev-parse HEAD >actual &&
153- test_cmp expect actual
174+ run_with_uri . "$from_format" "$to_format://$BACKEND_PATH" \
175+ "rev-parse 2" "$method" >actual &&
176+ run_with_uri ../wt "$from_format" "$to_format://$BACKEND_PATH" \
177+ "rev-parse HEAD" "$method" >expect &&
178+ test_cmp expect actual
179+ )
154180 '
155181 done # closes dir
156182done # closes to_format
157- done # closes from_format
183+ done # closes to_format
184+
185+ done # closes method
158186
159187test_done
0 commit comments