summaryrefslogtreecommitdiff
path: root/t/t3404-rebase-interactive.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t3404-rebase-interactive.sh')
-rwxr-xr-xt/t3404-rebase-interactive.sh273
1 files changed, 273 insertions, 0 deletions
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index f31afd4..688b01e 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1743,6 +1743,279 @@ test_expect_success 'ORIG_HEAD is updated correctly' '
test_cmp_rev ORIG_HEAD test-orig-head@{1}
'
+test_expect_success '--update-refs adds label and update-ref commands' '
+ git checkout -b update-refs no-conflict-branch &&
+ git branch -f base HEAD~4 &&
+ git branch -f first HEAD~3 &&
+ git branch -f second HEAD~3 &&
+ git branch -f third HEAD~1 &&
+ git commit --allow-empty --fixup=third &&
+ git branch -f is-not-reordered &&
+ git commit --allow-empty --fixup=HEAD~4 &&
+ git branch -f shared-tip &&
+ (
+ set_cat_todo_editor &&
+
+ cat >expect <<-EOF &&
+ pick $(git log -1 --format=%h J) J
+ fixup $(git log -1 --format=%h update-refs) fixup! J # empty
+ update-ref refs/heads/second
+ update-ref refs/heads/first
+ pick $(git log -1 --format=%h K) K
+ pick $(git log -1 --format=%h L) L
+ fixup $(git log -1 --format=%h is-not-reordered) fixup! L # empty
+ update-ref refs/heads/third
+ pick $(git log -1 --format=%h M) M
+ update-ref refs/heads/no-conflict-branch
+ update-ref refs/heads/is-not-reordered
+ update-ref refs/heads/shared-tip
+ EOF
+
+ test_must_fail git rebase -i --autosquash --update-refs primary >todo &&
+ test_cmp expect todo &&
+
+ test_must_fail git -c rebase.autosquash=true \
+ -c rebase.updaterefs=true \
+ rebase -i primary >todo &&
+
+ test_cmp expect todo
+ )
+'
+
+test_expect_success '--update-refs adds commands with --rebase-merges' '
+ git checkout -b update-refs-with-merge no-conflict-branch &&
+ git branch -f base HEAD~4 &&
+ git branch -f first HEAD~3 &&
+ git branch -f second HEAD~3 &&
+ git branch -f third HEAD~1 &&
+ git merge -m merge branch2 &&
+ git branch -f merge-branch &&
+ git commit --fixup=third --allow-empty &&
+ (
+ set_cat_todo_editor &&
+
+ cat >expect <<-EOF &&
+ label onto
+ reset onto
+ pick $(git log -1 --format=%h branch2~1) F
+ pick $(git log -1 --format=%h branch2) I
+ update-ref refs/heads/branch2
+ label merge
+ reset onto
+ pick $(git log -1 --format=%h refs/heads/second) J
+ update-ref refs/heads/second
+ update-ref refs/heads/first
+ pick $(git log -1 --format=%h refs/heads/third~1) K
+ pick $(git log -1 --format=%h refs/heads/third) L
+ fixup $(git log -1 --format=%h update-refs-with-merge) fixup! L # empty
+ update-ref refs/heads/third
+ pick $(git log -1 --format=%h HEAD~2) M
+ update-ref refs/heads/no-conflict-branch
+ merge -C $(git log -1 --format=%h HEAD~1) merge # merge
+ update-ref refs/heads/merge-branch
+ EOF
+
+ test_must_fail git rebase -i --autosquash \
+ --rebase-merges=rebase-cousins \
+ --update-refs primary >todo &&
+
+ test_cmp expect todo &&
+
+ test_must_fail git -c rebase.autosquash=true \
+ -c rebase.updaterefs=true \
+ rebase -i \
+ --rebase-merges=rebase-cousins \
+ primary >todo &&
+
+ test_cmp expect todo
+ )
+'
+
+test_expect_success '--update-refs updates refs correctly' '
+ git checkout -B update-refs no-conflict-branch &&
+ git branch -f base HEAD~4 &&
+ git branch -f first HEAD~3 &&
+ git branch -f second HEAD~3 &&
+ git branch -f third HEAD~1 &&
+ test_commit extra2 fileX &&
+ git commit --amend --fixup=L &&
+
+ git rebase -i --autosquash --update-refs primary 2>err &&
+
+ test_cmp_rev HEAD~3 refs/heads/first &&
+ test_cmp_rev HEAD~3 refs/heads/second &&
+ test_cmp_rev HEAD~1 refs/heads/third &&
+ test_cmp_rev HEAD refs/heads/no-conflict-branch &&
+
+ cat >expect <<-\EOF &&
+ Successfully rebased and updated refs/heads/update-refs.
+ Updated the following refs with --update-refs:
+ refs/heads/first
+ refs/heads/no-conflict-branch
+ refs/heads/second
+ refs/heads/third
+ EOF
+
+ # Clear "Rebasing (X/Y)" progress lines and drop leading tabs.
+ sed -e "s/Rebasing.*Successfully/Successfully/g" -e "s/^\t//g" \
+ <err >err.trimmed &&
+ test_cmp expect err.trimmed
+'
+
+test_expect_success 'respect user edits to update-ref steps' '
+ git checkout -B update-refs-break no-conflict-branch &&
+ git branch -f base HEAD~4 &&
+ git branch -f first HEAD~3 &&
+ git branch -f second HEAD~3 &&
+ git branch -f third HEAD~1 &&
+ git branch -f unseen base &&
+
+ # First, we will add breaks to the expected todo file
+ cat >fake-todo-1 <<-EOF &&
+ pick $(git rev-parse HEAD~3)
+ break
+ update-ref refs/heads/second
+ update-ref refs/heads/first
+
+ pick $(git rev-parse HEAD~2)
+ pick $(git rev-parse HEAD~1)
+ update-ref refs/heads/third
+
+ pick $(git rev-parse HEAD)
+ update-ref refs/heads/no-conflict-branch
+ EOF
+
+ # Second, we will drop some update-refs commands (and move one)
+ cat >fake-todo-2 <<-EOF &&
+ update-ref refs/heads/second
+
+ pick $(git rev-parse HEAD~2)
+ update-ref refs/heads/third
+ pick $(git rev-parse HEAD~1)
+ break
+
+ pick $(git rev-parse HEAD)
+ EOF
+
+ # Third, we will:
+ # * insert a new one (new-branch),
+ # * re-add an old one (first), and
+ # * add a second instance of a previously-stored one (second)
+ cat >fake-todo-3 <<-EOF &&
+ update-ref refs/heads/unseen
+ update-ref refs/heads/new-branch
+ pick $(git rev-parse HEAD)
+ update-ref refs/heads/first
+ update-ref refs/heads/second
+ EOF
+
+ (
+ set_replace_editor fake-todo-1 &&
+ git rebase -i --update-refs primary &&
+
+ # These branches are currently locked.
+ for b in first second third no-conflict-branch
+ do
+ test_must_fail git branch -f $b base || return 1
+ done &&
+
+ set_replace_editor fake-todo-2 &&
+ git rebase --edit-todo &&
+
+ # These branches are currently locked.
+ for b in second third
+ do
+ test_must_fail git branch -f $b base || return 1
+ done &&
+
+ # These branches are currently unlocked for checkout.
+ for b in first no-conflict-branch
+ do
+ git worktree add wt-$b $b &&
+ git worktree remove wt-$b || return 1
+ done &&
+
+ git rebase --continue &&
+
+ set_replace_editor fake-todo-3 &&
+ git rebase --edit-todo &&
+
+ # These branches are currently locked.
+ for b in second third first unseen
+ do
+ test_must_fail git branch -f $b base || return 1
+ done &&
+
+ # These branches are currently unlocked for checkout.
+ for b in no-conflict-branch
+ do
+ git worktree add wt-$b $b &&
+ git worktree remove wt-$b || return 1
+ done &&
+
+ git rebase --continue
+ ) &&
+
+ test_cmp_rev HEAD~2 refs/heads/third &&
+ test_cmp_rev HEAD~1 refs/heads/unseen &&
+ test_cmp_rev HEAD~1 refs/heads/new-branch &&
+ test_cmp_rev HEAD refs/heads/first &&
+ test_cmp_rev HEAD refs/heads/second &&
+ test_cmp_rev HEAD refs/heads/no-conflict-branch
+'
+
+test_expect_success '--update-refs: check failed ref update' '
+ git checkout -B update-refs-error no-conflict-branch &&
+ git branch -f base HEAD~4 &&
+ git branch -f first HEAD~3 &&
+ git branch -f second HEAD~2 &&
+ git branch -f third HEAD~1 &&
+
+ cat >fake-todo <<-EOF &&
+ pick $(git rev-parse HEAD~3)
+ break
+ update-ref refs/heads/first
+
+ pick $(git rev-parse HEAD~2)
+ update-ref refs/heads/second
+
+ pick $(git rev-parse HEAD~1)
+ update-ref refs/heads/third
+
+ pick $(git rev-parse HEAD)
+ update-ref refs/heads/no-conflict-branch
+ EOF
+
+ (
+ set_replace_editor fake-todo &&
+ git rebase -i --update-refs base
+ ) &&
+
+ # At this point, the values of first, second, and third are
+ # recorded in the update-refs file. We will force-update the
+ # "second" ref, but "git branch -f" will not work because of
+ # the lock in the update-refs file.
+ git rev-parse third >.git/refs/heads/second &&
+
+ test_must_fail git rebase --continue 2>err &&
+ grep "update_ref failed for ref '\''refs/heads/second'\''" err &&
+
+ cat >expect <<-\EOF &&
+ Updated the following refs with --update-refs:
+ refs/heads/first
+ refs/heads/no-conflict-branch
+ refs/heads/third
+ Failed to update the following refs with --update-refs:
+ refs/heads/second
+ EOF
+
+ # Clear "Rebasing (X/Y)" progress lines and drop leading tabs.
+ tail -n 6 err >err.last &&
+ sed -e "s/Rebasing.*Successfully/Successfully/g" -e "s/^\t//g" \
+ <err.last >err.trimmed &&
+ test_cmp expect err.trimmed
+'
+
# This must be the last test in this file
test_expect_success '$EDITOR and friends are unchanged' '
test_editor_unchanged