aboutsummaryrefslogtreecommitdiffstats
path: root/t/t3650-replay-basics.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-11-24 15:46:40 -0800
committerJunio C Hamano <gitster@pobox.com>2025-11-24 15:46:40 -0800
commit9370a6be79e89112486e99ff75db43e3c15841e5 (patch)
tree68c2609a477422028e30c5916e649bacfbd51529 /t/t3650-replay-basics.sh
parentd91d79f26d5f2fb0468f42bf5d44356dce15a414 (diff)
parent336ac90c06ec757f613faae4ffc6c32578a99cd1 (diff)
downloadgit-9370a6be79e89112486e99ff75db43e3c15841e5.tar.gz
Merge branch 'sa/replay-atomic-ref-updates'
"git replay" (experimental) learned to perform ref updates itself in a transaction by default, instead of emitting where each refs should point at and leaving the actual update to another command. * sa/replay-atomic-ref-updates: replay: add replay.refAction config option replay: make atomic ref updates the default behavior replay: use die_for_incompatible_opt2() for option validation
Diffstat (limited to 't/t3650-replay-basics.sh')
-rwxr-xr-xt/t3650-replay-basics.sh113
1 files changed, 105 insertions, 8 deletions
diff --git a/t/t3650-replay-basics.sh b/t/t3650-replay-basics.sh
index 58b3759935..cf3aacf355 100755
--- a/t/t3650-replay-basics.sh
+++ b/t/t3650-replay-basics.sh
@@ -52,7 +52,7 @@ test_expect_success 'setup bare' '
'
test_expect_success 'using replay to rebase two branches, one on top of other' '
- git replay --onto main topic1..topic2 >result &&
+ git replay --ref-action=print --onto main topic1..topic2 >result &&
test_line_count = 1 result &&
@@ -68,7 +68,7 @@ test_expect_success 'using replay to rebase two branches, one on top of other' '
'
test_expect_success 'using replay on bare repo to rebase two branches, one on top of other' '
- git -C bare replay --onto main topic1..topic2 >result-bare &&
+ git -C bare replay --ref-action=print --onto main topic1..topic2 >result-bare &&
test_cmp expect result-bare
'
@@ -86,7 +86,7 @@ test_expect_success 'using replay to perform basic cherry-pick' '
# 2nd field of result is refs/heads/main vs. refs/heads/topic2
# 4th field of result is hash for main instead of hash for topic2
- git replay --advance main topic1..topic2 >result &&
+ git replay --ref-action=print --advance main topic1..topic2 >result &&
test_line_count = 1 result &&
@@ -102,7 +102,7 @@ test_expect_success 'using replay to perform basic cherry-pick' '
'
test_expect_success 'using replay on bare repo to perform basic cherry-pick' '
- git -C bare replay --advance main topic1..topic2 >result-bare &&
+ git -C bare replay --ref-action=print --advance main topic1..topic2 >result-bare &&
test_cmp expect result-bare
'
@@ -115,7 +115,7 @@ test_expect_success 'replay fails when both --advance and --onto are omitted' '
'
test_expect_success 'using replay to also rebase a contained branch' '
- git replay --contained --onto main main..topic3 >result &&
+ git replay --ref-action=print --contained --onto main main..topic3 >result &&
test_line_count = 2 result &&
cut -f 3 -d " " result >new-branch-tips &&
@@ -139,12 +139,12 @@ test_expect_success 'using replay to also rebase a contained branch' '
'
test_expect_success 'using replay on bare repo to also rebase a contained branch' '
- git -C bare replay --contained --onto main main..topic3 >result-bare &&
+ git -C bare replay --ref-action=print --contained --onto main main..topic3 >result-bare &&
test_cmp expect result-bare
'
test_expect_success 'using replay to rebase multiple divergent branches' '
- git replay --onto main ^topic1 topic2 topic4 >result &&
+ git replay --ref-action=print --onto main ^topic1 topic2 topic4 >result &&
test_line_count = 2 result &&
cut -f 3 -d " " result >new-branch-tips &&
@@ -168,7 +168,7 @@ test_expect_success 'using replay to rebase multiple divergent branches' '
'
test_expect_success 'using replay on bare repo to rebase multiple divergent branches, including contained ones' '
- git -C bare replay --contained --onto main ^main topic2 topic3 topic4 >result &&
+ git -C bare replay --ref-action=print --contained --onto main ^main topic2 topic3 topic4 >result &&
test_line_count = 4 result &&
cut -f 3 -d " " result >new-branch-tips &&
@@ -217,4 +217,101 @@ test_expect_success 'merge.directoryRenames=false' '
--onto rename-onto rename-onto..rename-from
'
+test_expect_success 'default atomic behavior updates refs directly' '
+ # Use a separate branch to avoid contaminating topic2 for later tests
+ git branch test-atomic topic2 &&
+ test_when_finished "git branch -D test-atomic" &&
+
+ # Test default atomic behavior (no output, refs updated)
+ git replay --onto main topic1..test-atomic >output &&
+ test_must_be_empty output &&
+
+ # Verify ref was updated
+ git log --format=%s test-atomic >actual &&
+ test_write_lines E D M L B A >expect &&
+ test_cmp expect actual &&
+
+ # Verify reflog message includes SHA of onto commit
+ git reflog test-atomic -1 --format=%gs >reflog-msg &&
+ ONTO_SHA=$(git rev-parse main) &&
+ echo "replay --onto $ONTO_SHA" >expect-reflog &&
+ test_cmp expect-reflog reflog-msg
+'
+
+test_expect_success 'atomic behavior in bare repository' '
+ # Store original state for cleanup
+ START=$(git -C bare rev-parse topic2) &&
+ test_when_finished "git -C bare update-ref refs/heads/topic2 $START" &&
+
+ # Test atomic updates work in bare repo
+ git -C bare replay --onto main topic1..topic2 >output &&
+ test_must_be_empty output &&
+
+ # Verify ref was updated in bare repo
+ git -C bare log --format=%s topic2 >actual &&
+ test_write_lines E D M L B A >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'reflog message for --advance mode' '
+ # Store original state
+ START=$(git rev-parse main) &&
+ test_when_finished "git update-ref refs/heads/main $START" &&
+
+ # Test --advance mode reflog message
+ git replay --advance main topic1..topic2 >output &&
+ test_must_be_empty output &&
+
+ # Verify reflog message includes --advance and branch name
+ git reflog main -1 --format=%gs >reflog-msg &&
+ echo "replay --advance main" >expect-reflog &&
+ test_cmp expect-reflog reflog-msg
+'
+
+test_expect_success 'replay.refAction=print config option' '
+ # Store original state
+ START=$(git rev-parse topic2) &&
+ test_when_finished "git branch -f topic2 $START" &&
+
+ # Test with config set to print
+ test_config replay.refAction print &&
+ git replay --onto main topic1..topic2 >output &&
+ test_line_count = 1 output &&
+ test_grep "^update refs/heads/topic2 " output
+'
+
+test_expect_success 'replay.refAction=update config option' '
+ # Store original state
+ START=$(git rev-parse topic2) &&
+ test_when_finished "git branch -f topic2 $START" &&
+
+ # Test with config set to update
+ test_config replay.refAction update &&
+ git replay --onto main topic1..topic2 >output &&
+ test_must_be_empty output &&
+
+ # Verify ref was updated
+ git log --format=%s topic2 >actual &&
+ test_write_lines E D M L B A >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'command-line --ref-action overrides config' '
+ # Store original state
+ START=$(git rev-parse topic2) &&
+ test_when_finished "git branch -f topic2 $START" &&
+
+ # Set config to update but use --ref-action=print
+ test_config replay.refAction update &&
+ git replay --ref-action=print --onto main topic1..topic2 >output &&
+ test_line_count = 1 output &&
+ test_grep "^update refs/heads/topic2 " output
+'
+
+test_expect_success 'invalid replay.refAction value' '
+ test_config replay.refAction invalid &&
+ test_must_fail git replay --onto main topic1..topic2 2>error &&
+ test_grep "invalid.*replay.refAction.*value" error
+'
+
test_done