From 717e78f17695cf7130f9d51fd96e3b3576da0a7c Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 18 Mar 2023 21:48:24 -0700 Subject: [PATCH] status: implement the UnmergedSummary TODO item Signed-off-by: David Aguilar --- CHANGES.rst | 2 ++ cola/cmds.py | 24 +++++++++++++++++++----- cola/widgets/status.py | 3 +-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index aa236e13..08e4eee2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -117,6 +117,8 @@ Usability, bells and whistles ``git show`` when saving files from arbitrary commits. (`#1065 `_) +* The "Unmerged" header item in the Status tool now displays a summary list of unmerged files. + Development ----------- diff --git a/cola/cmds.py b/cola/cmds.py index cf2cd1fe..e6491b69 100644 --- a/cola/cmds.py +++ b/cola/cmds.py @@ -2926,19 +2926,33 @@ class Untrack(ContextCommand): Interaction.log_status(status, out, err) +class UnmergedSummary(EditModel): + """List unmerged files in the diff text.""" + + def __init__(self, context): + super(UnmergedSummary, self).__init__(context) + unmerged = self.model.unmerged + io = StringIO() + io.write('# %s unmerged file(s)\n' % len(unmerged)) + if unmerged: + io.write('\n'.join(unmerged) + '\n') + self.new_diff_text = io.getvalue() + self.new_diff_type = main.Types.TEXT + self.new_file_type = main.Types.TEXT + self.new_mode = self.model.mode_display + + class UntrackedSummary(EditModel): """List possible .gitignore rules as the diff text.""" def __init__(self, context): super(UntrackedSummary, self).__init__(context) untracked = self.model.untracked - suffix = 's' if untracked else '' io = StringIO() - io.write('# %s untracked file%s\n' % (len(untracked), suffix)) + io.write('# %s untracked file(s)\n' % len(untracked)) if untracked: - io.write('# possible .gitignore rule%s:\n' % suffix) - for u in untracked: - io.write('/' + u + '\n') + io.write('# Add these lines to ".gitignore" to ignore these files:\n') + io.write('\n'.join('/' + filename for filename in untracked) + '\n') self.new_diff_text = io.getvalue() self.new_diff_type = main.Types.TEXT self.new_file_type = main.Types.TEXT diff --git a/cola/widgets/status.py b/cola/widgets/status.py index d8991a83..bc95b028 100644 --- a/cola/widgets/status.py +++ b/cola/widgets/status.py @@ -1123,8 +1123,7 @@ class StatusTreeWidget(QtWidgets.QTreeWidget): cls = { STAGED_IDX: cmds.DiffStagedSummary, MODIFIED_IDX: cmds.Diffstat, - # TODO implement UnmergedSummary - # UNMERGED_IDX: cmds.UnmergedSummary, + UNMERGED_IDX: cmds.UnmergedSummary, UNTRACKED_IDX: cmds.UntrackedSummary, }.get(idx, cmds.Diffstat) cmds.do(cls, context) -- 2.11.4.GIT