]>
Commit | Line | Data |
---|---|---|
3e5057a8 NS |
1 | #!/bin/sh |
2 | ||
3 | test_description='am --abort' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success setup ' | |
8 | for i in a b c d e f g | |
9 | do | |
10 | echo $i | |
11 | done >file-1 && | |
12 | cp file-1 file-2 && | |
13 | test_tick && | |
14 | git add file-1 file-2 && | |
15 | git commit -m initial && | |
16 | git tag initial && | |
e06764c8 | 17 | git format-patch --stdout --root initial >initial.patch && |
95f8ebbf | 18 | for i in 2 3 4 5 6 |
3e5057a8 NS |
19 | do |
20 | echo $i >>file-1 && | |
9944d1a0 OM |
21 | echo $i >otherfile-$i && |
22 | git add otherfile-$i && | |
3e5057a8 | 23 | test_tick && |
e6821d09 | 24 | git commit -a -m $i || return 1 |
3e5057a8 | 25 | done && |
a567fdcb | 26 | git format-patch --no-numbered initial && |
3e5057a8 NS |
27 | git checkout -b side initial && |
28 | echo local change >file-2-expect | |
29 | ' | |
30 | ||
31 | for with3 in '' ' -3' | |
32 | do | |
33 | test_expect_success "am$with3 stops at a patch that does not apply" ' | |
34 | ||
35 | git reset --hard initial && | |
36 | cp file-2-expect file-2 && | |
37 | ||
95f8ebbf | 38 | test_must_fail git am$with3 000[1245]-*.patch && |
3e5057a8 NS |
39 | git log --pretty=tformat:%s >actual && |
40 | for i in 3 2 initial | |
41 | do | |
42 | echo $i | |
43 | done >expect && | |
44 | test_cmp expect actual | |
45 | ' | |
46 | ||
95f8ebbf | 47 | test_expect_success "am$with3 --skip continue after failed am$with3" ' |
3604e7c5 | 48 | test_must_fail git am$with3 --skip >output && |
dee8b71e RJ |
49 | test_i18ngrep "^Applying: 6$" output && |
50 | test_cmp file-2-expect file-2 && | |
3ca399d4 | 51 | test ! -f .git/MERGE_RR |
95f8ebbf OM |
52 | ' |
53 | ||
3e5057a8 | 54 | test_expect_success "am --abort goes back after failed am$with3" ' |
3604e7c5 | 55 | git am --abort && |
3e5057a8 NS |
56 | git rev-parse HEAD >actual && |
57 | git rev-parse initial >expect && | |
58 | test_cmp expect actual && | |
59 | test_cmp file-2-expect file-2 && | |
60 | git diff-index --exit-code --cached HEAD && | |
3ca399d4 | 61 | test ! -f .git/MERGE_RR |
3e5057a8 NS |
62 | ' |
63 | ||
64 | done | |
65 | ||
88d50724 PT |
66 | test_expect_success 'am -3 --skip removes otherfile-4' ' |
67 | git reset --hard initial && | |
68 | test_must_fail git am -3 0003-*.patch && | |
69 | test 3 -eq $(git ls-files -u | wc -l) && | |
70 | test 4 = "$(cat otherfile-4)" && | |
71 | git am --skip && | |
72 | test_cmp_rev initial HEAD && | |
20c3fe76 PT |
73 | test -z "$(git ls-files -u)" && |
74 | test_path_is_missing otherfile-4 | |
75 | ' | |
76 | ||
77 | test_expect_success 'am -3 --abort removes otherfile-4' ' | |
78 | git reset --hard initial && | |
79 | test_must_fail git am -3 0003-*.patch && | |
80 | test 3 -eq $(git ls-files -u | wc -l) && | |
81 | test 4 = "$(cat otherfile-4)" && | |
82 | git am --abort && | |
83 | test_cmp_rev initial HEAD && | |
2bb05186 | 84 | test -z "$(git ls-files -u)" && |
88d50724 PT |
85 | test_path_is_missing otherfile-4 |
86 | ' | |
87 | ||
7b3b7e37 JH |
88 | test_expect_success 'am --abort will keep the local commits intact' ' |
89 | test_must_fail git am 0004-*.patch && | |
90 | test_commit unrelated && | |
91 | git rev-parse HEAD >expect && | |
92 | git am --abort && | |
93 | git rev-parse HEAD >actual && | |
94 | test_cmp expect actual | |
95 | ' | |
96 | ||
528484c6 PT |
97 | test_expect_success 'am --abort will keep dirty index intact' ' |
98 | git reset --hard initial && | |
99 | echo dirtyfile >dirtyfile && | |
100 | cp dirtyfile dirtyfile.expected && | |
101 | git add dirtyfile && | |
102 | test_must_fail git am 0001-*.patch && | |
103 | test_cmp_rev initial HEAD && | |
104 | test_path_is_file dirtyfile && | |
105 | test_cmp dirtyfile.expected dirtyfile && | |
106 | git am --abort && | |
107 | test_cmp_rev initial HEAD && | |
108 | test_path_is_file dirtyfile && | |
109 | test_cmp dirtyfile.expected dirtyfile | |
110 | ' | |
111 | ||
2c970c9e PT |
112 | test_expect_success 'am -3 stops on conflict on unborn branch' ' |
113 | git checkout -f --orphan orphan && | |
114 | git reset && | |
115 | rm -f otherfile-4 && | |
116 | test_must_fail git am -3 0003-*.patch && | |
117 | test 2 -eq $(git ls-files -u | wc -l) && | |
118 | test 4 = "$(cat otherfile-4)" | |
119 | ' | |
120 | ||
f8da6801 PT |
121 | test_expect_success 'am -3 --skip clears index on unborn branch' ' |
122 | test_path_is_dir .git/rebase-apply && | |
123 | echo tmpfile >tmpfile && | |
124 | git add tmpfile && | |
125 | git am --skip && | |
126 | test -z "$(git ls-files)" && | |
127 | test_path_is_missing otherfile-4 && | |
128 | test_path_is_missing tmpfile | |
129 | ' | |
130 | ||
20c3fe76 PT |
131 | test_expect_success 'am -3 --abort removes otherfile-4 on unborn branch' ' |
132 | git checkout -f --orphan orphan && | |
133 | git reset && | |
134 | rm -f otherfile-4 file-1 && | |
135 | test_must_fail git am -3 0003-*.patch && | |
136 | test 2 -eq $(git ls-files -u | wc -l) && | |
137 | test 4 = "$(cat otherfile-4)" && | |
138 | git am --abort && | |
139 | test -z "$(git ls-files -u)" && | |
140 | test_path_is_missing otherfile-4 | |
141 | ' | |
142 | ||
e06764c8 PT |
143 | test_expect_success 'am -3 --abort on unborn branch removes applied commits' ' |
144 | git checkout -f --orphan orphan && | |
145 | git reset && | |
146 | rm -f otherfile-4 otherfile-2 file-1 file-2 && | |
147 | test_must_fail git am -3 initial.patch 0003-*.patch && | |
148 | test 3 -eq $(git ls-files -u | wc -l) && | |
149 | test 4 = "$(cat otherfile-4)" && | |
150 | git am --abort && | |
151 | test -z "$(git ls-files -u)" && | |
152 | test_path_is_missing otherfile-4 && | |
153 | test_path_is_missing file-1 && | |
154 | test_path_is_missing file-2 && | |
155 | test 0 -eq $(git log --oneline 2>/dev/null | wc -l) && | |
156 | test refs/heads/orphan = "$(git symbolic-ref HEAD)" | |
157 | ' | |
158 | ||
6ea3b67b PT |
159 | test_expect_success 'am --abort on unborn branch will keep local commits intact' ' |
160 | git checkout -f --orphan orphan && | |
161 | git reset && | |
162 | test_must_fail git am 0004-*.patch && | |
163 | test_commit unrelated2 && | |
164 | git rev-parse HEAD >expect && | |
165 | git am --abort && | |
166 | git rev-parse HEAD >actual && | |
167 | test_cmp expect actual | |
168 | ' | |
169 | ||
3ecc7040 PT |
170 | test_expect_success 'am --skip leaves index stat info alone' ' |
171 | git checkout -f --orphan skip-stat-info && | |
172 | git reset && | |
173 | test_commit skip-should-be-untouched && | |
0e496492 | 174 | test-tool chmtime =0 skip-should-be-untouched.t && |
3ecc7040 PT |
175 | git update-index --refresh && |
176 | git diff-files --exit-code --quiet && | |
177 | test_must_fail git am 0001-*.patch && | |
178 | git am --skip && | |
179 | git diff-files --exit-code --quiet | |
180 | ' | |
181 | ||
182 | test_expect_success 'am --abort leaves index stat info alone' ' | |
183 | git checkout -f --orphan abort-stat-info && | |
184 | git reset && | |
185 | test_commit abort-should-be-untouched && | |
0e496492 | 186 | test-tool chmtime =0 abort-should-be-untouched.t && |
3ecc7040 PT |
187 | git update-index --refresh && |
188 | git diff-files --exit-code --quiet && | |
189 | test_must_fail git am 0001-*.patch && | |
190 | git am --abort && | |
191 | git diff-files --exit-code --quiet | |
192 | ' | |
193 | ||
3e5057a8 | 194 | test_done |