Skip to content

Commit cbc5cf7

Browse files
dturner-twgitster
authored andcommitted
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 <[email protected]> Helped-by: Johannes Schindelin <[email protected]> Signed-off-by: David Turner <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 468165c commit cbc5cf7

9 files changed

+26
-25
lines changed

t/lib-t6000.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ mkdir -p .git/refs/tags
44

55
>sed.script
66

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
88
tag () {
99
_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"
1212
}
1313

1414
# Generate a commit using the text specified to make it unique and the tree

t/t1401-symbolic-ref.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ reset_to_sane
6565
test_expect_success 'symbolic-ref fails to delete real ref' '
6666
echo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect &&
6767
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 &&
6969
test_cmp expect actual
7070
'
7171
reset_to_sane

t/t3200-branch.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,34 +233,34 @@ test_expect_success 'git branch -M master2 master2 should work when master is ch
233233

234234
test_expect_success 'git branch -v -d t should work' '
235235
git branch t &&
236-
test_path_is_file .git/refs/heads/t &&
236+
git rev-parse --verify refs/heads/t &&
237237
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
239239
'
240240

241241
test_expect_success 'git branch -v -m t s should work' '
242242
git branch t &&
243-
test_path_is_file .git/refs/heads/t &&
243+
git rev-parse --verify refs/heads/t &&
244244
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 &&
247247
git branch -d s
248248
'
249249

250250
test_expect_success 'git branch -m -d t s should fail' '
251251
git branch t &&
252-
test_path_is_file .git/refs/heads/t &&
252+
git rev-parse refs/heads/t &&
253253
test_must_fail git branch -m -d t s &&
254254
git branch -d t &&
255-
test_path_is_missing .git/refs/heads/t
255+
test_must_fail git rev-parse refs/heads/t
256256
'
257257

258258
test_expect_success 'git branch --list -d t should fail' '
259259
git branch t &&
260-
test_path_is_file .git/refs/heads/t &&
260+
git rev-parse refs/heads/t &&
261261
test_must_fail git branch --list -d t &&
262262
git branch -d t &&
263-
test_path_is_missing .git/refs/heads/t
263+
test_must_fail git rev-parse refs/heads/t
264264
'
265265

266266
test_expect_success 'git branch --list -v with --abbrev' '

t/t3903-stash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ test_expect_success 'store updates stash ref and reflog' '
726726
git reset --hard &&
727727
! grep quux bazzy &&
728728
git stash store -m quuxery $STASH_ID &&
729-
test $(cat .git/refs/stash) = $STASH_ID &&
729+
test $(git rev-parse stash) = $STASH_ID &&
730730
git reflog --format=%H stash| grep $STASH_ID &&
731731
git stash pop &&
732732
grep quux bazzy

t/t5500-fetch-pack.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ add () {
3030
test_tick &&
3131
commit=$(echo "$text" | git commit-tree $tree $parents) &&
3232
eval "$name=$commit; export $name" &&
33-
echo $commit > .git/refs/heads/$branch &&
33+
git update-ref "refs/heads/$branch" "$commit" &&
3434
eval ${branch}TIP=$commit
3535
}
3636

@@ -45,10 +45,10 @@ pull_to_client () {
4545
4646
case "$heads" in
4747
*A*)
48-
echo $ATIP > .git/refs/heads/A;;
48+
git update-ref refs/heads/A "$ATIP";;
4949
esac &&
5050
case "$heads" in *B*)
51-
echo $BTIP > .git/refs/heads/B;;
51+
git update-ref refs/heads/B "$BTIP";;
5252
esac &&
5353
git symbolic-ref HEAD refs/heads/$(echo $heads \
5454
| sed -e "s/^\(.\).*$/\1/") &&
@@ -92,8 +92,8 @@ test_expect_success 'setup' '
9292
cur=$(($cur+1))
9393
done &&
9494
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" &&
9797
git symbolic-ref HEAD refs/heads/B
9898
'
9999

t/t5510-fetch.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ test_expect_success "fetch test" '
6363
git commit -a -m "updated by origin" &&
6464
cd two &&
6565
git fetch &&
66-
test -f .git/refs/heads/one &&
66+
git rev-parse --verify refs/heads/one &&
6767
mine=$(git rev-parse refs/heads/one) &&
6868
his=$(cd ../one && git rev-parse refs/heads/master) &&
6969
test "z$mine" = "z$his"
@@ -73,8 +73,8 @@ test_expect_success "fetch test for-merge" '
7373
cd "$D" &&
7474
cd three &&
7575
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 &&
7878
master_in_two=$(cd ../two && git rev-parse master) &&
7979
one_in_two=$(cd ../two && git rev-parse one) &&
8080
{

t/t6010-merge-base.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ doit () {
3434

3535
commit=$(echo $NAME | git commit-tree $T $PARENTS) &&
3636

37-
echo $commit >.git/refs/tags/$NAME &&
37+
git update-ref "refs/tags/$NAME" "$commit" &&
3838
echo $commit
3939
}
4040

t/t7201-co.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test_expect_success setup '
6565
test_expect_success "checkout from non-existing branch" '
6666
6767
git checkout -b delete-me master &&
68-
rm .git/refs/heads/delete-me &&
68+
git update-ref -d --no-deref refs/heads/delete-me &&
6969
test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
7070
git checkout master &&
7171
test refs/heads/master = "$(git symbolic-ref HEAD)"

t/t9104-git-svn-follow-parent.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ test_expect_success "multi-fetch continues to work" "
213213
"
214214

215215
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 &&
217218
mkdir "$GIT_DIR/svn" &&
218219
git svn multi-fetch
219220
'

0 commit comments

Comments
 (0)