Subject: Re: Bug? diff.submodule=log adds text to commit -v message

From: Jens Lehmann <[email-masked]>
Date: Mon, 11 Nov 2013 22:29:25 +0100

Am 11.11.2013 21:48, schrieb Ari Pollak:
> Jens Lehmann writes:
>> And after adding a modified file the log message also shows the diff of
>> that file (and without leading "# "s too), so I doubt that diffs aren't
>> normally included in the commit message with -v. What am I missing?
> 
> Ah, it is true that -v normally does not prefix the diffs with #, but there 
> must be some filter in place after I save & quit my editor when a normal file 
> diff is present, since that does not get included in the final commit 
> message. But the submodule log does get included, which does not seem 
> intentional.

Ok, now this makes sense. "git commit" strips off the diff added by
-v by skipping everything starting with "\ndiff --git ". But that
logic fails when the "diff.submodule = log" setting adds a shortlog
instead of a regular diff, as that starts with "\nSubmodule ".

The diff below fixes the problem you describe for me. (But I do not
consider it a worthwhile fix in its current form because a line
starting with "Submodule " might appear in a perfectly normal commit
message, while "diff --git " most probably won't).

And while testing this issue I noticed another problem: When using
"git commit -a" not only the staged commits of a submodule get
committed, but also the unstaged commits. Will look into that too.

-------------------------8<---------------------
diff --git a/builtin/commit.c b/builtin/commit.c
index 6ab4605..ff6e171 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1600,11 +1600,14 @@ int cmd_commit(int argc, const char **argv, const char *
                die(_("could not read commit message: %s"), strerror(saved_errno
        }

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

        if (cleanup_mode != CLEANUP_NONE)