Skip to content

Commit 33c6fe8

Browse files
committed
Allow the default for --edit/--no-edit to be configured
The commands `git imerge continue` and `git imerge record` allow an `--edit`/`--no-edit` option to choose whether to ask the user to edit the commit messages if a merge commit is ready to be committed. These messages are pretty useless, so add a configuration option `imerge.editmergemessages` that can be used to set the default to `--no-edit`.
1 parent e017c2b commit 33c6fe8

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

git-imerge

+31-5
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,30 @@ else:
260260
return s
261261

262262

263+
def get_default_edit():
264+
"""Should '--edit' be used when committing intermediate user merges?
265+
266+
When 'git imerge continue' or 'git imerge record' finds a user
267+
merge that can be committed, should it (by default) ask the user
268+
to edit the commit message? This behavior can be configured via
269+
'imerge.editmergemessages'. If it is not configured, return True.
270+
271+
Please note that this function is only used to choose the default
272+
value. It can be overridden on the command line using '--edit' or
273+
'--no-edit'.
274+
275+
"""
276+
277+
try:
278+
return {'true' : True, 'false' : False}[
279+
check_output(
280+
['git', 'config', '--bool', 'imerge.editmergemessages']
281+
).rstrip()
282+
]
283+
except CalledProcessError:
284+
return True
285+
286+
263287
class UncleanWorkTreeError(Failure):
264288
pass
265289

@@ -2622,11 +2646,13 @@ def incorporate_user_merge(merge_state, edit_log_msg=None):
26222646
# There are staged changes; commit them if possible.
26232647
cmd = ['git', 'commit', '--no-verify']
26242648

2625-
if edit_log_msg is not None:
2626-
if edit_log_msg:
2627-
cmd += ['--edit']
2628-
else:
2629-
cmd += ['--no-edit']
2649+
if edit_log_msg is None:
2650+
edit_log_msg = get_default_edit()
2651+
2652+
if edit_log_msg:
2653+
cmd += ['--edit']
2654+
else:
2655+
cmd += ['--no-edit']
26302656

26312657
try:
26322658
check_call(cmd)

t/test-conflicted

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ git checkout c
2525
"$GIT_IMERGE" diagram --commits --frontier --html=imerge0.html
2626
"$GIT_IMERGE" autofill || true
2727
"$GIT_IMERGE" diagram --commits --frontier --html=imerge1.html
28-
"$GIT_IMERGE" continue
28+
"$GIT_IMERGE" continue --edit
2929
echo 'cd version' >conflict.txt
3030
git add conflict.txt
3131
"$GIT_IMERGE" continue --no-edit
@@ -41,7 +41,7 @@ git checkout c
4141
echo 'cd version' >conflict.txt
4242
git add conflict.txt
4343
GIT_EDITOR=cat git commit
44-
"$GIT_IMERGE" continue
44+
"$GIT_IMERGE" continue --edit
4545
"$GIT_IMERGE" diagram --commits --frontier --html=imerge4.html
4646
"$GIT_IMERGE" finish --branch=c-d-full
4747

0 commit comments

Comments
 (0)