interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t3407-rebase-abort.sh

135 lines · 3965 bytes Raw Blame History
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 show-ref --verify AUTO_MERGE &&
39 test_cmp_rev d REBASE_HEAD &&
40 git rebase --abort &&
41 test_ref_missing AUTO_MERGE &&
42 test_ref_missing REBASE_HEAD &&
43 check_head &&
44 test_path_is_missing "$state_dir"
45 '
46
47 test_expect_success "pre rebase$type head is marked as reachable" '
48 # Clean up the state from the previous one
49 git checkout -f --detach pre-rebase &&
50 test_tick &&
51 git commit --amend --only -m "reworded" &&
52 orig_head=$(git rev-parse HEAD) &&
53 test_must_fail git rebase$type main &&
54 # Stop ORIG_HEAD marking $state_dir/orig-head as reachable
55 git update-ref -d ORIG_HEAD &&
56 git reflog expire --expire="$GIT_COMMITTER_DATE" --all &&
57 git prune --expire=now &&
58 git rebase --abort &&
59 test_cmp_rev $orig_head HEAD
60 '
61
62 test_expect_success "rebase$type --abort after --skip" '
63 # Clean up the state from the previous one
64 git checkout -B to-rebase pre-rebase &&
65 test_must_fail git rebase$type main &&
66 test_path_is_dir "$state_dir" &&
67 test_must_fail git rebase --skip &&
68 test_cmp_rev HEAD main &&
69 git rebase --abort &&
70 check_head &&
71 test_path_is_missing "$state_dir"
72 '
73
74 test_expect_success "rebase$type --abort after --continue" '
75 # Clean up the state from the previous one
76 git reset --hard pre-rebase &&
77 test_must_fail git rebase$type main &&
78 test_path_is_dir "$state_dir" &&
79 echo c > a &&
80 echo d >> a &&
81 git add a &&
82 test_must_fail git rebase --continue &&
83 test_cmp_rev ! HEAD main &&
84 git rebase --abort &&
85 check_head &&
86 test_path_is_missing "$state_dir"
87 '
88
89 test_expect_success "rebase$type --abort when checking out a tag" '
90 test_when_finished "git symbolic-ref HEAD refs/heads/to-rebase" &&
91 git reset --hard a -- &&
92 test_must_fail git rebase$type --onto b c pre-rebase &&
93 test_cmp_rev HEAD b^{commit} &&
94 git rebase --abort &&
95 test_cmp_rev HEAD pre-rebase^{commit} &&
96 ! git symbolic-ref HEAD
97 '
98
99 test_expect_success "rebase$type --abort does not update reflog" '
100 # Clean up the state from the previous one
101 git reset --hard pre-rebase &&
102 git reflog show to-rebase > reflog_before &&
103 test_must_fail git rebase$type main &&
104 git rebase --abort &&
105 git reflog show to-rebase > reflog_after &&
106 test_cmp reflog_before reflog_after &&
107 rm reflog_before reflog_after
108 '
109
110 test_expect_success 'rebase --abort can not be used with other options' '
111 # Clean up the state from the previous one
112 git reset --hard pre-rebase &&
113 test_must_fail git rebase$type main &&
114 test_must_fail git rebase -v --abort &&
115 test_must_fail git rebase --abort -v &&
116 git rebase --abort
117 '
118
119 test_expect_success "rebase$type --quit" '
120 test_when_finished "git symbolic-ref HEAD refs/heads/to-rebase" &&
121 # Clean up the state from the previous one
122 git reset --hard pre-rebase &&
123 test_must_fail git rebase$type main &&
124 test_path_is_dir $state_dir &&
125 head_before=$(git rev-parse HEAD) &&
126 git rebase --quit &&
127 test_cmp_rev HEAD $head_before &&
128 test_path_is_missing .git/rebase-apply
129 '
130}
131
132testrebase " --apply" .git/rebase-apply
133testrebase " --merge" .git/rebase-merge
134
135test_done