t: make many tests depend less on the refs being files

Many tests are very focused on the file system representation of the loose and packed refs code. As there are plans to implement other ref storage systems, let's migrate these tests to a form that test the intent of the refs storage system instead of it internals. This will make clear to readers that these tests do not depend on which ref backend is used. The internals of the loose refs backend are still tested in t1400-update-ref.sh, whereas the tests changed in this patch focus on testing other aspects. This patch just takes care of many low hanging fruits. It does not try to completely solves the issue. Helped-by: Stefan Beller <sbeller@google.com> Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Turner committed May 23, 2018 at 07:25 UTC cbc5cf7ce5112a5c704ce4116b8414c8385d23ca
9 files changed +26 -25
t/lib-t6000.sh
+3 -3
@@ -4,11 +4,11 @@ mkdir -p .git/refs/tags
4
5 >sed.script
6
7 -# Answer the sha1 has associated with the tag. The tag must exist in .git/refs/tags
7 +# Answer the sha1 has associated with the tag. The tag must exist under refs/tags
8 tag () {
9 _tag=$1
10 - test -f ".git/refs/tags/$_tag" || error "tag: \"$_tag\" does not exist"
11 - cat ".git/refs/tags/$_tag"
10 + git rev-parse --verify "refs/tags/$_tag" ||
11 + error "tag: \"$_tag\" does not exist"
12 }
13
14 # Generate a commit using the text specified to make it unique and the tree
t/t1401-symbolic-ref.sh
+1 -1
@@ -65,7 +65,7 @@ reset_to_sane
65 test_expect_success 'symbolic-ref fails to delete real ref' '
66 echo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect &&
67 test_must_fail git symbolic-ref -d refs/heads/foo >actual 2>&1 &&
68 - test_path_is_file .git/refs/heads/foo &&
68 + git rev-parse --verify refs/heads/foo &&
69 test_cmp expect actual
70 '
71 reset_to_sane
t/t3200-branch.sh
+9 -9
@@ -233,34 +233,34 @@ test_expect_success 'git branch -M master2 master2 should work when master is ch
233
234 test_expect_success 'git branch -v -d t should work' '
235 git branch t &&
236 - test_path_is_file .git/refs/heads/t &&
236 + git rev-parse --verify refs/heads/t &&
237 git branch -v -d t &&
238 - test_path_is_missing .git/refs/heads/t
238 + test_must_fail git rev-parse --verify refs/heads/t
239 '
240
241 test_expect_success 'git branch -v -m t s should work' '
242 git branch t &&
243 - test_path_is_file .git/refs/heads/t &&
243 + git rev-parse --verify refs/heads/t &&
244 git branch -v -m t s &&
245 - test_path_is_missing .git/refs/heads/t &&
246 - test_path_is_file .git/refs/heads/s &&
245 + test_must_fail git rev-parse --verify refs/heads/t &&
246 + git rev-parse --verify refs/heads/s &&
247 git branch -d s
248 '
249
250 test_expect_success 'git branch -m -d t s should fail' '
251 git branch t &&
252 - test_path_is_file .git/refs/heads/t &&
252 + git rev-parse refs/heads/t &&
253 test_must_fail git branch -m -d t s &&
254 git branch -d t &&
255 - test_path_is_missing .git/refs/heads/t
255 + test_must_fail git rev-parse refs/heads/t
256 '
257
258 test_expect_success 'git branch --list -d t should fail' '
259 git branch t &&
260 - test_path_is_file .git/refs/heads/t &&
260 + git rev-parse refs/heads/t &&
261 test_must_fail git branch --list -d t &&
262 git branch -d t &&
263 - test_path_is_missing .git/refs/heads/t
263 + test_must_fail git rev-parse refs/heads/t
264 '
265
266 test_expect_success 'git branch --list -v with --abbrev' '
t/t3903-stash.sh
+1 -1
@@ -726,7 +726,7 @@ test_expect_success 'store updates stash ref and reflog' '
726 git reset --hard &&
727 ! grep quux bazzy &&
728 git stash store -m quuxery $STASH_ID &&
729 - test $(cat .git/refs/stash) = $STASH_ID &&
729 + test $(git rev-parse stash) = $STASH_ID &&
730 git reflog --format=%H stash| grep $STASH_ID &&
731 git stash pop &&
732 grep quux bazzy
t/t5500-fetch-pack.sh
+5 -5
@@ -30,7 +30,7 @@ add () {
30 test_tick &&
31 commit=$(echo "$text" | git commit-tree $tree $parents) &&
32 eval "$name=$commit; export $name" &&
33 - echo $commit > .git/refs/heads/$branch &&
33 + git update-ref "refs/heads/$branch" "$commit" &&
34 eval ${branch}TIP=$commit
35 }
36
@@ -45,10 +45,10 @@ pull_to_client () {
45
46 case "$heads" in
47 *A*)
48 - echo $ATIP > .git/refs/heads/A;;
48 + git update-ref refs/heads/A "$ATIP";;
49 esac &&
50 case "$heads" in *B*)
51 - echo $BTIP > .git/refs/heads/B;;
51 + git update-ref refs/heads/B "$BTIP";;
52 esac &&
53 git symbolic-ref HEAD refs/heads/$(echo $heads \
54 | sed -e "s/^\(.\).*$/\1/") &&
@@ -92,8 +92,8 @@ test_expect_success 'setup' '
92 cur=$(($cur+1))
93 done &&
94 add B1 $A1 &&
95 - echo $ATIP > .git/refs/heads/A &&
96 - echo $BTIP > .git/refs/heads/B &&
95 + git update-ref refs/heads/A "$ATIP" &&
96 + git update-ref refs/heads/B "$BTIP" &&
97 git symbolic-ref HEAD refs/heads/B
98 '
99
t/t5510-fetch.sh
+3 -3
@@ -63,7 +63,7 @@ test_expect_success "fetch test" '
63 git commit -a -m "updated by origin" &&
64 cd two &&
65 git fetch &&
66 - test -f .git/refs/heads/one &&
66 + git rev-parse --verify refs/heads/one &&
67 mine=$(git rev-parse refs/heads/one) &&
68 his=$(cd ../one && git rev-parse refs/heads/master) &&
69 test "z$mine" = "z$his"
@@ -73,8 +73,8 @@ test_expect_success "fetch test for-merge" '
73 cd "$D" &&
74 cd three &&
75 git fetch &&
76 - test -f .git/refs/heads/two &&
77 - test -f .git/refs/heads/one &&
76 + git rev-parse --verify refs/heads/two &&
77 + git rev-parse --verify refs/heads/one &&
78 master_in_two=$(cd ../two && git rev-parse master) &&
79 one_in_two=$(cd ../two && git rev-parse one) &&
80 {
t/t6010-merge-base.sh
+1 -1
@@ -34,7 +34,7 @@ doit () {
34
35 commit=$(echo $NAME | git commit-tree $T $PARENTS) &&
36
37 - echo $commit >.git/refs/tags/$NAME &&
37 + git update-ref "refs/tags/$NAME" "$commit" &&
38 echo $commit
39 }
40
t/t7201-co.sh
+1 -1
@@ -65,7 +65,7 @@ test_expect_success setup '
65 test_expect_success "checkout from non-existing branch" '
66
67 git checkout -b delete-me master &&
68 - rm .git/refs/heads/delete-me &&
68 + git update-ref -d --no-deref refs/heads/delete-me &&
69 test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
70 git checkout master &&
71 test refs/heads/master = "$(git symbolic-ref HEAD)"
t/t9104-git-svn-follow-parent.sh
+2 -1
@@ -213,7 +213,8 @@ test_expect_success "multi-fetch continues to work" "
213 "
214
215 test_expect_success "multi-fetch works off a 'clean' repository" '
216 - rm -r "$GIT_DIR/svn" "$GIT_DIR/refs/remotes" "$GIT_DIR/logs" &&
216 + rm -rf "$GIT_DIR/svn" "$GIT_DIR/refs/remotes" &&
217 + git reflog expire --all --expire=all &&
218 mkdir "$GIT_DIR/svn" &&
219 git svn multi-fetch
220 '