]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4151-am-abort.sh
am --abort: support aborting to unborn branch
[thirdparty/git.git] / t / t4151-am-abort.sh
CommitLineData
3e5057a8
NS
1#!/bin/sh
2
3test_description='am --abort'
4
5. ./test-lib.sh
6
7test_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
NS
23 test_tick &&
24 git commit -a -m $i || break
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
31for with3 in '' ' -3'
32do
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 &&
dff1a983
ÆAB
49 test_i18ngrep "^Applying" output >output.applying &&
50 test_i18ngrep "^Applying: 6$" output.applying &&
51 test_i18ncmp file-2-expect file-2 &&
3ca399d4 52 test ! -f .git/MERGE_RR
95f8ebbf
OM
53 '
54
3e5057a8 55 test_expect_success "am --abort goes back after failed am$with3" '
3604e7c5 56 git am --abort &&
3e5057a8
NS
57 git rev-parse HEAD >actual &&
58 git rev-parse initial >expect &&
59 test_cmp expect actual &&
60 test_cmp file-2-expect file-2 &&
61 git diff-index --exit-code --cached HEAD &&
3ca399d4 62 test ! -f .git/MERGE_RR
3e5057a8
NS
63 '
64
65done
66
88d50724
PT
67test_expect_success 'am -3 --skip removes otherfile-4' '
68 git reset --hard initial &&
69 test_must_fail git am -3 0003-*.patch &&
70 test 3 -eq $(git ls-files -u | wc -l) &&
71 test 4 = "$(cat otherfile-4)" &&
72 git am --skip &&
73 test_cmp_rev initial HEAD &&
20c3fe76
PT
74 test -z "$(git ls-files -u)" &&
75 test_path_is_missing otherfile-4
76'
77
78test_expect_success 'am -3 --abort removes otherfile-4' '
79 git reset --hard initial &&
80 test_must_fail git am -3 0003-*.patch &&
81 test 3 -eq $(git ls-files -u | wc -l) &&
82 test 4 = "$(cat otherfile-4)" &&
83 git am --abort &&
84 test_cmp_rev initial HEAD &&
88d50724
PT
85 test -z $(git ls-files -u) &&
86 test_path_is_missing otherfile-4
87'
88
7b3b7e37
JH
89test_expect_success 'am --abort will keep the local commits intact' '
90 test_must_fail git am 0004-*.patch &&
91 test_commit unrelated &&
92 git rev-parse HEAD >expect &&
93 git am --abort &&
94 git rev-parse HEAD >actual &&
95 test_cmp expect actual
96'
97
2c970c9e
PT
98test_expect_success 'am -3 stops on conflict on unborn branch' '
99 git checkout -f --orphan orphan &&
100 git reset &&
101 rm -f otherfile-4 &&
102 test_must_fail git am -3 0003-*.patch &&
103 test 2 -eq $(git ls-files -u | wc -l) &&
104 test 4 = "$(cat otherfile-4)"
105'
106
f8da6801
PT
107test_expect_success 'am -3 --skip clears index on unborn branch' '
108 test_path_is_dir .git/rebase-apply &&
109 echo tmpfile >tmpfile &&
110 git add tmpfile &&
111 git am --skip &&
112 test -z "$(git ls-files)" &&
113 test_path_is_missing otherfile-4 &&
114 test_path_is_missing tmpfile
115'
116
20c3fe76
PT
117test_expect_success 'am -3 --abort removes otherfile-4 on unborn branch' '
118 git checkout -f --orphan orphan &&
119 git reset &&
120 rm -f otherfile-4 file-1 &&
121 test_must_fail git am -3 0003-*.patch &&
122 test 2 -eq $(git ls-files -u | wc -l) &&
123 test 4 = "$(cat otherfile-4)" &&
124 git am --abort &&
125 test -z "$(git ls-files -u)" &&
126 test_path_is_missing otherfile-4
127'
128
e06764c8
PT
129test_expect_success 'am -3 --abort on unborn branch removes applied commits' '
130 git checkout -f --orphan orphan &&
131 git reset &&
132 rm -f otherfile-4 otherfile-2 file-1 file-2 &&
133 test_must_fail git am -3 initial.patch 0003-*.patch &&
134 test 3 -eq $(git ls-files -u | wc -l) &&
135 test 4 = "$(cat otherfile-4)" &&
136 git am --abort &&
137 test -z "$(git ls-files -u)" &&
138 test_path_is_missing otherfile-4 &&
139 test_path_is_missing file-1 &&
140 test_path_is_missing file-2 &&
141 test 0 -eq $(git log --oneline 2>/dev/null | wc -l) &&
142 test refs/heads/orphan = "$(git symbolic-ref HEAD)"
143'
144
3e5057a8 145test_done