t5700: modernize style

The early part of this test is rather old, and does not
follow our usual style guidelines. In particular:

  - the tests liberally chdir, and expect out-of-test "cd"
    commands to return them to a sane state

  - test commands aren't indented at all

  - there are a lot of minor formatting nits, like the
    opening quote of the test block on the wrong line,
    spaces after ">", etc

This patch fixes the style issues, and uses a few helper
functions, along with subshells and "git -C", to avoid
changing the cwd of the main script.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Jeff King 2015-08-10 05:32:30 -04:00 committed by Junio C Hamano
parent f5895fd399
commit bc192300c4
1 changed files with 79 additions and 110 deletions

View File

@ -10,49 +10,51 @@ base_dir=`pwd`


U=$base_dir/UPLOAD_LOG U=$base_dir/UPLOAD_LOG


test_expect_success 'preparing first repository' \ # create a commit in repo $1 with name $2
'test_create_repo A && cd A && commit_in () {
echo first > file1 && (
git add file1 && cd "$1" &&
git commit -m initial' echo "$2" >"$2" &&
git add "$2" &&
git commit -m "$2"
)
}


cd "$base_dir" # check that there are $2 loose objects in repo $1
test_objcount () {
echo "$2" >expect &&
git -C "$1" count-objects >actual.raw &&
cut -d' ' -f1 <actual.raw >actual &&
test_cmp expect actual
}


test_expect_success 'preparing second repository' \ test_expect_success 'preparing first repository' '
'git clone A B && cd B && test_create_repo A &&
echo second > file2 && commit_in A file1
git add file2 && '
git commit -m addition &&
git repack -a -d &&
git prune'


cd "$base_dir" test_expect_success 'preparing second repository' '
git clone A B &&
commit_in B file2 &&
git -C B repack -ad &&
git -C B prune
'


test_expect_success 'cloning with reference (-l -s)' \ test_expect_success 'cloning with reference (-l -s)' '
'git clone -l -s --reference B A C' git clone -l -s --reference B A C
'


cd "$base_dir" test_expect_success 'existence of info/alternates' '
test_line_count = 2 C/.git/objects/info/alternates
'


test_expect_success 'existence of info/alternates' \ test_expect_success 'pulling from reference' '
'test_line_count = 2 C/.git/objects/info/alternates' git -C C pull ../B master
'


cd "$base_dir" test_expect_success 'that reference gets used' '

test_objcount C 0
test_expect_success 'pulling from reference' \ '
'cd C &&
git pull ../B master'

cd "$base_dir"

test_expect_success 'that reference gets used' \
'cd C &&
echo "0 objects, 0 kilobytes" > expected &&
git count-objects > current &&
test_cmp expected current'

cd "$base_dir"

rm -f "$U.D"


test_expect_success 'cloning with reference (no -l -s)' ' test_expect_success 'cloning with reference (no -l -s)' '
GIT_TRACE_PACKET=$U.D git clone --reference B "file://$(pwd)/A" D GIT_TRACE_PACKET=$U.D git clone --reference B "file://$(pwd)/A" D
@ -63,95 +65,64 @@ test_expect_success 'fetched no objects' '
! grep " want" "$U.D" ! grep " want" "$U.D"
' '


cd "$base_dir" test_expect_success 'existence of info/alternates' '
test_line_count = 1 D/.git/objects/info/alternates
'


test_expect_success 'existence of info/alternates' \ test_expect_success 'pulling from reference' '
'test_line_count = 1 D/.git/objects/info/alternates' git -C D pull ../B master
'


cd "$base_dir" test_expect_success 'that reference gets used' '
test_objcount D 0
'


test_expect_success 'pulling from reference' \ test_expect_success 'updating origin' '
'cd D && git pull ../B master' commit_in A file3 &&
git -C A repack -ad &&
git -C A prune
'


cd "$base_dir" test_expect_success 'pulling changes from origin' '

git -C C pull origin
test_expect_success 'that reference gets used' \ '
'cd D && echo "0 objects, 0 kilobytes" > expected &&
git count-objects > current &&
test_cmp expected current'

cd "$base_dir"

test_expect_success 'updating origin' \
'cd A &&
echo third > file3 &&
git add file3 &&
git commit -m update &&
git repack -a -d &&
git prune'

cd "$base_dir"

test_expect_success 'pulling changes from origin' \
'cd C &&
git pull origin'

cd "$base_dir"


# the 2 local objects are commit and tree from the merge # the 2 local objects are commit and tree from the merge
test_expect_success 'that alternate to origin gets used' \ test_expect_success 'that alternate to origin gets used' '
'cd C && test_objcount C 2
echo "2 objects" > expected && '
git count-objects | cut -d, -f1 > current &&
test_cmp expected current'


cd "$base_dir" test_expect_success 'pulling changes from origin' '

git -C D pull origin
test_expect_success 'pulling changes from origin' \ '
'cd D &&
git pull origin'

cd "$base_dir"


# the 5 local objects are expected; file3 blob, commit in A to add it # the 5 local objects are expected; file3 blob, commit in A to add it
# and its tree, and 2 are our tree and the merge commit. # and its tree, and 2 are our tree and the merge commit.
test_expect_success 'check objects expected to exist locally' \ test_expect_success 'check objects expected to exist locally' '
'cd D && test_objcount D 5
echo "5 objects" > expected && '
git count-objects | cut -d, -f1 > current &&
test_cmp expected current'


cd "$base_dir" test_expect_success 'preparing alternate repository #1' '
test_create_repo F &&
commit_in F file1
'


test_expect_success 'preparing alternate repository #1' \ test_expect_success 'cloning alternate repo #2 and adding changes to repo #1' '
'test_create_repo F && cd F && git clone F G &&
echo first > file1 && commit_in F file2
git add file1 && '
git commit -m initial'


cd "$base_dir" test_expect_success 'cloning alternate repo #1, using #2 as reference' '
git clone --reference G F H
'


test_expect_success 'cloning alternate repo #2 and adding changes to repo #1' \ test_expect_success 'cloning with reference being subset of source (-l -s)' '
'git clone F G && cd F && git clone -l -s --reference A B E
echo second > file2 && '
git add file2 &&
git commit -m addition'

cd "$base_dir"

test_expect_success 'cloning alternate repo #1, using #2 as reference' \
'git clone --reference G F H'

cd "$base_dir"

test_expect_success 'cloning with reference being subset of source (-l -s)' \
'git clone -l -s --reference A B E'

cd "$base_dir"


test_expect_success 'clone with reference from a tagged repository' ' test_expect_success 'clone with reference from a tagged repository' '
( (
cd A && git tag -a -m 'tagged' HEAD cd A && git tag -a -m tagged HEAD
) && ) &&
git clone --reference=A A I git clone --reference=A A I
' '
@ -168,8 +139,6 @@ test_expect_success 'prepare branched repository' '
) )
' '


rm -f "$U.K"

test_expect_success 'fetch with incomplete alternates' ' test_expect_success 'fetch with incomplete alternates' '
git init K && git init K &&
echo "$base_dir/A/.git/objects" >K/.git/objects/info/alternates && echo "$base_dir/A/.git/objects" >K/.git/objects/info/alternates &&