I discovered a bug in Git a while ago where if one is using
commit.cleanup = scissors, if making a commit after a merge conflict,
the scissors line will be placed after the `Conflicts:` section. As a
result, a careless Git user (e.g. me) may accidentally commit the
`Conflicts:` section.
Here is a test case to replicate the behaviour:
mkdir test
cd test/
git init
git config commit.cleanup scissors
touch a
git add a
git commit -m 'test'
echo a > a
git commit -am 'test2'
git checkout -b new HEAD^
echo b > a
git commit -am 'test3'
git merge master
echo c > a
git add a
git commit # look at the commit message here
And the resulting message that's sent to the text editor:
Merge branch 'master' into new
# Conflicts:
# a
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
#
# It looks like you may be committing a merge.
# If this is not correct, please remove the file
# .git/MERGE_HEAD
# and try again.
# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# On branch new
# All conflicts fixed but you are still merging.
#
# Changes to be committed:
# modified: a
#
With this fix, the message becomes the following:
Merge branch 'master' into new
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
#
# Conflicts:
# a
#
# It looks like you may be committing a merge.
# If this is not correct, please remove the file
# .git/MERGE_HEAD
# and try again.
# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# On branch new
# All conflicts fixed but you are still merging.
#
# Changes to be committed:
# modified: a
#
Let me know what you think of the change. Of course, documentation and
testing will come after this leaves the RFC phase.
Denton Liu (2):
commit: don't add scissors line if one exists
merge: add scissors line on merge conflict
builtin/commit.c | 11 +++++++++--
builtin/merge.c | 16 ++++++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
--
2.19.1