@@ -14,6 +14,7 @@ test_expect_success setup '
14
14
git add file-1 file-2 &&
15
15
git commit -m initial &&
16
16
git tag initial &&
17
+ git format-patch --stdout --root initial >initial.patch &&
17
18
for i in 2 3 4 5 6
18
19
do
19
20
echo $i >>file-1 &&
63
64
64
65
done
65
66
67
+ test_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 &&
74
+ test -z "$(git ls-files -u)" &&
75
+ test_path_is_missing otherfile-4
76
+ '
77
+
78
+ test_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 &&
85
+ test -z $(git ls-files -u) &&
86
+ test_path_is_missing otherfile-4
87
+ '
88
+
66
89
test_expect_success ' am --abort will keep the local commits intact' '
67
90
test_must_fail git am 0004-*.patch &&
68
91
test_commit unrelated &&
@@ -72,4 +95,62 @@ test_expect_success 'am --abort will keep the local commits intact' '
72
95
test_cmp expect actual
73
96
'
74
97
98
+ test_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
+
107
+ test_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
+
117
+ test_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
+
129
+ test_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
+
145
+ test_expect_success ' am --abort on unborn branch will keep local commits intact' '
146
+ git checkout -f --orphan orphan &&
147
+ git reset &&
148
+ test_must_fail git am 0004-*.patch &&
149
+ test_commit unrelated2 &&
150
+ git rev-parse HEAD >expect &&
151
+ git am --abort &&
152
+ git rev-parse HEAD >actual &&
153
+ test_cmp expect actual
154
+ '
155
+
75
156
test_done
0 commit comments