Skip to content

Commit

Permalink
t: make many tests depend less on the refs being files
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dturner-tw authored and gitster committed May 23, 2018
1 parent 468165c commit cbc5cf7
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 25 deletions.
6 changes: 3 additions & 3 deletions t/lib-t6000.sh
Expand Up @@ -4,11 +4,11 @@ mkdir -p .git/refs/tags

>sed.script

# Answer the sha1 has associated with the tag. The tag must exist in .git/refs/tags
# Answer the sha1 has associated with the tag. The tag must exist under refs/tags
tag () {
_tag=$1
test -f ".git/refs/tags/$_tag" || error "tag: \"$_tag\" does not exist"
cat ".git/refs/tags/$_tag"
git rev-parse --verify "refs/tags/$_tag" ||
error "tag: \"$_tag\" does not exist"
}

# Generate a commit using the text specified to make it unique and the tree
Expand Down
2 changes: 1 addition & 1 deletion t/t1401-symbolic-ref.sh
Expand Up @@ -65,7 +65,7 @@ reset_to_sane
test_expect_success 'symbolic-ref fails to delete real ref' '
echo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect &&
test_must_fail git symbolic-ref -d refs/heads/foo >actual 2>&1 &&
test_path_is_file .git/refs/heads/foo &&
git rev-parse --verify refs/heads/foo &&
test_cmp expect actual
'
reset_to_sane
Expand Down
18 changes: 9 additions & 9 deletions t/t3200-branch.sh
Expand Up @@ -233,34 +233,34 @@ test_expect_success 'git branch -M master2 master2 should work when master is ch

test_expect_success 'git branch -v -d t should work' '
git branch t &&
test_path_is_file .git/refs/heads/t &&
git rev-parse --verify refs/heads/t &&
git branch -v -d t &&
test_path_is_missing .git/refs/heads/t
test_must_fail git rev-parse --verify refs/heads/t
'

test_expect_success 'git branch -v -m t s should work' '
git branch t &&
test_path_is_file .git/refs/heads/t &&
git rev-parse --verify refs/heads/t &&
git branch -v -m t s &&
test_path_is_missing .git/refs/heads/t &&
test_path_is_file .git/refs/heads/s &&
test_must_fail git rev-parse --verify refs/heads/t &&
git rev-parse --verify refs/heads/s &&
git branch -d s
'

test_expect_success 'git branch -m -d t s should fail' '
git branch t &&
test_path_is_file .git/refs/heads/t &&
git rev-parse refs/heads/t &&
test_must_fail git branch -m -d t s &&
git branch -d t &&
test_path_is_missing .git/refs/heads/t
test_must_fail git rev-parse refs/heads/t
'

test_expect_success 'git branch --list -d t should fail' '
git branch t &&
test_path_is_file .git/refs/heads/t &&
git rev-parse refs/heads/t &&
test_must_fail git branch --list -d t &&
git branch -d t &&
test_path_is_missing .git/refs/heads/t
test_must_fail git rev-parse refs/heads/t
'

test_expect_success 'git branch --list -v with --abbrev' '
Expand Down
2 changes: 1 addition & 1 deletion t/t3903-stash.sh
Expand Up @@ -726,7 +726,7 @@ test_expect_success 'store updates stash ref and reflog' '
git reset --hard &&
! grep quux bazzy &&
git stash store -m quuxery $STASH_ID &&
test $(cat .git/refs/stash) = $STASH_ID &&
test $(git rev-parse stash) = $STASH_ID &&
git reflog --format=%H stash| grep $STASH_ID &&
git stash pop &&
grep quux bazzy
Expand Down
10 changes: 5 additions & 5 deletions t/t5500-fetch-pack.sh
Expand Up @@ -30,7 +30,7 @@ add () {
test_tick &&
commit=$(echo "$text" | git commit-tree $tree $parents) &&
eval "$name=$commit; export $name" &&
echo $commit > .git/refs/heads/$branch &&
git update-ref "refs/heads/$branch" "$commit" &&
eval ${branch}TIP=$commit
}

Expand All @@ -45,10 +45,10 @@ pull_to_client () {
case "$heads" in
*A*)
echo $ATIP > .git/refs/heads/A;;
git update-ref refs/heads/A "$ATIP";;
esac &&
case "$heads" in *B*)
echo $BTIP > .git/refs/heads/B;;
git update-ref refs/heads/B "$BTIP";;
esac &&
git symbolic-ref HEAD refs/heads/$(echo $heads \
| sed -e "s/^\(.\).*$/\1/") &&
Expand Down Expand Up @@ -92,8 +92,8 @@ test_expect_success 'setup' '
cur=$(($cur+1))
done &&
add B1 $A1 &&
echo $ATIP > .git/refs/heads/A &&
echo $BTIP > .git/refs/heads/B &&
git update-ref refs/heads/A "$ATIP" &&
git update-ref refs/heads/B "$BTIP" &&
git symbolic-ref HEAD refs/heads/B
'

Expand Down
6 changes: 3 additions & 3 deletions t/t5510-fetch.sh
Expand Up @@ -63,7 +63,7 @@ test_expect_success "fetch test" '
git commit -a -m "updated by origin" &&
cd two &&
git fetch &&
test -f .git/refs/heads/one &&
git rev-parse --verify refs/heads/one &&
mine=$(git rev-parse refs/heads/one) &&
his=$(cd ../one && git rev-parse refs/heads/master) &&
test "z$mine" = "z$his"
Expand All @@ -73,8 +73,8 @@ test_expect_success "fetch test for-merge" '
cd "$D" &&
cd three &&
git fetch &&
test -f .git/refs/heads/two &&
test -f .git/refs/heads/one &&
git rev-parse --verify refs/heads/two &&
git rev-parse --verify refs/heads/one &&
master_in_two=$(cd ../two && git rev-parse master) &&
one_in_two=$(cd ../two && git rev-parse one) &&
{
Expand Down
2 changes: 1 addition & 1 deletion t/t6010-merge-base.sh
Expand Up @@ -34,7 +34,7 @@ doit () {

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

echo $commit >.git/refs/tags/$NAME &&
git update-ref "refs/tags/$NAME" "$commit" &&
echo $commit
}

Expand Down
2 changes: 1 addition & 1 deletion t/t7201-co.sh
Expand Up @@ -65,7 +65,7 @@ test_expect_success setup '
test_expect_success "checkout from non-existing branch" '
git checkout -b delete-me master &&
rm .git/refs/heads/delete-me &&
git update-ref -d --no-deref refs/heads/delete-me &&
test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
git checkout master &&
test refs/heads/master = "$(git symbolic-ref HEAD)"
Expand Down
3 changes: 2 additions & 1 deletion t/t9104-git-svn-follow-parent.sh
Expand Up @@ -213,7 +213,8 @@ test_expect_success "multi-fetch continues to work" "
"

test_expect_success "multi-fetch works off a 'clean' repository" '
rm -r "$GIT_DIR/svn" "$GIT_DIR/refs/remotes" "$GIT_DIR/logs" &&
rm -rf "$GIT_DIR/svn" "$GIT_DIR/refs/remotes" &&
git reflog expire --all --expire=all &&
mkdir "$GIT_DIR/svn" &&
git svn multi-fetch
'
Expand Down

0 comments on commit cbc5cf7

Please sign in to comment.