git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] t/t3515-cherry-pick-rebase.sh: new testcase demonstrating broken behavior

From
Vegard Nossum <vegard.nossum@oracle.com>
Date
Feb 2, 2024, 09:18 UTC
Message-ID
<20240202091850.160203-1-vegard.nossum@oracle.com>

Running "git cherry-pick" as an x-command in the rebase plan loses the original authorship information.

Write a known-broken test case for this:
    $ (cd t && ./t3515-cherry-pick-rebase.sh)
    ok 1 - setup
    ok 2 - cherry-pick preserves authorship information
    not ok 3 - cherry-pick inside rebase preserves authorship information # TODO known breakage
    # still have 1 known breakage(s)
    # passed all remaining 2 test(s)
    1..3
Running with --verbose we see the diff between expected and actual:
    --- expected    2024-02-02 08:54:48.954753285 +0000
    +++ actual      2024-02-02 08:54:48.966753294 +0000
    @@ -1 +1 @@
    -Original Author
    +A U Thor

As far as I can tell, this is due to the check in print_advice() which deletes CHERRY_PICK_HEAD when GIT_CHERRY_PICK_HELP is set, but I'm not sure what a good fix would be.

Cc: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
---
 t/t3515-cherry-pick-rebase.sh | 37 +++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100755 t/t3515-cherry-pick-rebase.sh
diff --git a/t/t3515-cherry-pick-rebase.sh b/t/t3515-cherry-pick-rebase.sh
new file mode 100755
index 0000000000..ffe6f5fe2a
--- /dev/null
+++ b/t/t3515-cherry-pick-rebase.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+test_description='test cherry-pick during a rebase'
+
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+. ./test-lib.sh
+
+test_expect_success setup '
+	test_commit --author "Original Author <original.author@example.com>" foo file contents1 &&
+	git checkout -b feature &&
+	test_commit --author "Another Author <another.author@example.com>" bar file contents2
+'
+
+test_expect_success 'cherry-pick preserves authorship information' '
+	git checkout -B tmp feature &&
+	test_must_fail git cherry-pick foo &&
+	git add file &&
+	git commit --no-edit &&
+	git log -1 --format='%an' foo >expected &&
+	git log -1 --format='%an' >actual &&
+	test_cmp expected actual
+'
+
+test_expect_failure 'cherry-pick inside rebase preserves authorship information' '
+	git checkout -B tmp feature &&
+	echo "x git cherry-pick -x foo" >rebase-plan &&
+	test_must_fail env GIT_SEQUENCE_EDITOR="cp rebase-plan" git rebase -i feature &&
+	git add file &&
+	git commit --no-edit &&
+	git log -1 --format='%an' foo >expected &&
+	git log -1 --format='%an' >actual &&
+	test_cmp expected actual
+'
+
+test_done
-- 
2.34.1
Next: Phillip Wood
Message 1 of 16 in “t/t3515-cherry-pick-rebase.sh: new testcase demonstrating broken behavior”
  1. t/t3515-cherry-pick-rebase.sh: new testcase demonstrating broken behaviorVegard Nossum, Feb 2, 2024
  2. Phillip WoodFeb 4, 2024
  3. 2/2 sequencer: unset GIT_CHERRY_PICK_HELP for 'exec' commandsVegard Nossum, Feb 5, 2024
  4. Kristoffer HaugsbakkFeb 5, 2024
  5. Junio C HamanoFeb 5, 2024
  6. Vegard NossumFeb 5, 2024
  7. Junio C HamanoFeb 6, 2024
  8. Phillip WoodFeb 7, 2024
  9. Junio C HamanoFeb 7, 2024
  10. Vegard NossumFeb 8, 2024
  11. Phillip WoodFeb 8, 2024
  12. Junio C HamanoFeb 8, 2024
  13. Phillip WoodFeb 11, 2024
  14. Junio C HamanoFeb 11, 2024
  15. Vegard NossumFeb 15, 2024
  16. Junio C HamanoFeb 15, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.