Git fork

Merge branch 'jn/rebase-rename-am' into maint

* jn/rebase-rename-am:
rebase: protect against diff.renames configuration
t3400 (rebase): whitespace cleanup
Teach "apply --index-info" to handle rename patches
t4150 (am): futureproof against failing tests
t4150 (am): style fix

+333 -190
+1 -2
builtin/apply.c
··· 2979 2979 else if (get_sha1(patch->old_sha1_prefix, sha1)) 2980 2980 /* git diff has no index line for mode/type changes */ 2981 2981 if (!patch->lines_added && !patch->lines_deleted) { 2982 - if (get_current_sha1(patch->new_name, sha1) || 2983 - get_current_sha1(patch->old_name, sha1)) 2982 + if (get_current_sha1(patch->old_name, sha1)) 2984 2983 die("mode change for %s, which is not " 2985 2984 "in current HEAD", name); 2986 2985 sha1_ptr = sha1;
+1 -1
git-rebase.sh
··· 544 544 if test -z "$do_merge" 545 545 then 546 546 git format-patch -k --stdout --full-index --ignore-if-in-upstream \ 547 - $root_flag "$revisions" | 547 + --no-renames $root_flag "$revisions" | 548 548 git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" && 549 549 move_to_original_branch 550 550 ret=$?
+114 -90
t/t3400-rebase.sh
··· 14 14 GIT_AUTHOR_EMAIL=bogus@email@address 15 15 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL 16 16 17 - test_expect_success \ 18 - 'prepare repository with topic branches' \ 19 - 'git config core.logAllRefUpdates true && 20 - echo First > A && 21 - git update-index --add A && 22 - git commit -m "Add A." && 23 - git checkout -b my-topic-branch && 24 - echo Second > B && 25 - git update-index --add B && 26 - git commit -m "Add B." && 27 - git checkout -f master && 28 - echo Third >> A && 29 - git update-index A && 30 - git commit -m "Modify A." && 31 - git checkout -b side my-topic-branch && 32 - echo Side >> C && 33 - git add C && 34 - git commit -m "Add C" && 35 - git checkout -b nonlinear my-topic-branch && 36 - echo Edit >> B && 37 - git add B && 38 - git commit -m "Modify B" && 39 - git merge side && 40 - git checkout -b upstream-merged-nonlinear && 41 - git merge master && 42 - git checkout -f my-topic-branch && 43 - git tag topic 17 + test_expect_success 'prepare repository with topic branches' ' 18 + git config core.logAllRefUpdates true && 19 + echo First >A && 20 + git update-index --add A && 21 + git commit -m "Add A." && 22 + git checkout -b force-3way && 23 + echo Dummy >Y && 24 + git update-index --add Y && 25 + git commit -m "Add Y." && 26 + git checkout -b filemove && 27 + git reset --soft master && 28 + mkdir D && 29 + git mv A D/A && 30 + git commit -m "Move A." && 31 + git checkout -b my-topic-branch master && 32 + echo Second >B && 33 + git update-index --add B && 34 + git commit -m "Add B." && 35 + git checkout -f master && 36 + echo Third >>A && 37 + git update-index A && 38 + git commit -m "Modify A." && 39 + git checkout -b side my-topic-branch && 40 + echo Side >>C && 41 + git add C && 42 + git commit -m "Add C" && 43 + git checkout -b nonlinear my-topic-branch && 44 + echo Edit >>B && 45 + git add B && 46 + git commit -m "Modify B" && 47 + git merge side && 48 + git checkout -b upstream-merged-nonlinear && 49 + git merge master && 50 + git checkout -f my-topic-branch && 51 + git tag topic 44 52 ' 45 53 46 54 test_expect_success 'rebase on dirty worktree' ' 47 - echo dirty >> A && 48 - test_must_fail git rebase master' 55 + echo dirty >>A && 56 + test_must_fail git rebase master 57 + ' 49 58 50 59 test_expect_success 'rebase on dirty cache' ' 51 - git add A && 52 - test_must_fail git rebase master' 60 + git add A && 61 + test_must_fail git rebase master 62 + ' 53 63 54 64 test_expect_success 'rebase against master' ' 55 - git reset --hard HEAD && 56 - git rebase master' 65 + git reset --hard HEAD && 66 + git rebase master 67 + ' 57 68 58 69 test_expect_success 'rebase against master twice' ' 59 - git rebase master >out && 60 - grep "Current branch my-topic-branch is up to date" out 70 + git rebase master >out && 71 + grep "Current branch my-topic-branch is up to date" out 61 72 ' 62 73 63 74 test_expect_success 'rebase against master twice with --force' ' 64 - git rebase --force-rebase master >out && 65 - grep "Current branch my-topic-branch is up to date, rebase forced" out 75 + git rebase --force-rebase master >out && 76 + grep "Current branch my-topic-branch is up to date, rebase forced" out 66 77 ' 67 78 68 79 test_expect_success 'rebase against master twice from another branch' ' 69 - git checkout my-topic-branch^ && 70 - git rebase master my-topic-branch >out && 71 - grep "Current branch my-topic-branch is up to date" out 80 + git checkout my-topic-branch^ && 81 + git rebase master my-topic-branch >out && 82 + grep "Current branch my-topic-branch is up to date" out 72 83 ' 73 84 74 85 test_expect_success 'rebase fast-forward to master' ' 75 - git checkout my-topic-branch^ && 76 - git rebase my-topic-branch >out && 77 - grep "Fast-forwarded HEAD to my-topic-branch" out 86 + git checkout my-topic-branch^ && 87 + git rebase my-topic-branch >out && 88 + grep "Fast-forwarded HEAD to my-topic-branch" out 78 89 ' 79 90 80 - test_expect_success \ 81 - 'the rebase operation should not have destroyed author information' \ 82 - '! (git log | grep "Author:" | grep "<>")' 91 + test_expect_success 'the rebase operation should not have destroyed author information' ' 92 + ! (git log | grep "Author:" | grep "<>") 93 + ' 83 94 84 - test_expect_success \ 85 - 'the rebase operation should not have destroyed author information (2)' \ 86 - "git log -1 | grep 'Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>'" 95 + test_expect_success 'the rebase operation should not have destroyed author information (2)' " 96 + git log -1 | 97 + grep 'Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>' 98 + " 87 99 88 100 test_expect_success 'HEAD was detached during rebase' ' 89 - test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1}) 101 + test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1}) 90 102 ' 91 103 92 104 test_expect_success 'rebase after merge master' ' 93 - git reset --hard topic && 94 - git merge master && 95 - git rebase master && 96 - ! (git show | grep "^Merge:") 105 + git reset --hard topic && 106 + git merge master && 107 + git rebase master && 108 + ! (git show | grep "^Merge:") 97 109 ' 98 110 99 111 test_expect_success 'rebase of history with merges is linearized' ' 100 - git checkout nonlinear && 101 - test 4 = $(git rev-list master.. | wc -l) && 102 - git rebase master && 103 - test 3 = $(git rev-list master.. | wc -l) 112 + git checkout nonlinear && 113 + test 4 = $(git rev-list master.. | wc -l) && 114 + git rebase master && 115 + test 3 = $(git rev-list master.. | wc -l) 104 116 ' 105 117 106 - test_expect_success \ 107 - 'rebase of history with merges after upstream merge is linearized' ' 108 - git checkout upstream-merged-nonlinear && 109 - test 5 = $(git rev-list master.. | wc -l) && 110 - git rebase master && 111 - test 3 = $(git rev-list master.. | wc -l) 118 + test_expect_success 'rebase of history with merges after upstream merge is linearized' ' 119 + git checkout upstream-merged-nonlinear && 120 + test 5 = $(git rev-list master.. | wc -l) && 121 + git rebase master && 122 + test 3 = $(git rev-list master.. | wc -l) 112 123 ' 113 124 114 125 test_expect_success 'rebase a single mode change' ' 115 - git checkout master && 116 - echo 1 > X && 117 - git add X && 118 - test_tick && 119 - git commit -m prepare && 120 - git checkout -b modechange HEAD^ && 121 - echo 1 > X && 122 - git add X && 123 - test_chmod +x A && 124 - test_tick && 125 - git commit -m modechange && 126 - GIT_TRACE=1 git rebase master 126 + git checkout master && 127 + echo 1 >X && 128 + git add X && 129 + test_tick && 130 + git commit -m prepare && 131 + git checkout -b modechange HEAD^ && 132 + echo 1 >X && 133 + git add X && 134 + test_chmod +x A && 135 + test_tick && 136 + git commit -m modechange && 137 + GIT_TRACE=1 git rebase master 138 + ' 139 + 140 + test_expect_success 'rebase is not broken by diff.renames' ' 141 + git config diff.renames copies && 142 + test_when_finished "git config --unset diff.renames" && 143 + git checkout filemove && 144 + GIT_TRACE=1 git rebase force-3way 145 + ' 146 + 147 + test_expect_success 'setup: recover' ' 148 + test_might_fail git rebase --abort && 149 + git reset --hard && 150 + git checkout modechange 127 151 ' 128 152 129 153 test_expect_success 'Show verbose error when HEAD could not be detached' ' 130 - : > B && 131 - test_must_fail git rebase topic 2> output.err > output.out && 132 - grep "Untracked working tree file .B. would be overwritten" output.err 154 + >B && 155 + test_must_fail git rebase topic 2>output.err >output.out && 156 + grep "Untracked working tree file .B. would be overwritten" output.err 133 157 ' 134 158 rm -f B 135 159 136 160 test_expect_success 'dump usage when upstream arg is missing' ' 137 - git checkout -b usage topic && 138 - test_must_fail git rebase 2>error1 && 139 - grep "[Uu]sage" error1 && 140 - test_must_fail git rebase --abort 2>error2 && 141 - grep "No rebase in progress" error2 && 142 - test_must_fail git rebase --onto master 2>error3 && 143 - grep "[Uu]sage" error3 && 144 - ! grep "can.t shift" error3 161 + git checkout -b usage topic && 162 + test_must_fail git rebase 2>error1 && 163 + grep "[Uu]sage" error1 && 164 + test_must_fail git rebase --abort 2>error2 && 165 + grep "No rebase in progress" error2 && 166 + test_must_fail git rebase --onto master 2>error3 && 167 + grep "[Uu]sage" error3 && 168 + ! grep "can.t shift" error3 145 169 ' 146 170 147 171 test_expect_success 'rebase -q is quiet' ' 148 - git checkout -b quiet topic && 149 - git rebase -q master > output.out 2>&1 && 150 - test ! -s output.out 172 + git checkout -b quiet topic && 173 + git rebase -q master >output.out 2>&1 && 174 + test ! -s output.out 151 175 ' 152 176 153 177 test_expect_success 'Rebase a commit that sprinkles CRs in' '
+213 -97
t/t4150-am.sh
··· 4 4 5 5 . ./test-lib.sh 6 6 7 - cat >msg <<EOF 8 - second 7 + test_expect_success 'setup: messages' ' 8 + cat >msg <<-\EOF && 9 + second 9 10 10 - Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy 11 - eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam 12 - voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita 13 - kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem 14 - ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod 15 - tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At 16 - vero eos et accusam et justo duo dolores et ea rebum. 11 + Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy 12 + eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam 13 + voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita 14 + kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem 15 + ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod 16 + tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At 17 + vero eos et accusam et justo duo dolores et ea rebum. 17 18 18 - Duis autem vel eum iriure dolor in hendrerit in vulputate velit 19 - esse molestie consequat, vel illum dolore eu feugiat nulla facilisis 20 - at vero eros et accumsan et iusto odio dignissim qui blandit 21 - praesent luptatum zzril delenit augue duis dolore te feugait nulla 22 - facilisi. 19 + EOF 20 + q_to_tab <<-\EOF >>msg && 21 + QDuis autem vel eum iriure dolor in hendrerit in vulputate velit 22 + Qesse molestie consequat, vel illum dolore eu feugiat nulla facilisis 23 + Qat vero eros et accumsan et iusto odio dignissim qui blandit 24 + Qpraesent luptatum zzril delenit augue duis dolore te feugait nulla 25 + Qfacilisi. 26 + EOF 27 + cat >>msg <<-\EOF && 23 28 29 + Lorem ipsum dolor sit amet, 30 + consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut 31 + laoreet dolore magna aliquam erat volutpat. 24 32 25 - Lorem ipsum dolor sit amet, 26 - consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut 27 - laoreet dolore magna aliquam erat volutpat. 33 + git 34 + --- 35 + +++ 28 36 29 - git 30 - --- 31 - +++ 37 + Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit 38 + lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure 39 + dolor in hendrerit in vulputate velit esse molestie consequat, vel illum 40 + dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio 41 + dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te 42 + feugait nulla facilisi. 43 + EOF 32 44 33 - Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit 34 - lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure 35 - dolor in hendrerit in vulputate velit esse molestie consequat, vel illum 36 - dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio 37 - dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te 38 - feugait nulla facilisi. 39 - EOF 45 + cat >failmail <<-\EOF && 46 + From foo@example.com Fri May 23 10:43:49 2008 47 + From: foo@example.com 48 + To: bar@example.com 49 + Subject: Re: [RFC/PATCH] git-foo.sh 50 + Date: Fri, 23 May 2008 05:23:42 +0200 40 51 41 - cat >failmail <<EOF 42 - From foo@example.com Fri May 23 10:43:49 2008 43 - From: foo@example.com 44 - To: bar@example.com 45 - Subject: Re: [RFC/PATCH] git-foo.sh 46 - Date: Fri, 23 May 2008 05:23:42 +0200 52 + Sometimes we have to find out that there'\''s nothing left. 47 53 48 - Sometimes we have to find out that there's nothing left. 54 + EOF 49 55 50 - EOF 56 + cat >pine <<-\EOF && 57 + From MAILER-DAEMON Fri May 23 10:43:49 2008 58 + Date: 23 May 2008 05:23:42 +0200 59 + From: Mail System Internal Data <MAILER-DAEMON@example.com> 60 + Subject: DON'\''T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA 61 + Message-ID: <foo-0001@example.com> 51 62 52 - cat >pine <<EOF 53 - From MAILER-DAEMON Fri May 23 10:43:49 2008 54 - Date: 23 May 2008 05:23:42 +0200 55 - From: Mail System Internal Data <MAILER-DAEMON@example.com> 56 - Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA 57 - Message-ID: <foo-0001@example.com> 63 + This text is part of the internal format of your mail folder, and is not 64 + a real message. It is created automatically by the mail system software. 65 + If deleted, important folder data will be lost, and it will be re-created 66 + with the data reset to initial values. 58 67 59 - This text is part of the internal format of your mail folder, and is not 60 - a real message. It is created automatically by the mail system software. 61 - If deleted, important folder data will be lost, and it will be re-created 62 - with the data reset to initial values. 68 + EOF 63 69 64 - EOF 65 - 66 - echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected 70 + signoff="Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" 71 + ' 67 72 68 73 test_expect_success setup ' 69 74 echo hello >file && ··· 71 76 test_tick && 72 77 git commit -m first && 73 78 git tag first && 79 + 74 80 echo world >>file && 75 81 git add file && 76 82 test_tick && 77 83 git commit -s -F msg && 78 84 git tag second && 85 + 79 86 git format-patch --stdout first >patch1 && 80 87 { 81 88 echo "X-Fake-Field: Line One" && ··· 89 96 echo "X-Fake-Field: Line Three" && 90 97 git format-patch --stdout first | sed -e "1d" 91 98 } | append_cr >patch1-crlf.eml && 99 + 92 100 sed -n -e "3,\$p" msg >file && 93 101 git add file && 94 102 test_tick && 95 103 git commit -m third && 104 + 96 105 git format-patch --stdout first >patch2 && 106 + 97 107 git checkout -b lorem && 98 108 sed -n -e "11,\$p" msg >file && 99 109 head -n 9 msg >>file && 100 110 test_tick && 101 111 git commit -a -m "moved stuff" && 112 + 102 113 echo goodbye >another && 103 114 git add another && 104 115 test_tick && 105 116 git commit -m "added another file" && 106 - git format-patch --stdout master >lorem-move.patch 117 + 118 + git format-patch --stdout master >lorem-move.patch && 119 + 120 + git checkout -b rename && 121 + git mv file renamed && 122 + git commit -m "renamed a file" && 123 + 124 + git format-patch -M --stdout lorem >rename.patch && 125 + 126 + git reset --soft lorem^ && 127 + git commit -m "renamed a file and added another" && 128 + 129 + git format-patch -M --stdout lorem^ >rename-add.patch && 130 + 131 + # reset time 132 + unset test_tick && 133 + test_tick 107 134 ' 108 135 109 - # reset time 110 - unset test_tick 111 - test_tick 112 - 113 136 test_expect_success 'am applies patch correctly' ' 137 + rm -fr .git/rebase-apply && 138 + git reset --hard && 114 139 git checkout first && 115 140 test_tick && 116 141 git am <patch1 && 117 142 ! test -d .git/rebase-apply && 118 - test -z "$(git diff second)" && 143 + git diff --exit-code second && 119 144 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" && 120 145 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" 121 146 ' 122 147 123 148 test_expect_success 'am applies patch e-mail not in a mbox' ' 149 + rm -fr .git/rebase-apply && 150 + git reset --hard && 124 151 git checkout first && 125 152 git am patch1.eml && 126 153 ! test -d .git/rebase-apply && 127 - test -z "$(git diff second)" && 154 + git diff --exit-code second && 128 155 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" && 129 156 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" 130 157 ' 131 158 132 159 test_expect_success 'am applies patch e-mail not in a mbox with CRLF' ' 160 + rm -fr .git/rebase-apply && 161 + git reset --hard && 133 162 git checkout first && 134 163 git am patch1-crlf.eml && 135 164 ! test -d .git/rebase-apply && 136 - test -z "$(git diff second)" && 165 + git diff --exit-code second && 137 166 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" && 138 167 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" 139 168 ' 140 169 141 - GIT_AUTHOR_NAME="Another Thor" 142 - GIT_AUTHOR_EMAIL="a.thor@example.com" 143 - GIT_COMMITTER_NAME="Co M Miter" 144 - GIT_COMMITTER_EMAIL="c.miter@example.com" 145 - export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL 170 + test_expect_success 'setup: new author and committer' ' 171 + GIT_AUTHOR_NAME="Another Thor" && 172 + GIT_AUTHOR_EMAIL="a.thor@example.com" && 173 + GIT_COMMITTER_NAME="Co M Miter" && 174 + GIT_COMMITTER_EMAIL="c.miter@example.com" && 175 + export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL 176 + ' 146 177 147 178 compare () { 148 - test "$(git cat-file commit "$2" | grep "^$1 ")" = \ 149 - "$(git cat-file commit "$3" | grep "^$1 ")" 179 + a=$(git cat-file commit "$2" | grep "^$1 ") && 180 + b=$(git cat-file commit "$3" | grep "^$1 ") && 181 + test "$a" = "$b" 150 182 } 151 183 152 184 test_expect_success 'am changes committer and keeps author' ' 153 185 test_tick && 186 + rm -fr .git/rebase-apply && 187 + git reset --hard && 154 188 git checkout first && 155 189 git am patch2 && 156 190 ! test -d .git/rebase-apply && 157 191 test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" && 158 - test -z "$(git diff master..HEAD)" && 159 - test -z "$(git diff master^..HEAD^)" && 192 + git diff --exit-code master..HEAD && 193 + git diff --exit-code master^..HEAD^ && 160 194 compare author master HEAD && 161 195 compare author master^ HEAD^ && 162 196 test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \ ··· 164 198 ' 165 199 166 200 test_expect_success 'am --signoff adds Signed-off-by: line' ' 201 + rm -fr .git/rebase-apply && 202 + git reset --hard && 167 203 git checkout -b master2 first && 168 204 git am --signoff <patch2 && 205 + printf "%s\n" "$signoff" >expected && 169 206 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected && 170 207 git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && 171 - test_cmp actual expected && 208 + test_cmp expected actual && 172 209 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected && 173 210 git cat-file commit HEAD | grep "Signed-off-by:" >actual && 174 - test_cmp actual expected 211 + test_cmp expected actual 175 212 ' 176 213 177 214 test_expect_success 'am stays in branch' ' 178 - test "refs/heads/master2" = "$(git symbolic-ref HEAD)" 215 + echo refs/heads/master2 >expected && 216 + git symbolic-ref HEAD >actual && 217 + test_cmp expected actual 179 218 ' 180 219 181 220 test_expect_success 'am --signoff does not add Signed-off-by: line if already there' ' 182 221 git format-patch --stdout HEAD^ >patch3 && 183 222 sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4 223 + rm -fr .git/rebase-apply && 224 + git reset --hard && 184 225 git checkout HEAD^ && 185 226 git am --signoff patch4 && 186 - test "$(git cat-file commit HEAD | grep -c "^Signed-off-by:")" -eq 1 227 + git cat-file commit HEAD >actual && 228 + test $(grep -c "^Signed-off-by:" actual) -eq 1 187 229 ' 188 230 189 231 test_expect_success 'am without --keep removes Re: and [PATCH] stuff' ' 190 - test "$(git rev-parse HEAD)" = "$(git rev-parse master2)" 232 + git rev-parse HEAD >expected && 233 + git rev-parse master2 >actual && 234 + test_cmp expected actual 191 235 ' 192 236 193 237 test_expect_success 'am --keep really keeps the subject' ' 238 + rm -fr .git/rebase-apply && 239 + git reset --hard && 194 240 git checkout HEAD^ && 195 241 git am --keep patch4 && 196 242 ! test -d .git/rebase-apply && 197 - git cat-file commit HEAD | 198 - fgrep "Re: Re: Re: [PATCH 1/5 v2] third" 243 + git cat-file commit HEAD >actual && 244 + grep "Re: Re: Re: \[PATCH 1/5 v2\] third" actual 199 245 ' 200 246 201 247 test_expect_success 'am -3 falls back to 3-way merge' ' 248 + rm -fr .git/rebase-apply && 249 + git reset --hard && 202 250 git checkout -b lorem2 master2 && 203 251 sed -n -e "3,\$p" msg >file && 204 252 head -n 9 msg >>file && ··· 207 255 git commit -m "copied stuff" && 208 256 git am -3 lorem-move.patch && 209 257 ! test -d .git/rebase-apply && 210 - test -z "$(git diff lorem)" 258 + git diff --exit-code lorem 259 + ' 260 + 261 + test_expect_success 'am can rename a file' ' 262 + grep "^rename from" rename.patch && 263 + rm -fr .git/rebase-apply && 264 + git reset --hard && 265 + git checkout lorem^0 && 266 + git am rename.patch && 267 + ! test -d .git/rebase-apply && 268 + git update-index --refresh && 269 + git diff --exit-code rename 270 + ' 271 + 272 + test_expect_success 'am -3 can rename a file' ' 273 + grep "^rename from" rename.patch && 274 + rm -fr .git/rebase-apply && 275 + git reset --hard && 276 + git checkout lorem^0 && 277 + git am -3 rename.patch && 278 + ! test -d .git/rebase-apply && 279 + git update-index --refresh && 280 + git diff --exit-code rename 281 + ' 282 + 283 + test_expect_success 'am -3 can rename a file after falling back to 3-way merge' ' 284 + grep "^rename from" rename-add.patch && 285 + rm -fr .git/rebase-apply && 286 + git reset --hard && 287 + git checkout lorem^0 && 288 + git am -3 rename-add.patch && 289 + ! test -d .git/rebase-apply && 290 + git update-index --refresh && 291 + git diff --exit-code rename 211 292 ' 212 293 213 294 test_expect_success 'am -3 -q is quiet' ' 295 + rm -fr .git/rebase-apply && 296 + git checkout -f lorem2 && 214 297 git reset master2 --hard && 215 298 sed -n -e "3,\$p" msg >file && 216 299 head -n 9 msg >>file && 217 300 git add file && 218 301 test_tick && 219 302 git commit -m "copied stuff" && 220 - git am -3 -q lorem-move.patch > output.out 2>&1 && 303 + git am -3 -q lorem-move.patch >output.out 2>&1 && 221 304 ! test -s output.out 222 305 ' 223 306 224 307 test_expect_success 'am pauses on conflict' ' 308 + rm -fr .git/rebase-apply && 309 + git reset --hard && 225 310 git checkout lorem2^^ && 226 311 test_must_fail git am lorem-move.patch && 227 312 test -d .git/rebase-apply 228 313 ' 229 314 230 315 test_expect_success 'am --skip works' ' 316 + echo goodbye >expected && 231 317 git am --skip && 232 318 ! test -d .git/rebase-apply && 233 - test -z "$(git diff lorem2^^ -- file)" && 234 - test goodbye = "$(cat another)" 319 + git diff --exit-code lorem2^^ -- file && 320 + test_cmp expected another 235 321 ' 236 322 237 323 test_expect_success 'am --resolved works' ' 324 + echo goodbye >expected && 325 + rm -fr .git/rebase-apply && 326 + git reset --hard && 238 327 git checkout lorem2^^ && 239 328 test_must_fail git am lorem-move.patch && 240 329 test -d .git/rebase-apply && ··· 242 331 git add file && 243 332 git am --resolved && 244 333 ! test -d .git/rebase-apply && 245 - test goodbye = "$(cat another)" 334 + test_cmp expected another 246 335 ' 247 336 248 337 test_expect_success 'am takes patches from a Pine mailbox' ' 338 + rm -fr .git/rebase-apply && 339 + git reset --hard && 249 340 git checkout first && 250 341 cat pine patch1 | git am && 251 342 ! test -d .git/rebase-apply && 252 - test -z "$(git diff master^..HEAD)" 343 + git diff --exit-code master^..HEAD 253 344 ' 254 345 255 346 test_expect_success 'am fails on mail without patch' ' 347 + rm -fr .git/rebase-apply && 348 + git reset --hard && 256 349 test_must_fail git am <failmail && 257 - rm -r .git/rebase-apply/ 350 + git am --abort && 351 + ! test -d .git/rebase-apply 258 352 ' 259 353 260 354 test_expect_success 'am fails on empty patch' ' 355 + rm -fr .git/rebase-apply && 356 + git reset --hard && 261 357 echo "---" >>failmail && 262 358 test_must_fail git am <failmail && 263 359 git am --skip && ··· 266 362 267 363 test_expect_success 'am works from stdin in subdirectory' ' 268 364 rm -fr subdir && 365 + rm -fr .git/rebase-apply && 366 + git reset --hard && 269 367 git checkout first && 270 368 ( 271 369 mkdir -p subdir && 272 370 cd subdir && 273 371 git am <../patch1 274 372 ) && 275 - test -z "$(git diff second)" 373 + git diff --exit-code second 276 374 ' 277 375 278 376 test_expect_success 'am works from file (relative path given) in subdirectory' ' 279 377 rm -fr subdir && 378 + rm -fr .git/rebase-apply && 379 + git reset --hard && 280 380 git checkout first && 281 381 ( 282 382 mkdir -p subdir && 283 383 cd subdir && 284 384 git am ../patch1 285 385 ) && 286 - test -z "$(git diff second)" 386 + git diff --exit-code second 287 387 ' 288 388 289 389 test_expect_success 'am works from file (absolute path given) in subdirectory' ' 290 390 rm -fr subdir && 391 + rm -fr .git/rebase-apply && 392 + git reset --hard && 291 393 git checkout first && 292 394 P=$(pwd) && 293 395 ( ··· 295 397 cd subdir && 296 398 git am "$P/patch1" 297 399 ) && 298 - test -z "$(git diff second)" 400 + git diff --exit-code second 299 401 ' 300 402 301 403 test_expect_success 'am --committer-date-is-author-date' ' 404 + rm -fr .git/rebase-apply && 405 + git reset --hard && 302 406 git checkout first && 303 407 test_tick && 304 408 git am --committer-date-is-author-date patch1 && 305 409 git cat-file commit HEAD | sed -e "/^\$/q" >head1 && 306 - at=$(sed -ne "/^author /s/.*> //p" head1) && 307 - ct=$(sed -ne "/^committer /s/.*> //p" head1) && 308 - test "$at" = "$ct" 410 + sed -ne "/^author /s/.*> //p" head1 >at && 411 + sed -ne "/^committer /s/.*> //p" head1 >ct && 412 + test_cmp at ct 309 413 ' 310 414 311 415 test_expect_success 'am without --committer-date-is-author-date' ' 416 + rm -fr .git/rebase-apply && 417 + git reset --hard && 312 418 git checkout first && 313 419 test_tick && 314 420 git am patch1 && 315 421 git cat-file commit HEAD | sed -e "/^\$/q" >head1 && 316 - at=$(sed -ne "/^author /s/.*> //p" head1) && 317 - ct=$(sed -ne "/^committer /s/.*> //p" head1) && 318 - test "$at" != "$ct" 422 + sed -ne "/^author /s/.*> //p" head1 >at && 423 + sed -ne "/^committer /s/.*> //p" head1 >ct && 424 + ! test_cmp at ct 319 425 ' 320 426 321 427 # This checks for +0000 because TZ is set to UTC and that should ··· 323 429 # by test_tick that uses -0700 timezone; if this feature does not 324 430 # work, we will see that instead of +0000. 325 431 test_expect_success 'am --ignore-date' ' 432 + rm -fr .git/rebase-apply && 433 + git reset --hard && 326 434 git checkout first && 327 435 test_tick && 328 436 git am --ignore-date patch1 && 329 437 git cat-file commit HEAD | sed -e "/^\$/q" >head1 && 330 - at=$(sed -ne "/^author /s/.*> //p" head1) && 331 - echo "$at" | grep "+0000" 438 + sed -ne "/^author /s/.*> //p" head1 >at && 439 + grep "+0000" at 332 440 ' 333 441 334 442 test_expect_success 'am into an unborn branch' ' 443 + git rev-parse first^{tree} >expected && 444 + rm -fr .git/rebase-apply && 445 + git reset --hard && 335 446 rm -fr subdir && 336 - mkdir -p subdir && 447 + mkdir subdir && 337 448 git format-patch --numbered-files -o subdir -1 first && 338 449 ( 339 450 cd subdir && 340 451 git init && 341 452 git am 1 342 453 ) && 343 - result=$( 344 - cd subdir && git rev-parse HEAD^{tree} 454 + ( 455 + cd subdir && 456 + git rev-parse HEAD^{tree} >../actual 345 457 ) && 346 - test "z$result" = "z$(git rev-parse first^{tree})" 458 + test_cmp expected actual 347 459 ' 348 460 349 461 test_expect_success 'am newline in subject' ' 462 + rm -fr .git/rebase-apply && 463 + git reset --hard && 350 464 git checkout first && 351 465 test_tick && 352 - sed -e "s/second/second \\\n foo/" patch1 > patchnl && 353 - git am < patchnl > output.out 2>&1 && 466 + sed -e "s/second/second \\\n foo/" patch1 >patchnl && 467 + git am <patchnl >output.out 2>&1 && 354 468 grep "^Applying: second \\\n foo$" output.out 355 469 ' 356 470 357 471 test_expect_success 'am -q is quiet' ' 472 + rm -fr .git/rebase-apply && 473 + git reset --hard && 358 474 git checkout first && 359 475 test_tick && 360 - git am -q < patch1 > output.out 2>&1 && 476 + git am -q <patch1 >output.out 2>&1 && 361 477 ! test -s output.out 362 478 ' 363 479
+4
t/test-lib.sh
··· 256 256 tr Q '\015' 257 257 } 258 258 259 + q_to_tab () { 260 + tr Q '\011' 261 + } 262 + 259 263 append_cr () { 260 264 sed -e 's/$/Q/' | tr Q '\015' 261 265 }