Skip to content

Commit fc6fa0d

Browse files
rctaygitster
authored andcommitted
t7502-commit: add tests for summary output
Signed-off-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c197702 commit fc6fa0d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

t/t7502-commit.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,51 @@ test_description='git commit porcelain-ish'
44

55
. ./test-lib.sh
66

7+
# Arguments: [<prefix] [<commit message>]
8+
check_summary_oneline() {
9+
test_tick &&
10+
git commit -m "$2" | head -1 > act &&
11+
12+
# branch name
13+
SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" &&
14+
15+
# append the "special" prefix, like "root-commit", "detached HEAD"
16+
if test -n "$1"
17+
then
18+
SUMMARY_PREFIX="$SUMMARY_PREFIX ($1)"
19+
fi
20+
21+
# abbrev SHA-1
22+
SUMMARY_POSTFIX="$(git log -1 --pretty='format:%h')"
23+
echo "[$SUMMARY_PREFIX $SUMMARY_POSTFIX] $2" >exp &&
24+
25+
test_cmp exp act
26+
}
27+
28+
test_expect_success 'output summary format' '
29+
30+
echo new >file1 &&
31+
git add file1 &&
32+
check_summary_oneline "root-commit" "initial" &&
33+
34+
echo change >>file1 &&
35+
git add file1 &&
36+
check_summary_oneline "" "a change"
37+
'
38+
39+
output_tests_cleanup() {
40+
# this is needed for "do not fire editor in the presence of conflicts"
41+
git checkout master &&
42+
43+
# this is needed for the "partial removal" test to pass
44+
git rm file1 &&
45+
git commit -m "cleanup"
46+
}
47+
748
test_expect_success 'the basics' '
849
50+
output_tests_cleanup &&
51+
952
echo doing partial >"commit is" &&
1053
mkdir not &&
1154
echo very much encouraged but we should >not/forbid &&

0 commit comments

Comments
 (0)