Skip to content

Commit

Permalink
Merge branch 'jk/maint-commit-v-strip' into maint
Browse files Browse the repository at this point in the history
* jk/maint-commit-v-strip:
  commit: Fix stripping of patch in verbose mode.
  • Loading branch information
Junio C Hamano committed Dec 3, 2008
2 parents 733070b + 0b38227 commit 2ab4de5
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
8 changes: 5 additions & 3 deletions builtin-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,9 +1004,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
}

/* Truncate the message just before the diff, if any. */
p = strstr(sb.buf, "\ndiff --git a/");
if (p != NULL)
strbuf_setlen(&sb, p - sb.buf + 1);
if (verbose) {
p = strstr(sb.buf, "\ndiff --git ");
if (p != NULL)
strbuf_setlen(&sb, p - sb.buf + 1);
}

if (cleanup_mode != CLEANUP_NONE)
stripspace(&sb, cleanup_mode == CLEANUP_ALL);
Expand Down
73 changes: 73 additions & 0 deletions t/t7507-commit-verbose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/sh

test_description='verbose commit template'
. ./test-lib.sh

cat >check-for-diff <<EOF
#!$SHELL_PATH
exec grep '^diff --git' "\$1"
EOF
chmod +x check-for-diff
test_set_editor "$PWD/check-for-diff"

cat >message <<'EOF'
subject
body
EOF

test_expect_success 'setup' '
echo content >file &&
git add file &&
git commit -F message
'

test_expect_failure 'initial commit shows verbose diff' '
git commit --amend -v
'

test_expect_success 'second commit' '
echo content modified >file &&
git add file &&
git commit -F message
'

check_message() {
git log -1 --pretty=format:%s%n%n%b >actual &&
test_cmp "$1" actual
}

test_expect_success 'verbose diff is stripped out' '
git commit --amend -v &&
check_message message
'

test_expect_success 'verbose diff is stripped out (mnemonicprefix)' '
git config diff.mnemonicprefix true &&
git commit --amend -v &&
check_message message
'

cat >diff <<'EOF'
This is an example commit message that contains a diff.
diff --git c/file i/file
new file mode 100644
index 0000000..f95c11d
--- /dev/null
+++ i/file
@@ -0,0 +1 @@
+this is some content
EOF

test_expect_success 'diff in message is retained without -v' '
git commit --amend -F diff &&
check_message diff
'

test_expect_failure 'diff in message is retained with -v' '
git commit --amend -F diff -v &&
check_message diff
'

test_done

0 comments on commit 2ab4de5

Please sign in to comment.