From 609f79a714314e1e46fe3b61ed983b6f14308bb3 Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Mon, 10 Aug 2026 18:00:30 -0700 Subject: [PATCH 1/2] kt/ktlib/ciq_helpers.py: Fix the cherry-pick marker check The trailer-indent loop in CIQ_cherry_pick_commit_standardization() is meant to stop indenting once it hits the marker line that git cherry-pick -x writes, but it tests for a line starting with "cherry picked from commit" while git actually writes "(cherry picked from commit )". The leading parenthesis means the break never fires, so the loop runs past the marker and tab-indents the backporter's own Signed-off-by that cherry-pick -s appends below it. As a result, every backport made through this helper ends up with its trailing Signed-off-by indented. Fix it by matching the line git actually writes. Trailers above the marker still get their tab, while the marker and everything below it are now left untouched. Add a test covering both sides of the marker. Co-authored-by: Claude Fable 5 --- kt/ktlib/ciq_helpers.py | 4 ++-- tests/kt/ktlib/test_ciq_helpers.py | 31 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/kt/ktlib/test_ciq_helpers.py diff --git a/kt/ktlib/ciq_helpers.py b/kt/ktlib/ciq_helpers.py index de9d4a3..05b0c4e 100644 --- a/kt/ktlib/ciq_helpers.py +++ b/kt/ktlib/ciq_helpers.py @@ -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: ) line is the indicator we cherry-picked - if lines[i].startswith("cherry picked from commit"): + # The (cherry picked from commit ) line is the indicator we cherry-picked + if lines[i].lstrip().startswith("(cherry picked from commit"): break if ( lines[i].startswith("Signed-off-by") diff --git a/tests/kt/ktlib/test_ciq_helpers.py b/tests/kt/ktlib/test_ciq_helpers.py new file mode 100644 index 0000000..d88668e --- /dev/null +++ b/tests/kt/ktlib/test_ciq_helpers.py @@ -0,0 +1,31 @@ +from kt.ktlib.ciq_helpers import CIQ_cherry_pick_commit_standardization + +UPSTREAM_SHA = "1234567890abcdef1234567890abcdef12345678" +AUTHOR_TAG = "commit-author Upstream Author " + + +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 \n", + "Reviewed-by: Upstream Reviewer \n", + f"(cherry picked from commit {UPSTREAM_SHA})\n", + "Signed-off-by: Backporter \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 \n" in lines + assert "\tReviewed-by: Upstream Reviewer \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 \n" From 3960b7111f2ddfb7f1c82cab44866c7018af3eac Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Mon, 10 Aug 2026 18:00:38 -0700 Subject: [PATCH 2/2] ciq-cherry-pick.py: Drop git's conflict comment block from MERGE_MSG When a cherry-pick hits a conflict, git appends a comment block to MERGE_MSG ("# Conflicts:" followed by the conflicted paths). manage_commit_message() reads MERGE_MSG, inserts the CIQ header block, and writes the whole thing back, conflict comments included. The script then exits telling the user to resolve the conflict and commit, and committing with -F keeps those lines, since -F's default cleanup mode only strips whitespace, not comments. The conflict block winds up in the final commit message verbatim. Fix it by dropping the tail of the message starting at the "# Conflicts:" line before standardizing. Only the trailing git-generated block goes; legitimate body lines starting with "#" earlier in the message survive. Co-authored-by: Claude Fable 5 --- ciq-cherry-pick.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ciq-cherry-pick.py b/ciq-cherry-pick.py index 3a7194b..fa92364 100644 --- a/ciq-cherry-pick.py +++ b/ciq-cherry-pick.py @@ -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