Skip to content

Commit 9a4b044

Browse files
committed
Use prepared commit message (MERGE_MSG) after merging
Strip conflict comments from MERGE_MSG as well.
1 parent 295abde commit 9a4b044

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

gitfourchette/porcelain.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,15 @@ def wrap_conflict(self, path: str) -> DiffConflict:
18481848
ancestor, ours, theirs = self.index.conflicts[path]
18491849
return DiffConflict(ancestor, ours, theirs)
18501850

1851+
@property
1852+
def message_without_conflict_comments(self) -> str:
1853+
message = self.message
1854+
clean_message = ""
1855+
for line in message.splitlines(keepends=True):
1856+
if not line.startswith('#'):
1857+
clean_message += line
1858+
return clean_message.strip()
1859+
18511860

18521861
class RepoContext:
18531862
def __init__(self, repo_or_path: Repo | str | _Path, flags=RepositoryOpenFlag.DEFAULT, write_index=False):

gitfourchette/tasks/branchtasks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,10 @@ def flow(self, them: str):
582582
# Create merge commit
583583
self.effects |= TaskEffects.Workdir
584584
self.jumpTo = NavLocator.inWorkdir()
585+
585586
self.repo.merge(target)
587+
self.repoModel.prefs.draftCommitMessage = self.repo.message_without_conflict_comments
588+
586589
self.postStatus = _("Merging {0} into {1}.", tquo(theirShorthand), tquo(myShorthand))
587590
else:
588591
# Fast-forward

gitfourchette/tasks/committasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def flow(self, oid: Oid):
405405

406406
yield from self.flowEnterUiThread()
407407

408-
repoModel.prefs.draftCommitMessage = self.repo.message
408+
repoModel.prefs.draftCommitMessage = self.repo.message_without_conflict_comments
409409
repoModel.prefs.setDirty()
410410

411411
self.jumpTo = NavLocator.inWorkdir()
@@ -446,7 +446,7 @@ def flow(self, oid: Oid):
446446
"that the current branch doesn’t already have.", bquo(shortHash(oid)))
447447
raise AbortTask(info, "information")
448448

449-
self.repoModel.prefs.draftCommitMessage = self.repo.message
449+
self.repoModel.prefs.draftCommitMessage = self.repo.message_without_conflict_comments
450450
self.repoModel.prefs.draftCommitSignature = commit.author
451451
self.repoModel.prefs.draftCommitSignatureOverride = SignatureOverride.Author
452452
self.repoModel.prefs.setDirty()

test/test_tasks_branch.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,17 @@ def testMergeCausesConflicts(tempDir, mainWindow):
912912
assert not rw.conflictView.isVisible()
913913
assert re.search(r"all conflicts fixed", rw.mergeBanner.label.text(), re.I)
914914

915+
rw.diffArea.commitButton.click()
916+
acceptQMessageBox(rw, "empty commit")
917+
commitDialog: CommitDialog = findQDialog(rw, "commit")
918+
preparedMessage = commitDialog.getFullMessage()
919+
assert re.match(r"Merge commit.+1b2bae55", preparedMessage)
920+
assert "Conflicts" not in preparedMessage
921+
assert "#" not in preparedMessage
922+
923+
commitDialog.accept()
924+
assert rw.repo.state() == RepositoryState.NONE
925+
915926

916927
@pytest.mark.parametrize("method", ["switchbranch", "newbranch", "checkout"])
917928
def testMightLoseDetachedHead(tempDir, mainWindow, method):

0 commit comments

Comments
 (0)