Fix auto-insertion of Author info in Git merge commits
Fix auto-insertion of Author info in Git merge commits

We had a bug in our git_hooks where doing a merge or certain types of
interactive rebase (for example, to squash in a commit made with `git
commit --fixup`) when having run `git pair` previously would spuriously
insert the author comment into the commit message. For an example, see
this Gerrit patchset:

  https://gerrit.causes.com/#patch,sidebyside,4366,2,/COMMIT_MSG

Worse still, repeated rebasing could end up inserting the author comment
again and again.

I looked into various ways of detecting when a rebase is in progress so
that I could skip the author insertion in those cases; for example, see
the techniques listed here:

  http://stackoverflow.com/questions/3921409/how-to-know-if-there-is-a-git-rebase-in-progress

but alas, there is no programmatic way that I could find to distinguish
between the kind of merge commits where the author comment insertion
will be fine (ie. merge commits which wind up opening an editor) and
those where it will not.

In the end, the simplest and safest heuristic is simply to refrain from
doing any kind of comment insertion if the proposed commit message file
doesn't already have comments in it. From this you can infer whether
you're destined for an editor (in which case it is safe/useful to insert
comments) or not (in which case it is unsafe/useless to do so).

Note that I also made sure we don't propagate the previous "# Author: "
field in the case where we're performing insertion, but the truth is now
that the heuristic is in place I don't really expect to ever have
duplicate comments anyway.

Related story:
  http://www.pivotaltracker.com/story/show/26823469 (fixed)
  ("Fix auto-insertion of Author info in Git merge commits")

Change-Id: I324253b77de023b3d9849b708259d2b8c44b9e0a
Reviewed-on: https://gerrit.causes.com/4392
Tested-by: Greg Hurrell <79e2475f81a6317276bf7cbb3958b20d289b78df@causes.com>
Reviewed-by: Lann Martin <564fa7a717c51b612962ea128f146981a0e99d90@causes.com>

oxocode/overcommit,blech75/overcommit,TheSooth/overcommit,TheSooth/overcommit,blech75/overcommit,oxocode/overcommit,gnagel/overcommit,gnagel/overcommit