Skip to content

Commit

Permalink
t/40-commit: Extract assert_branch function and abbreviate commits
Browse files Browse the repository at this point in the history
All calls to git-show-ref now set --abbrev=12 to make things a bit
more short and sweet. If this fails under earlier versions of Git
that we need to support with tests, we'll have to back this out,
but it's been tested on 2.11.0 and 1.9.1.

The new assert_branch function in most cases takes the just the
git-show-ref output, but you can give it a branch name if you need to
get information for a branch other than the default $branch we put our
test commits on.
  • Loading branch information
0cjs committed Mar 25, 2019
1 parent 2e0a48e commit 3648d28
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions t/40-commit.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export GIT_AUTHOR_DATE=2000-01-01T00:00:00
export GIT_COMMITTER_DATE=2001-01-01T00:00:00

git="git --git-dir=$repo/.git --work-tree=$repo"
git_show_refs="$git show-ref"
git_show_refs="$git show-ref --abbrev=12"
assert_branch() {
local output="$1"
local pattern="${2:-$branch}"
test_equal "$output" "$($git_show_refs "$pattern")"
}

make_test_repo() {
rm -rf tmp/test
Expand Down Expand Up @@ -77,16 +82,13 @@ start_test 'Commit data correct'

make_test_repo
$git branch $branch
test_equal "737b0f4390513917f3a19eece0dcd6a04e5deca3 refs/heads/master
737b0f4390513917f3a19eece0dcd6a04e5deca3 refs/heads/testbr" \
"$($git_show_refs)"
assert_branch '737b0f439051 refs/heads/master' master
assert_branch '737b0f439051 refs/heads/testbr'

echo bar > $files/one
echo bar > $files/subdir/two
$git commit-filetree $branch $files

test_equal "003e5987f3852ef5ad25ebd23b968de5f5104550 refs/heads/testbr" \
"$($git_show_refs $branch)"
assert_branch '003e5987f385 refs/heads/testbr'

end_test

Expand All @@ -100,9 +102,7 @@ $git branch $branch
echo bar > $files/one
echo bar > $files/subdir/two
$git commit-filetree refs/heads/$branch $files

test_equal "003e5987f3852ef5ad25ebd23b968de5f5104550 refs/heads/testbr" \
"$($git_show_refs $branch)"
assert_branch '003e5987f385 refs/heads/testbr'

end_test

Expand All @@ -116,9 +116,7 @@ $git branch $branch
echo bar > $files/one
echo bar > $files/subdir/two
(cd $repo && ../../../bin/git-commit-filetree $branch ../files)

test_equal "003e5987f3852ef5ad25ebd23b968de5f5104550 refs/heads/testbr" \
"$($git_show_refs $branch)"
assert_branch '003e5987f385 refs/heads/testbr'

end_test

Expand All @@ -132,8 +130,7 @@ echo bar > $files/subdir/two
$git commit-filetree $branch $files
$git commit-filetree $branch $files
$git commit-filetree $branch $files
test_equal "003e5987f3852ef5ad25ebd23b968de5f5104550 refs/heads/testbr" \
"$($git_show_refs $branch)"
assert_branch '003e5987f385 refs/heads/testbr'
end_test

##### 9
Expand Down

0 comments on commit 3648d28

Please sign in to comment.