am --skip: support skipping while on unborn branch
[git/mjg.git] / t / t4151-am-abort.sh
blob2a7c5247f9eb1083d615a8ff96fdaf904a3e8443
1 #!/bin/sh
3 test_description='am --abort'
5 . ./test-lib.sh
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 &&
17 for i in 2 3 4 5 6
19 echo $i >>file-1 &&
20 echo $i >otherfile-$i &&
21 git add otherfile-$i &&
22 test_tick &&
23 git commit -a -m $i || break
24 done &&
25 git format-patch --no-numbered initial &&
26 git checkout -b side initial &&
27 echo local change >file-2-expect
30 for with3 in '' ' -3'
32 test_expect_success "am$with3 stops at a patch that does not apply" '
34 git reset --hard initial &&
35 cp file-2-expect file-2 &&
37 test_must_fail git am$with3 000[1245]-*.patch &&
38 git log --pretty=tformat:%s >actual &&
39 for i in 3 2 initial
41 echo $i
42 done >expect &&
43 test_cmp expect actual
46 test_expect_success "am$with3 --skip continue after failed am$with3" '
47 test_must_fail git am$with3 --skip >output &&
48 test_i18ngrep "^Applying" output >output.applying &&
49 test_i18ngrep "^Applying: 6$" output.applying &&
50 test_i18ncmp file-2-expect file-2 &&
51 test ! -f .git/MERGE_RR
54 test_expect_success "am --abort goes back after failed am$with3" '
55 git am --abort &&
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 &&
61 test ! -f .git/MERGE_RR
64 done
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 &&
73 test -z $(git ls-files -u) &&
74 test_path_is_missing otherfile-4
77 test_expect_success 'am --abort will keep the local commits intact' '
78 test_must_fail git am 0004-*.patch &&
79 test_commit unrelated &&
80 git rev-parse HEAD >expect &&
81 git am --abort &&
82 git rev-parse HEAD >actual &&
83 test_cmp expect actual
86 test_expect_success 'am -3 stops on conflict on unborn branch' '
87 git checkout -f --orphan orphan &&
88 git reset &&
89 rm -f otherfile-4 &&
90 test_must_fail git am -3 0003-*.patch &&
91 test 2 -eq $(git ls-files -u | wc -l) &&
92 test 4 = "$(cat otherfile-4)"
95 test_expect_success 'am -3 --skip clears index on unborn branch' '
96 test_path_is_dir .git/rebase-apply &&
97 echo tmpfile >tmpfile &&
98 git add tmpfile &&
99 git am --skip &&
100 test -z "$(git ls-files)" &&
101 test_path_is_missing otherfile-4 &&
102 test_path_is_missing tmpfile
105 test_done