From 3ce82db2520b335fd9d8858b23a175da259b0a79 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sun, 3 Sep 2023 02:27:27 -0700 Subject: [PATCH] commit: strip commentary from .git/MERGE_MSG The git-generated MERGE_MSG files contain comments that should not be displayed in Git Cola's WYSIWG editor. Related-to: #1330 Signed-off-by: David Aguilar --- cola/gitcmds.py | 13 +++++++++++++ cola/models/main.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cola/gitcmds.py b/cola/gitcmds.py index bfc722c9..188817ce 100644 --- a/cola/gitcmds.py +++ b/cola/gitcmds.py @@ -12,6 +12,7 @@ from .git import EMPTY_TREE_OID from .git import OID_LENGTH from .i18n import N_ from .interaction import Interaction +from .models import prefs def add(context, items, u=False): @@ -845,6 +846,18 @@ def merge_message_path(context): return None +def read_merge_commit_message(context, path): + """Read a merge commit message from disk while stripping commentary""" + content = core.read(path) + cleanup_mode = prefs.commit_cleanup(context) + if cleanup_mode in ('verbatim', 'scissors', 'whitespace'): + return content + comment_char = prefs.comment_char(context) + return '\n'.join( + (line for line in content.splitlines() if not line.startswith(comment_char)) + ) + + def prepare_commit_message_hook(context): """Run the cola.preparecommitmessagehook to prepare the commit message""" config = context.cfg diff --git a/cola/models/main.py b/cola/models/main.py index 1119fa03..f3212721 100644 --- a/cola/models/main.py +++ b/cola/models/main.py @@ -401,7 +401,7 @@ class MainModel(QtCore.QObject): context = self.context merge_msg_path = gitcmds.merge_message_path(context) if merge_msg_path: - msg = core.read(merge_msg_path) + msg = gitcmds.read_merge_commit_message(context, merge_msg_path) if msg != self._auto_commitmsg: self._auto_commitmsg = msg self._prev_commitmsg = self.commitmsg -- 2.11.4.GIT