Git fork
at reftables-rust 131 lines 3.8 kB view raw
1#!/bin/sh 2 3test_description='git rebase --abort tests' 4 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8. ./test-lib.sh 9 10test_expect_success setup ' 11 test_commit a a a && 12 git branch to-rebase && 13 14 test_commit --annotate b a b && 15 test_commit --annotate c a c && 16 17 git checkout to-rebase && 18 test_commit "merge should fail on this" a d d && 19 test_commit --annotate "merge should fail on this, too" a e pre-rebase 20' 21 22# Check that HEAD is equal to "pre-rebase" and the current branch is 23# "to-rebase" 24check_head() { 25 test_cmp_rev HEAD pre-rebase^{commit} && 26 test "$(git symbolic-ref HEAD)" = refs/heads/to-rebase 27} 28 29testrebase() { 30 type=$1 31 state_dir=$2 32 33 test_expect_success "rebase$type --abort" ' 34 # Clean up the state from the previous one 35 git reset --hard pre-rebase && 36 test_must_fail git rebase$type main && 37 test_path_is_dir "$state_dir" && 38 git rebase --abort && 39 check_head && 40 test_path_is_missing "$state_dir" 41 ' 42 43 test_expect_success "pre rebase$type head is marked as reachable" ' 44 # Clean up the state from the previous one 45 git checkout -f --detach pre-rebase && 46 test_tick && 47 git commit --amend --only -m "reworded" && 48 orig_head=$(git rev-parse HEAD) && 49 test_must_fail git rebase$type main && 50 # Stop ORIG_HEAD marking $state_dir/orig-head as reachable 51 git update-ref -d ORIG_HEAD && 52 git reflog expire --expire="$GIT_COMMITTER_DATE" --all && 53 git prune --expire=now && 54 git rebase --abort && 55 test_cmp_rev $orig_head HEAD 56 ' 57 58 test_expect_success "rebase$type --abort after --skip" ' 59 # Clean up the state from the previous one 60 git checkout -B to-rebase pre-rebase && 61 test_must_fail git rebase$type main && 62 test_path_is_dir "$state_dir" && 63 test_must_fail git rebase --skip && 64 test_cmp_rev HEAD main && 65 git rebase --abort && 66 check_head && 67 test_path_is_missing "$state_dir" 68 ' 69 70 test_expect_success "rebase$type --abort after --continue" ' 71 # Clean up the state from the previous one 72 git reset --hard pre-rebase && 73 test_must_fail git rebase$type main && 74 test_path_is_dir "$state_dir" && 75 echo c > a && 76 echo d >> a && 77 git add a && 78 test_must_fail git rebase --continue && 79 test_cmp_rev ! HEAD main && 80 git rebase --abort && 81 check_head && 82 test_path_is_missing "$state_dir" 83 ' 84 85 test_expect_success "rebase$type --abort when checking out a tag" ' 86 test_when_finished "git symbolic-ref HEAD refs/heads/to-rebase" && 87 git reset --hard a -- && 88 test_must_fail git rebase$type --onto b c pre-rebase && 89 test_cmp_rev HEAD b^{commit} && 90 git rebase --abort && 91 test_cmp_rev HEAD pre-rebase^{commit} && 92 ! git symbolic-ref HEAD 93 ' 94 95 test_expect_success "rebase$type --abort does not update reflog" ' 96 # Clean up the state from the previous one 97 git reset --hard pre-rebase && 98 git reflog show to-rebase > reflog_before && 99 test_must_fail git rebase$type main && 100 git rebase --abort && 101 git reflog show to-rebase > reflog_after && 102 test_cmp reflog_before reflog_after && 103 rm reflog_before reflog_after 104 ' 105 106 test_expect_success 'rebase --abort can not be used with other options' ' 107 # Clean up the state from the previous one 108 git reset --hard pre-rebase && 109 test_must_fail git rebase$type main && 110 test_must_fail git rebase -v --abort && 111 test_must_fail git rebase --abort -v && 112 git rebase --abort 113 ' 114 115 test_expect_success "rebase$type --quit" ' 116 test_when_finished "git symbolic-ref HEAD refs/heads/to-rebase" && 117 # Clean up the state from the previous one 118 git reset --hard pre-rebase && 119 test_must_fail git rebase$type main && 120 test_path_is_dir $state_dir && 121 head_before=$(git rev-parse HEAD) && 122 git rebase --quit && 123 test_cmp_rev HEAD $head_before && 124 test_path_is_missing .git/rebase-apply 125 ' 126} 127 128testrebase " --apply" .git/rebase-apply 129testrebase " --merge" .git/rebase-merge 130 131test_done