Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions ciq-cherry-pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ def manage_commit_message(full_sha, ciq_tags, jira_ticket, commit_successful):
except IOError as e:
raise RuntimeError(f"Failed to read commit message from {MERGE_MSG}: {e}") from e

# git appends a "# Conflicts:" comment block to MERGE_MSG on a conflicted
# cherry-pick, and committing with -F doesn't strip comment lines. Drop the
# block to keep it out of the final commit message.
for i, line in enumerate(original_msg):
if line.rstrip("\n") == "# Conflicts:":
original_msg = original_msg[:i]
break

optional_msg = "" if commit_successful else "upstream-diff |"
new_msg = CIQ_cherry_pick_commit_standardization(
original_msg, full_sha, jira=jira_ticket, tags=new_tags, optional_msg=optional_msg
Expand Down
4 changes: 2 additions & 2 deletions kt/ktlib/ciq_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def CIQ_cherry_pick_commit_standardization(lines, commit, tags=None, jira="", op
# will atttempt to read these lines and email everyone on the list. We do not want
# to annoy the community when doing our own work.
for i in range(5, len(lines)):
# The (cherry Picked from commit: <sha1>) line is the indicator we cherry-picked
if lines[i].startswith("cherry picked from commit"):
# The (cherry picked from commit <sha1>) line is the indicator we cherry-picked
if lines[i].lstrip().startswith("(cherry picked from commit"):
break
if (
lines[i].startswith("Signed-off-by")
Expand Down
31 changes: 31 additions & 0 deletions tests/kt/ktlib/test_ciq_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from kt.ktlib.ciq_helpers import CIQ_cherry_pick_commit_standardization

UPSTREAM_SHA = "1234567890abcdef1234567890abcdef12345678"
AUTHOR_TAG = "commit-author Upstream Author <author@example.com>"


def standardized_cherry_pick_msg():
"""Run standardization on commit message lines mimicking MERGE_MSG after `git cherry-pick -nsx`."""
lines = [
"gve: fix a bug in the driver\n",
"\n",
"Some body text describing the fix.\n",
"\n",
"Signed-off-by: Upstream Author <author@example.com>\n",
"Reviewed-by: Upstream Reviewer <reviewer@example.com>\n",
f"(cherry picked from commit {UPSTREAM_SHA})\n",
"Signed-off-by: Backporter <backporter@example.com>\n",
]
return CIQ_cherry_pick_commit_standardization(lines, UPSTREAM_SHA, tags=[AUTHOR_TAG], jira="VULN-123")


def test_cherry_pick_standardization_indents_upstream_trailers():
lines = standardized_cherry_pick_msg()
assert "\tSigned-off-by: Upstream Author <author@example.com>\n" in lines
assert "\tReviewed-by: Upstream Reviewer <reviewer@example.com>\n" in lines


def test_cherry_pick_standardization_stops_indenting_at_marker():
lines = standardized_cherry_pick_msg()
assert lines[-2] == f"(cherry picked from commit {UPSTREAM_SHA})\n"
assert lines[-1] == "Signed-off-by: Backporter <backporter@example.com>\n"