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
This commit is contained in:
Junio C Hamano 2010-06-22 09:31:47 -07:00
commit b2a6095308
2 changed files with 72 additions and 6 deletions

View File

@ -1153,13 +1153,11 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
initial_commit ? " (root-commit)" : "");
if (!log_tree_commit(&rev, commit)) {
struct pretty_print_context ctx = {0};
struct strbuf buf = STRBUF_INIT;
ctx.date_mode = DATE_NORMAL;
format_commit_message(commit, format.buf + 7, &buf, &ctx);
printf("%s\n", buf.buf);
strbuf_release(&buf);
rev.always_show_header = 1;
rev.use_terminator = 1;
log_tree_commit(&rev, commit);
}
strbuf_release(&format);
}

View File

@ -4,8 +4,76 @@ test_description='git commit porcelain-ish'
. ./test-lib.sh
# Arguments: [<prefix] [<commit message>] [<commit options>]
check_summary_oneline() {
test_tick &&
git commit ${3+"$3"} -m "$2" | head -1 > act &&
# branch name
SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" &&
# append the "special" prefix, like "root-commit", "detached HEAD"
if test -n "$1"
then
SUMMARY_PREFIX="$SUMMARY_PREFIX ($1)"
fi
# abbrev SHA-1
SUMMARY_POSTFIX="$(git log -1 --pretty='format:%h')"
echo "[$SUMMARY_PREFIX $SUMMARY_POSTFIX] $2" >exp &&
test_cmp exp act
}
test_expect_success 'output summary format' '
echo new >file1 &&
git add file1 &&
check_summary_oneline "root-commit" "initial" &&
echo change >>file1 &&
git add file1 &&
check_summary_oneline "" "a change"
'
test_expect_success 'output summary format for commit with an empty diff' '
check_summary_oneline "" "empty" "--allow-empty"
'
test_expect_success 'output summary format for merges' '
git checkout -b recursive-base &&
test_commit base file1 &&
git checkout -b recursive-a recursive-base &&
test_commit commit-a file1 &&
git checkout -b recursive-b recursive-base &&
test_commit commit-b file1 &&
# conflict
git checkout recursive-a &&
test_must_fail git merge recursive-b &&
# resolve the conflict
echo commit-a > file1 &&
git add file1 &&
check_summary_oneline "" "Merge"
'
output_tests_cleanup() {
# this is needed for "do not fire editor in the presence of conflicts"
git checkout master &&
# this is needed for the "partial removal" test to pass
git rm file1 &&
git commit -m "cleanup"
}
test_expect_success 'the basics' '
output_tests_cleanup &&
echo doing partial >"commit is" &&
mkdir not &&
echo very much encouraged but we should >not/forbid &&