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 ' |
| 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 && |
Paul Tan | e06764c | 2015-06-06 19:46:11 +0800 | [diff] [blame] | 17 | git format-patch --stdout --root initial >initial.patch && |
Olivier Marin | 95f8ebb | 2008-07-21 15:39:06 +0200 | [diff] [blame] | 18 | for i in 2 3 4 5 6 |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 19 | do |
| 20 | echo $i >>file-1 && |
Olivier Marin | 9944d1a | 2008-07-24 14:44:40 +0200 | [diff] [blame] | 21 | echo $i >otherfile-$i && |
| 22 | git add otherfile-$i && |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 23 | test_tick && |
Jeff King | e6821d0 | 2015-03-25 01:29:52 -0400 | [diff] [blame] | 24 | git commit -a -m $i || return 1 |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 25 | done && |
Brian Gernhardt | a567fdc | 2008-10-02 16:55:39 -0400 | [diff] [blame] | 26 | git format-patch --no-numbered initial && |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 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 | |
Olivier Marin | 95f8ebb | 2008-07-21 15:39:06 +0200 | [diff] [blame] | 38 | test_must_fail git am$with3 000[1245]-*.patch && |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 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 | |
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 && |
Ævar Arnfjörð Bjarmason | dff1a98 | 2011-05-21 18:43:52 +0000 | [diff] [blame] | 49 | test_i18ngrep "^Applying" output >output.applying && |
| 50 | test_i18ngrep "^Applying: 6$" output.applying && |
| 51 | test_i18ncmp file-2-expect file-2 && |
Jay Soffian | 3ca399d | 2010-07-14 13:18:11 -0400 | [diff] [blame] | 52 | test ! -f .git/MERGE_RR |
Olivier Marin | 95f8ebb | 2008-07-21 15:39:06 +0200 | [diff] [blame] | 53 | ' |
| 54 | |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 55 | test_expect_success "am --abort goes back after failed am$with3" ' |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 56 | git am --abort && |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 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 && |
Jay Soffian | 3ca399d | 2010-07-14 13:18:11 -0400 | [diff] [blame] | 62 | test ! -f .git/MERGE_RR |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 63 | ' |
| 64 | |
| 65 | done |
| 66 | |
Paul Tan | 88d5072 | 2015-06-06 19:46:07 +0800 | [diff] [blame] | 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 && |
Paul Tan | 20c3fe7 | 2015-06-06 19:46:10 +0800 | [diff] [blame] | 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 && |
Armin Kunaschik | 2bb0518 | 2016-05-09 11:57:25 -0700 | [diff] [blame] | 85 | test -z "$(git ls-files -u)" && |
Paul Tan | 88d5072 | 2015-06-06 19:46:07 +0800 | [diff] [blame] | 86 | test_path_is_missing otherfile-4 |
| 87 | ' |
| 88 | |
Junio C Hamano | 7b3b7e3 | 2010-12-21 10:35:53 -0800 | [diff] [blame] | 89 | test_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 | |
Paul Tan | 528484c | 2015-07-19 23:49:09 +0800 | [diff] [blame] | 98 | test_expect_success 'am --abort will keep dirty index intact' ' |
| 99 | git reset --hard initial && |
| 100 | echo dirtyfile >dirtyfile && |
| 101 | cp dirtyfile dirtyfile.expected && |
| 102 | git add dirtyfile && |
| 103 | test_must_fail git am 0001-*.patch && |
| 104 | test_cmp_rev initial HEAD && |
| 105 | test_path_is_file dirtyfile && |
| 106 | test_cmp dirtyfile.expected dirtyfile && |
| 107 | git am --abort && |
| 108 | test_cmp_rev initial HEAD && |
| 109 | test_path_is_file dirtyfile && |
| 110 | test_cmp dirtyfile.expected dirtyfile |
| 111 | ' |
| 112 | |
Paul Tan | 2c970c9 | 2015-06-06 19:46:08 +0800 | [diff] [blame] | 113 | test_expect_success 'am -3 stops on conflict on unborn branch' ' |
| 114 | git checkout -f --orphan orphan && |
| 115 | git reset && |
| 116 | rm -f otherfile-4 && |
| 117 | test_must_fail git am -3 0003-*.patch && |
| 118 | test 2 -eq $(git ls-files -u | wc -l) && |
| 119 | test 4 = "$(cat otherfile-4)" |
| 120 | ' |
| 121 | |
Paul Tan | f8da680 | 2015-06-06 19:46:09 +0800 | [diff] [blame] | 122 | test_expect_success 'am -3 --skip clears index on unborn branch' ' |
| 123 | test_path_is_dir .git/rebase-apply && |
| 124 | echo tmpfile >tmpfile && |
| 125 | git add tmpfile && |
| 126 | git am --skip && |
| 127 | test -z "$(git ls-files)" && |
| 128 | test_path_is_missing otherfile-4 && |
| 129 | test_path_is_missing tmpfile |
| 130 | ' |
| 131 | |
Paul Tan | 20c3fe7 | 2015-06-06 19:46:10 +0800 | [diff] [blame] | 132 | test_expect_success 'am -3 --abort removes otherfile-4 on unborn branch' ' |
| 133 | git checkout -f --orphan orphan && |
| 134 | git reset && |
| 135 | rm -f otherfile-4 file-1 && |
| 136 | test_must_fail git am -3 0003-*.patch && |
| 137 | test 2 -eq $(git ls-files -u | wc -l) && |
| 138 | test 4 = "$(cat otherfile-4)" && |
| 139 | git am --abort && |
| 140 | test -z "$(git ls-files -u)" && |
| 141 | test_path_is_missing otherfile-4 |
| 142 | ' |
| 143 | |
Paul Tan | e06764c | 2015-06-06 19:46:11 +0800 | [diff] [blame] | 144 | test_expect_success 'am -3 --abort on unborn branch removes applied commits' ' |
| 145 | git checkout -f --orphan orphan && |
| 146 | git reset && |
| 147 | rm -f otherfile-4 otherfile-2 file-1 file-2 && |
| 148 | test_must_fail git am -3 initial.patch 0003-*.patch && |
| 149 | test 3 -eq $(git ls-files -u | wc -l) && |
| 150 | test 4 = "$(cat otherfile-4)" && |
| 151 | git am --abort && |
| 152 | test -z "$(git ls-files -u)" && |
| 153 | test_path_is_missing otherfile-4 && |
| 154 | test_path_is_missing file-1 && |
| 155 | test_path_is_missing file-2 && |
| 156 | test 0 -eq $(git log --oneline 2>/dev/null | wc -l) && |
| 157 | test refs/heads/orphan = "$(git symbolic-ref HEAD)" |
| 158 | ' |
| 159 | |
Paul Tan | 6ea3b67 | 2015-06-06 19:46:12 +0800 | [diff] [blame] | 160 | test_expect_success 'am --abort on unborn branch will keep local commits intact' ' |
| 161 | git checkout -f --orphan orphan && |
| 162 | git reset && |
| 163 | test_must_fail git am 0004-*.patch && |
| 164 | test_commit unrelated2 && |
| 165 | git rev-parse HEAD >expect && |
| 166 | git am --abort && |
| 167 | git rev-parse HEAD >actual && |
| 168 | test_cmp expect actual |
| 169 | ' |
| 170 | |
Paul Tan | 3ecc704 | 2015-08-19 16:22:22 +0800 | [diff] [blame] | 171 | test_expect_success 'am --skip leaves index stat info alone' ' |
| 172 | git checkout -f --orphan skip-stat-info && |
| 173 | git reset && |
| 174 | test_commit skip-should-be-untouched && |
| 175 | test-chmtime =0 skip-should-be-untouched.t && |
| 176 | git update-index --refresh && |
| 177 | git diff-files --exit-code --quiet && |
| 178 | test_must_fail git am 0001-*.patch && |
| 179 | git am --skip && |
| 180 | git diff-files --exit-code --quiet |
| 181 | ' |
| 182 | |
| 183 | test_expect_success 'am --abort leaves index stat info alone' ' |
| 184 | git checkout -f --orphan abort-stat-info && |
| 185 | git reset && |
| 186 | test_commit abort-should-be-untouched && |
| 187 | test-chmtime =0 abort-should-be-untouched.t && |
| 188 | git update-index --refresh && |
| 189 | git diff-files --exit-code --quiet && |
| 190 | test_must_fail git am 0001-*.patch && |
| 191 | git am --abort && |
| 192 | git diff-files --exit-code --quiet |
| 193 | ' |
| 194 | |
Nanako Shiraishi | 3e5057a | 2008-07-16 19:39:10 +0900 | [diff] [blame] | 195 | test_done |