t7502-commit: add tests for summary output
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tay Ray Chuan committed
May 27, 2010 at 23:34 UTC
fc6fa0d0f38f4e5b47f260fe2755ba0d1b17ae53
1 file changed
+43
t/t7502-commit.sh
+43
@@ -4,8 +4,51 @@ test_description='git commit porcelain-ish'
4
5
. ./test-lib.sh
6
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
+
48
test_expect_success 'the basics' '
49
50
+ output_tests_cleanup &&
51
+
52
echo doing partial >"commit is" &&
53
mkdir not &&
54
echo very much encouraged but we should >not/forbid &&