Skip to content

Commit b2a6095

Browse files
committed
Merge branch 'tc/commit-abbrev-fix' into maint
* tc/commit-abbrev-fix: commit::print_summary(): don't use format_commit_message() t7502-commit: add summary output tests for empty and merge commits t7502-commit: add tests for summary output
2 parents a7e664f + a45e1a8 commit b2a6095

File tree

2 files changed

+72
-6
lines changed

2 files changed

+72
-6
lines changed

builtin/commit.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,13 +1153,11 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
11531153
initial_commit ? " (root-commit)" : "");
11541154

11551155
if (!log_tree_commit(&rev, commit)) {
1156-
struct pretty_print_context ctx = {0};
1157-
struct strbuf buf = STRBUF_INIT;
1158-
ctx.date_mode = DATE_NORMAL;
1159-
format_commit_message(commit, format.buf + 7, &buf, &ctx);
1160-
printf("%s\n", buf.buf);
1161-
strbuf_release(&buf);
1156+
rev.always_show_header = 1;
1157+
rev.use_terminator = 1;
1158+
log_tree_commit(&rev, commit);
11621159
}
1160+
11631161
strbuf_release(&format);
11641162
}
11651163

t/t7502-commit.sh

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

55
. ./test-lib.sh
66

7+
# Arguments: [<prefix] [<commit message>] [<commit options>]
8+
check_summary_oneline() {
9+
test_tick &&
10+
git commit ${3+"$3"} -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+
test_expect_success 'output summary format for commit with an empty diff' '
40+
41+
check_summary_oneline "" "empty" "--allow-empty"
42+
'
43+
44+
test_expect_success 'output summary format for merges' '
45+
46+
git checkout -b recursive-base &&
47+
test_commit base file1 &&
48+
49+
git checkout -b recursive-a recursive-base &&
50+
test_commit commit-a file1 &&
51+
52+
git checkout -b recursive-b recursive-base &&
53+
test_commit commit-b file1 &&
54+
55+
# conflict
56+
git checkout recursive-a &&
57+
test_must_fail git merge recursive-b &&
58+
# resolve the conflict
59+
echo commit-a > file1 &&
60+
git add file1 &&
61+
check_summary_oneline "" "Merge"
62+
'
63+
64+
output_tests_cleanup() {
65+
# this is needed for "do not fire editor in the presence of conflicts"
66+
git checkout master &&
67+
68+
# this is needed for the "partial removal" test to pass
69+
git rm file1 &&
70+
git commit -m "cleanup"
71+
}
72+
773
test_expect_success 'the basics' '
874
75+
output_tests_cleanup &&
76+
977
echo doing partial >"commit is" &&
1078
mkdir not &&
1179
echo very much encouraged but we should >not/forbid &&

0 commit comments

Comments
 (0)