From fc6fa0d0f38f4e5b47f260fe2755ba0d1b17ae53 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Thu, 27 May 2010 23:34:50 +0800 Subject: t7502-commit: add tests for summary output Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index 844fb43..478b637 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -4,8 +4,51 @@ test_description='git commit porcelain-ish' . ./test-lib.sh +# Arguments: [] +check_summary_oneline() { + test_tick && + git commit -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" +' + +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 && -- cgit v0.10.2-6-g49f6 From cee9f2b37bd7c65de5fb507d11b4caac31c29039 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Thu, 27 May 2010 23:34:51 +0800 Subject: t7502-commit: add summary output tests for empty and merge commits After c197702 (pretty: Respect --abbrev option), non-abbreviated hashes began to appear, leading to failures for these tests. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index 478b637..b10541d 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -4,10 +4,10 @@ test_description='git commit porcelain-ish' . ./test-lib.sh -# Arguments: [] +# Arguments: [] [] check_summary_oneline() { test_tick && - git commit -m "$2" | head -1 > act && + git commit ${3+"$3"} -m "$2" | head -1 > act && # branch name SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" && @@ -36,6 +36,31 @@ test_expect_success 'output summary format' ' check_summary_oneline "" "a change" ' +test_expect_failure 'output summary format for commit with an empty diff' ' + + check_summary_oneline "" "empty" "--allow-empty" +' + +test_expect_failure '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 && -- cgit v0.10.2-6-g49f6 From a45e1a87adc7cd7ace911049829308ae97b2e914 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Sat, 12 Jun 2010 22:15:39 +0800 Subject: commit::print_summary(): don't use format_commit_message() This attempts to fix a regression in git-commit, where non-abbreviated SHA-1s were printed in the summary. One possible fix would be to set ctx.abbrev to DEFAULT_ABBREV in the `if` block, where format_commit_message() is used. Instead, we do away with the format_commit_message() codeblock altogether, replacing it with a re-run of log_tree_commit(). We re-run log_tree_commit() with rev.always_show_header set, to force the invocation of show_log(). The effect of this flag can be seen from this excerpt from log-tree.c:560, the only area that rev.always_show_header is checked: shown = log_tree_diff(opt, commit, &log); if (!shown && opt->loginfo && opt->always_show_header) { log.parent = NULL; show_log(opt); shown = 1; } We also set rev.use_terminator, so that a newline is appended at the end of the log message. Note that callers in builtin/log.c that also set rev.always_show_header don't have to set rev.use_terminator, but still get a newline, because they are wrapped in a pager. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano diff --git a/builtin-commit.c b/builtin-commit.c index f4c7344..7b7a51a 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -1136,13 +1136,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); } diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index b10541d..08c0247 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -36,12 +36,12 @@ test_expect_success 'output summary format' ' check_summary_oneline "" "a change" ' -test_expect_failure 'output summary format for commit with an empty diff' ' +test_expect_success 'output summary format for commit with an empty diff' ' check_summary_oneline "" "empty" "--allow-empty" ' -test_expect_failure 'output summary format for merges' ' +test_expect_success 'output summary format for merges' ' git checkout -b recursive-base && test_commit base file1 && -- cgit v0.10.2-6-g49f6