Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='am --abort' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success setup ' |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 8 | test_write_lines a b c d e f g >file-1 && |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 9 | cp file-1 file-2 && |
| 10 | test_tick && |
| 11 | git add file-1 file-2 && |
| 12 | git commit -m initial && |
| 13 | git tag initial && |
Paul Tan | e06764c | 2015-06-06 19:46:11 +0800 | [diff] [blame] | 14 | git format-patch --stdout --root initial >initial.patch && |
Olivier Marin | 95f8ebb | 2008-07-21 15:39:06 +0200 | [diff] [blame] | 15 | for i in 2 3 4 5 6 |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 16 | do |
| 17 | echo $i >>file-1 && |
Olivier Marin | 9944d1a | 2008-07-24 14:44:40 +0200 | [diff] [blame] | 18 | echo $i >otherfile-$i && |
| 19 | git add otherfile-$i && |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 20 | test_tick && |
Jeff King | e6821d0 | 2015-03-25 01:29:52 -0400 | [diff] [blame] | 21 | git commit -a -m $i || return 1 |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 22 | done && |
Elijah Newren | 42b5e09 | 2021-09-10 10:31:15 +0000 | [diff] [blame] | 23 | git branch changes && |
Brian Gernhardt | a567fdc | 2008-10-02 16:55:39 -0400 | [diff] [blame] | 24 | git format-patch --no-numbered initial && |
Elijah Newren | 42b5e09 | 2021-09-10 10:31:15 +0000 | [diff] [blame] | 25 | git checkout -b conflicting initial && |
| 26 | echo different >>file-1 && |
| 27 | echo whatever >new-file && |
| 28 | git add file-1 new-file && |
| 29 | git commit -m different && |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 30 | git checkout -b side initial && |
| 31 | echo local change >file-2-expect |
| 32 | ' |
| 33 | |
| 34 | for with3 in '' ' -3' |
| 35 | do |
| 36 | test_expect_success "am$with3 stops at a patch that does not apply" ' |
| 37 | |
| 38 | git reset --hard initial && |
| 39 | cp file-2-expect file-2 && |
| 40 | |
Olivier Marin | 95f8ebb | 2008-07-21 15:39:06 +0200 | [diff] [blame] | 41 | test_must_fail git am$with3 000[1245]-*.patch && |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 42 | git log --pretty=tformat:%s >actual && |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 43 | test_write_lines 3 2 initial >expect && |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 44 | test_cmp expect actual |
| 45 | ' |
| 46 | |
Olivier Marin | 95f8ebb | 2008-07-21 15:39:06 +0200 | [diff] [blame] | 47 | test_expect_success "am$with3 --skip continue after failed am$with3" ' |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 48 | test_must_fail git am$with3 --skip >output && |
Ramsay Jones | dee8b71 | 2018-02-12 00:17:20 +0000 | [diff] [blame] | 49 | test_i18ngrep "^Applying: 6$" output && |
| 50 | test_cmp file-2-expect file-2 && |
Jay Soffian | 3ca399d | 2010-07-14 13:18:11 -0400 | [diff] [blame] | 51 | test ! -f .git/MERGE_RR |
Olivier Marin | 95f8ebb | 2008-07-21 15:39:06 +0200 | [diff] [blame] | 52 | ' |
| 53 | |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 54 | test_expect_success "am --abort goes back after failed am$with3" ' |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 55 | git am --abort && |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 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 && |
Jay Soffian | 3ca399d | 2010-07-14 13:18:11 -0400 | [diff] [blame] | 61 | test ! -f .git/MERGE_RR |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 62 | ' |
| 63 | |
| 64 | done |
| 65 | |
Paul Tan | 88d5072 | 2015-06-06 19:46:07 +0800 | [diff] [blame] | 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 && |
Paul Tan | 20c3fe7 | 2015-06-06 19:46:10 +0800 | [diff] [blame] | 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 && |
Armin Kunaschik | 2bb0518 | 2016-05-09 11:57:25 -0700 | [diff] [blame] | 84 | test -z "$(git ls-files -u)" && |
Paul Tan | 88d5072 | 2015-06-06 19:46:07 +0800 | [diff] [blame] | 85 | test_path_is_missing otherfile-4 |
| 86 | ' |
| 87 | |
Junio C Hamano | 7b3b7e3 | 2010-12-21 10:35:53 -0800 | [diff] [blame] | 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 | |
Paul Tan | 528484c | 2015-07-19 23:49:09 +0800 | [diff] [blame] | 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 | |
Paul Tan | 2c970c9 | 2015-06-06 19:46:08 +0800 | [diff] [blame] | 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 | |
Paul Tan | f8da680 | 2015-06-06 19:46:09 +0800 | [diff] [blame] | 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 | |
Paul Tan | 20c3fe7 | 2015-06-06 19:46:10 +0800 | [diff] [blame] | 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 | |
Paul Tan | e06764c | 2015-06-06 19:46:11 +0800 | [diff] [blame] | 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 | |
Paul Tan | 6ea3b67 | 2015-06-06 19:46:12 +0800 | [diff] [blame] | 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 | |
Paul Tan | 3ecc704 | 2015-08-19 16:22:22 +0800 | [diff] [blame] | 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 && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 174 | test-tool chmtime =0 skip-should-be-untouched.t && |
Paul Tan | 3ecc704 | 2015-08-19 16:22:22 +0800 | [diff] [blame] | 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 && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 186 | test-tool chmtime =0 abort-should-be-untouched.t && |
Paul Tan | 3ecc704 | 2015-08-19 16:22:22 +0800 | [diff] [blame] | 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 | |
Elijah Newren | c5ead19 | 2021-09-10 10:31:16 +0000 | [diff] [blame] | 194 | test_expect_success 'git am --abort return failed exit status when it fails' ' |
Elijah Newren | 42b5e09 | 2021-09-10 10:31:15 +0000 | [diff] [blame] | 195 | test_when_finished "rm -rf file-2/ && git reset --hard && git am --abort" && |
| 196 | git checkout changes && |
| 197 | git format-patch -1 --stdout conflicting >changes.mbox && |
| 198 | test_must_fail git am --3way changes.mbox && |
| 199 | |
| 200 | git rm file-2 && |
| 201 | mkdir file-2 && |
| 202 | echo precious >file-2/somefile && |
| 203 | test_must_fail git am --abort && |
| 204 | test_path_is_dir file-2/ |
| 205 | ' |
| 206 | |
| 207 | test_expect_success 'git am --abort cleans relevant files' ' |
| 208 | git checkout changes && |
| 209 | git format-patch -1 --stdout conflicting >changes.mbox && |
| 210 | test_must_fail git am --3way changes.mbox && |
| 211 | |
| 212 | test_path_is_file new-file && |
| 213 | echo further changes >>file-1 && |
| 214 | echo change other file >>file-2 && |
| 215 | |
| 216 | # Abort, and expect the files touched by am to be reverted |
| 217 | git am --abort && |
| 218 | |
| 219 | test_path_is_missing new-file && |
| 220 | |
| 221 | # Files not involved in am operation are left modified |
| 222 | git diff --name-only changes >actual && |
| 223 | test_write_lines file-2 >expect && |
| 224 | test_cmp expect actual |
| 225 | ' |
| 226 | |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 227 | test_done |