Skip to content

Rearchitect squash edit message to include all commits. #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 16 additions & 25 deletions stgit/commands/squash.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,10 @@ class SaveTemplateDone(Exception):
pass


def _append_comment(message, comment):
return '\n'.join(
[
message,
'',
'---',
'Everything following the line with "---" will be ignored',
'',
comment,
]
)


def _strip_comment(message):
try:
return message[: message.index('\n---\n')]
except ValueError:
return message
def _strip_comments(message):
for line in message.splitlines():
if not line.startswith('#'):
yield line


def _squash_patches(trans, patches, msg, save_template, no_verify=False):
Expand All @@ -94,19 +80,24 @@ def _squash_patches(trans, patches, msg, save_template, no_verify=False):
return None
cd = cd.set_tree(tree)
if msg is None:
msg = _append_comment(
cd.message_str,
'\n\n'.join(
'%s\n\n%s' % (pn.ljust(70, '-'), trans.patches[pn].data.message_str)
for pn in patches[1:]
),
msg = "# This is a combination of %s patches.\n" % len(patches)
for num, pn in enumerate(patches, 1):
msg += "# This is the commit message for %s (patch #%s):" % (
pn,
num,
)
msg += "\n%s\n" % trans.patches[pn].data.message_str
msg += (
"# Please enter the commit message for your patch. Lines starting\n"
"# with '#' will be ignored."
)

if save_template:
save_template(msg.encode(cd.encoding))
raise SaveTemplateDone()
else:
msg = utils.edit_string(msg, '.stgit-squash.txt')
msg = _strip_comment(msg).strip()
msg = '\n'.join(_strip_comments(msg)).strip()
cd = cd.set_message(msg)

if not no_verify:
Expand Down