aboutsummaryrefslogtreecommitdiffstats
path: root/t/t3650-replay-basics.sh
diff options
context:
space:
mode:
authorSiddharth Asthana <siddharthasthana31@gmail.com>2025-11-06 00:46:00 +0530
committerJunio C Hamano <gitster@pobox.com>2025-11-05 13:34:55 -0800
commit15cd4ef1f495e51f7db39583b7f562e7170da3d2 (patch)
tree69b252a113cb75a143bbb4409a947c0307d2612e /t/t3650-replay-basics.sh
parentreplay: use die_for_incompatible_opt2() for option validation (diff)
downloadgit-15cd4ef1f495e51f7db39583b7f562e7170da3d2.tar.gz
git-15cd4ef1f495e51f7db39583b7f562e7170da3d2.zip
replay: make atomic ref updates the default behavior
The git replay command currently outputs update commands that can be piped to update-ref to achieve a rebase, e.g. git replay --onto main topic1..topic2 | git update-ref --stdin This separation had advantages for three special cases: * it made testing easy (when state isn't modified from one step to the next, you don't need to make temporary branches or have undo commands, or try to track the changes) * it provided a natural can-it-rebase-cleanly (and what would it rebase to) capability without automatically updating refs, similar to a --dry-run * it provided a natural low-level tool for the suite of hash-object, mktree, commit-tree, mktag, merge-tree, and update-ref, allowing users to have another building block for experimentation and making new tools However, it should be noted that all three of these are somewhat special cases; users, whether on the client or server side, would almost certainly find it more ergonomic to simply have the updating of refs be the default. For server-side operations in particular, the pipeline architecture creates process coordination overhead. Server implementations that need to perform rebases atomically must maintain additional code to: 1. Spawn and manage a pipeline between git-replay and git-update-ref 2. Coordinate stdout/stderr streams across the pipe boundary 3. Handle partial failure states if the pipeline breaks mid-execution 4. Parse and validate the update-ref command output Change the default behavior to update refs directly, and atomically (at least to the extent supported by the refs backend in use). This eliminates the process coordination overhead for the common case. For users needing the traditional pipeline workflow, add a new --ref-action=<mode> option that preserves the original behavior: git replay --ref-action=print --onto main topic1..topic2 | git update-ref --stdin The mode can be: * update (default): Update refs directly using an atomic transaction * print: Output update-ref commands for pipeline use Test suite changes: All existing tests that expected command output now use --ref-action=print to preserve their original behavior. This keeps the tests valid while allowing them to verify that the pipeline workflow still works correctly. New tests were added to verify: - Default atomic behavior (no output, refs updated directly) - Bare repository support (server-side use case) - Equivalence between traditional pipeline and atomic updates - Real atomicity using a lock file to verify all-or-nothing guarantee - Test isolation using test_when_finished to clean up state - Reflog messages include replay mode and target A following commit will add a replay.refAction configuration option for users who prefer the traditional pipeline output as their default behavior. Helped-by: Elijah Newren <newren@gmail.com> Helped-by: Patrick Steinhardt <ps@pks.im> Helped-by: Christian Couder <christian.couder@gmail.com> Helped-by: Phillip Wood <phillip.wood123@gmail.com> Signed-off-by: Siddharth Asthana <siddharthasthana31@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rwxr-xr-xt/t3650-replay-basics.sh67
1 files changed, 59 insertions, 8 deletions
diff --git a/t/t3650-replay-basics.sh b/t/t3650-replay-basics.sh
index 58b3759935..ec79234c80 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,55 @@ 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_done