Merge branch 'jn/rebase-rename-am'

* 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
This commit is contained in:
Junio C Hamano 2010-08-18 12:16:31 -07:00
Родитель ebb561bcfc 840b3ca758
Коммит 9c74b94401
5 изменённых файлов: 333 добавлений и 190 удалений

Просмотреть файл

@ -2979,8 +2979,7 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
else if (get_sha1(patch->old_sha1_prefix, sha1)) else if (get_sha1(patch->old_sha1_prefix, sha1))
/* git diff has no index line for mode/type changes */ /* git diff has no index line for mode/type changes */
if (!patch->lines_added && !patch->lines_deleted) { if (!patch->lines_added && !patch->lines_deleted) {
if (get_current_sha1(patch->new_name, sha1) || if (get_current_sha1(patch->old_name, sha1))
get_current_sha1(patch->old_name, sha1))
die("mode change for %s, which is not " die("mode change for %s, which is not "
"in current HEAD", name); "in current HEAD", name);
sha1_ptr = sha1; sha1_ptr = sha1;

Просмотреть файл

@ -544,7 +544,7 @@ fi
if test -z "$do_merge" if test -z "$do_merge"
then then
git format-patch -k --stdout --full-index --ignore-if-in-upstream \ git format-patch -k --stdout --full-index --ignore-if-in-upstream \
$root_flag "$revisions" | --no-renames $root_flag "$revisions" |
git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" && git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
move_to_original_branch move_to_original_branch
ret=$? ret=$?

Просмотреть файл

@ -14,13 +14,21 @@ GIT_AUTHOR_NAME=author@name
GIT_AUTHOR_EMAIL=bogus@email@address GIT_AUTHOR_EMAIL=bogus@email@address
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
test_expect_success \ test_expect_success 'prepare repository with topic branches' '
'prepare repository with topic branches' \ git config core.logAllRefUpdates true &&
'git config core.logAllRefUpdates true &&
echo First >A && echo First >A &&
git update-index --add A && git update-index --add A &&
git commit -m "Add A." && git commit -m "Add A." &&
git checkout -b my-topic-branch && git checkout -b force-3way &&
echo Dummy >Y &&
git update-index --add Y &&
git commit -m "Add Y." &&
git checkout -b filemove &&
git reset --soft master &&
mkdir D &&
git mv A D/A &&
git commit -m "Move A." &&
git checkout -b my-topic-branch master &&
echo Second >B && echo Second >B &&
git update-index --add B && git update-index --add B &&
git commit -m "Add B." && git commit -m "Add B." &&
@ -45,15 +53,18 @@ test_expect_success \
test_expect_success 'rebase on dirty worktree' ' test_expect_success 'rebase on dirty worktree' '
echo dirty >>A && echo dirty >>A &&
test_must_fail git rebase master' test_must_fail git rebase master
'
test_expect_success 'rebase on dirty cache' ' test_expect_success 'rebase on dirty cache' '
git add A && git add A &&
test_must_fail git rebase master' test_must_fail git rebase master
'
test_expect_success 'rebase against master' ' test_expect_success 'rebase against master' '
git reset --hard HEAD && git reset --hard HEAD &&
git rebase master' git rebase master
'
test_expect_success 'rebase against master twice' ' test_expect_success 'rebase against master twice' '
git rebase master >out && git rebase master >out &&
@ -77,13 +88,14 @@ test_expect_success 'rebase fast-forward to master' '
grep "Fast-forwarded HEAD to my-topic-branch" out grep "Fast-forwarded HEAD to my-topic-branch" out
' '
test_expect_success \ test_expect_success 'the rebase operation should not have destroyed author information' '
'the rebase operation should not have destroyed author information' \ ! (git log | grep "Author:" | grep "<>")
'! (git log | grep "Author:" | grep "<>")' '
test_expect_success \ test_expect_success 'the rebase operation should not have destroyed author information (2)' "
'the rebase operation should not have destroyed author information (2)' \ git log -1 |
"git log -1 | grep 'Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>'" grep 'Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>'
"
test_expect_success 'HEAD was detached during rebase' ' test_expect_success 'HEAD was detached during rebase' '
test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1}) test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1})
@ -103,8 +115,7 @@ test_expect_success 'rebase of history with merges is linearized' '
test 3 = $(git rev-list master.. | wc -l) test 3 = $(git rev-list master.. | wc -l)
' '
test_expect_success \ test_expect_success 'rebase of history with merges after upstream merge is linearized' '
'rebase of history with merges after upstream merge is linearized' '
git checkout upstream-merged-nonlinear && git checkout upstream-merged-nonlinear &&
test 5 = $(git rev-list master.. | wc -l) && test 5 = $(git rev-list master.. | wc -l) &&
git rebase master && git rebase master &&
@ -126,8 +137,21 @@ test_expect_success 'rebase a single mode change' '
GIT_TRACE=1 git rebase master GIT_TRACE=1 git rebase master
' '
test_expect_success 'rebase is not broken by diff.renames' '
git config diff.renames copies &&
test_when_finished "git config --unset diff.renames" &&
git checkout filemove &&
GIT_TRACE=1 git rebase force-3way
'
test_expect_success 'setup: recover' '
test_might_fail git rebase --abort &&
git reset --hard &&
git checkout modechange
'
test_expect_success 'Show verbose error when HEAD could not be detached' ' test_expect_success 'Show verbose error when HEAD could not be detached' '
: > B && >B &&
test_must_fail git rebase topic 2>output.err >output.out && test_must_fail git rebase topic 2>output.err >output.out &&
grep "Untracked working tree file .B. would be overwritten" output.err grep "Untracked working tree file .B. would be overwritten" output.err
' '

Просмотреть файл

@ -4,7 +4,8 @@ test_description='git am running'
. ./test-lib.sh . ./test-lib.sh
cat >msg <<EOF test_expect_success 'setup: messages' '
cat >msg <<-\EOF &&
second second
Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy
@ -15,12 +16,15 @@ ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. vero eos et accusam et justo duo dolores et ea rebum.
Duis autem vel eum iriure dolor in hendrerit in vulputate velit EOF
esse molestie consequat, vel illum dolore eu feugiat nulla facilisis q_to_tab <<-\EOF >>msg &&
at vero eros et accumsan et iusto odio dignissim qui blandit QDuis autem vel eum iriure dolor in hendrerit in vulputate velit
praesent luptatum zzril delenit augue duis dolore te feugait nulla Qesse molestie consequat, vel illum dolore eu feugiat nulla facilisis
facilisi. Qat vero eros et accumsan et iusto odio dignissim qui blandit
Qpraesent luptatum zzril delenit augue duis dolore te feugait nulla
Qfacilisi.
EOF
cat >>msg <<-\EOF &&
Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet,
consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
@ -38,22 +42,22 @@ dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
feugait nulla facilisi. feugait nulla facilisi.
EOF EOF
cat >failmail <<EOF cat >failmail <<-\EOF &&
From foo@example.com Fri May 23 10:43:49 2008 From foo@example.com Fri May 23 10:43:49 2008
From: foo@example.com From: foo@example.com
To: bar@example.com To: bar@example.com
Subject: Re: [RFC/PATCH] git-foo.sh Subject: Re: [RFC/PATCH] git-foo.sh
Date: Fri, 23 May 2008 05:23:42 +0200 Date: Fri, 23 May 2008 05:23:42 +0200
Sometimes we have to find out that there's nothing left. Sometimes we have to find out that there'\''s nothing left.
EOF EOF
cat >pine <<EOF cat >pine <<-\EOF &&
From MAILER-DAEMON Fri May 23 10:43:49 2008 From MAILER-DAEMON Fri May 23 10:43:49 2008
Date: 23 May 2008 05:23:42 +0200 Date: 23 May 2008 05:23:42 +0200
From: Mail System Internal Data <MAILER-DAEMON@example.com> From: Mail System Internal Data <MAILER-DAEMON@example.com>
Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA Subject: DON'\''T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
Message-ID: <foo-0001@example.com> Message-ID: <foo-0001@example.com>
This text is part of the internal format of your mail folder, and is not This text is part of the internal format of your mail folder, and is not
@ -63,7 +67,8 @@ with the data reset to initial values.
EOF EOF
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected signoff="Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
'
test_expect_success setup ' test_expect_success setup '
echo hello >file && echo hello >file &&
@ -71,11 +76,13 @@ test_expect_success setup '
test_tick && test_tick &&
git commit -m first && git commit -m first &&
git tag first && git tag first &&
echo world >>file && echo world >>file &&
git add file && git add file &&
test_tick && test_tick &&
git commit -s -F msg && git commit -s -F msg &&
git tag second && git tag second &&
git format-patch --stdout first >patch1 && git format-patch --stdout first >patch1 &&
{ {
echo "X-Fake-Field: Line One" && echo "X-Fake-Field: Line One" &&
@ -89,74 +96,101 @@ test_expect_success setup '
echo "X-Fake-Field: Line Three" && echo "X-Fake-Field: Line Three" &&
git format-patch --stdout first | sed -e "1d" git format-patch --stdout first | sed -e "1d"
} | append_cr >patch1-crlf.eml && } | append_cr >patch1-crlf.eml &&
sed -n -e "3,\$p" msg >file && sed -n -e "3,\$p" msg >file &&
git add file && git add file &&
test_tick && test_tick &&
git commit -m third && git commit -m third &&
git format-patch --stdout first >patch2 && git format-patch --stdout first >patch2 &&
git checkout -b lorem && git checkout -b lorem &&
sed -n -e "11,\$p" msg >file && sed -n -e "11,\$p" msg >file &&
head -n 9 msg >>file && head -n 9 msg >>file &&
test_tick && test_tick &&
git commit -a -m "moved stuff" && git commit -a -m "moved stuff" &&
echo goodbye >another && echo goodbye >another &&
git add another && git add another &&
test_tick && test_tick &&
git commit -m "added another file" && git commit -m "added another file" &&
git format-patch --stdout master >lorem-move.patch
' git format-patch --stdout master >lorem-move.patch &&
git checkout -b rename &&
git mv file renamed &&
git commit -m "renamed a file" &&
git format-patch -M --stdout lorem >rename.patch &&
git reset --soft lorem^ &&
git commit -m "renamed a file and added another" &&
git format-patch -M --stdout lorem^ >rename-add.patch &&
# reset time # reset time
unset test_tick unset test_tick &&
test_tick test_tick
'
test_expect_success 'am applies patch correctly' ' test_expect_success 'am applies patch correctly' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
test_tick && test_tick &&
git am <patch1 && git am <patch1 &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test -z "$(git diff second)" && git diff --exit-code second &&
test "$(git rev-parse second)" = "$(git rev-parse HEAD)" && test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
' '
test_expect_success 'am applies patch e-mail not in a mbox' ' test_expect_success 'am applies patch e-mail not in a mbox' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
git am patch1.eml && git am patch1.eml &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test -z "$(git diff second)" && git diff --exit-code second &&
test "$(git rev-parse second)" = "$(git rev-parse HEAD)" && test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
' '
test_expect_success 'am applies patch e-mail not in a mbox with CRLF' ' test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
git am patch1-crlf.eml && git am patch1-crlf.eml &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test -z "$(git diff second)" && git diff --exit-code second &&
test "$(git rev-parse second)" = "$(git rev-parse HEAD)" && test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
' '
GIT_AUTHOR_NAME="Another Thor" test_expect_success 'setup: new author and committer' '
GIT_AUTHOR_EMAIL="a.thor@example.com" GIT_AUTHOR_NAME="Another Thor" &&
GIT_COMMITTER_NAME="Co M Miter" GIT_AUTHOR_EMAIL="a.thor@example.com" &&
GIT_COMMITTER_EMAIL="c.miter@example.com" GIT_COMMITTER_NAME="Co M Miter" &&
GIT_COMMITTER_EMAIL="c.miter@example.com" &&
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
'
compare () { compare () {
test "$(git cat-file commit "$2" | grep "^$1 ")" = \ a=$(git cat-file commit "$2" | grep "^$1 ") &&
"$(git cat-file commit "$3" | grep "^$1 ")" b=$(git cat-file commit "$3" | grep "^$1 ") &&
test "$a" = "$b"
} }
test_expect_success 'am changes committer and keeps author' ' test_expect_success 'am changes committer and keeps author' '
test_tick && test_tick &&
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
git am patch2 && git am patch2 &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" && test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" &&
test -z "$(git diff master..HEAD)" && git diff --exit-code master..HEAD &&
test -z "$(git diff master^..HEAD^)" && git diff --exit-code master^..HEAD^ &&
compare author master HEAD && compare author master HEAD &&
compare author master^ HEAD^ && compare author master^ HEAD^ &&
test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \ test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \
@ -164,41 +198,55 @@ test_expect_success 'am changes committer and keeps author' '
' '
test_expect_success 'am --signoff adds Signed-off-by: line' ' test_expect_success 'am --signoff adds Signed-off-by: line' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout -b master2 first && git checkout -b master2 first &&
git am --signoff <patch2 && git am --signoff <patch2 &&
printf "%s\n" "$signoff" >expected &&
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected && echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected &&
git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
test_cmp actual expected && test_cmp expected actual &&
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected && echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
git cat-file commit HEAD | grep "Signed-off-by:" >actual && git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
test_cmp actual expected test_cmp expected actual
' '
test_expect_success 'am stays in branch' ' test_expect_success 'am stays in branch' '
test "refs/heads/master2" = "$(git symbolic-ref HEAD)" echo refs/heads/master2 >expected &&
git symbolic-ref HEAD >actual &&
test_cmp expected actual
' '
test_expect_success 'am --signoff does not add Signed-off-by: line if already there' ' test_expect_success 'am --signoff does not add Signed-off-by: line if already there' '
git format-patch --stdout HEAD^ >patch3 && git format-patch --stdout HEAD^ >patch3 &&
sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4 sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout HEAD^ && git checkout HEAD^ &&
git am --signoff patch4 && git am --signoff patch4 &&
test "$(git cat-file commit HEAD | grep -c "^Signed-off-by:")" -eq 1 git cat-file commit HEAD >actual &&
test $(grep -c "^Signed-off-by:" actual) -eq 1
' '
test_expect_success 'am without --keep removes Re: and [PATCH] stuff' ' test_expect_success 'am without --keep removes Re: and [PATCH] stuff' '
test "$(git rev-parse HEAD)" = "$(git rev-parse master2)" git rev-parse HEAD >expected &&
git rev-parse master2 >actual &&
test_cmp expected actual
' '
test_expect_success 'am --keep really keeps the subject' ' test_expect_success 'am --keep really keeps the subject' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout HEAD^ && git checkout HEAD^ &&
git am --keep patch4 && git am --keep patch4 &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
git cat-file commit HEAD | git cat-file commit HEAD >actual &&
fgrep "Re: Re: Re: [PATCH 1/5 v2] third" grep "Re: Re: Re: \[PATCH 1/5 v2\] third" actual
' '
test_expect_success 'am -3 falls back to 3-way merge' ' test_expect_success 'am -3 falls back to 3-way merge' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout -b lorem2 master2 && git checkout -b lorem2 master2 &&
sed -n -e "3,\$p" msg >file && sed -n -e "3,\$p" msg >file &&
head -n 9 msg >>file && head -n 9 msg >>file &&
@ -207,10 +255,45 @@ test_expect_success 'am -3 falls back to 3-way merge' '
git commit -m "copied stuff" && git commit -m "copied stuff" &&
git am -3 lorem-move.patch && git am -3 lorem-move.patch &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test -z "$(git diff lorem)" git diff --exit-code lorem
'
test_expect_success 'am can rename a file' '
grep "^rename from" rename.patch &&
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout lorem^0 &&
git am rename.patch &&
! test -d .git/rebase-apply &&
git update-index --refresh &&
git diff --exit-code rename
'
test_expect_success 'am -3 can rename a file' '
grep "^rename from" rename.patch &&
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout lorem^0 &&
git am -3 rename.patch &&
! test -d .git/rebase-apply &&
git update-index --refresh &&
git diff --exit-code rename
'
test_expect_success 'am -3 can rename a file after falling back to 3-way merge' '
grep "^rename from" rename-add.patch &&
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout lorem^0 &&
git am -3 rename-add.patch &&
! test -d .git/rebase-apply &&
git update-index --refresh &&
git diff --exit-code rename
' '
test_expect_success 'am -3 -q is quiet' ' test_expect_success 'am -3 -q is quiet' '
rm -fr .git/rebase-apply &&
git checkout -f lorem2 &&
git reset master2 --hard && git reset master2 --hard &&
sed -n -e "3,\$p" msg >file && sed -n -e "3,\$p" msg >file &&
head -n 9 msg >>file && head -n 9 msg >>file &&
@ -222,19 +305,25 @@ test_expect_success 'am -3 -q is quiet' '
' '
test_expect_success 'am pauses on conflict' ' test_expect_success 'am pauses on conflict' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout lorem2^^ && git checkout lorem2^^ &&
test_must_fail git am lorem-move.patch && test_must_fail git am lorem-move.patch &&
test -d .git/rebase-apply test -d .git/rebase-apply
' '
test_expect_success 'am --skip works' ' test_expect_success 'am --skip works' '
echo goodbye >expected &&
git am --skip && git am --skip &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test -z "$(git diff lorem2^^ -- file)" && git diff --exit-code lorem2^^ -- file &&
test goodbye = "$(cat another)" test_cmp expected another
' '
test_expect_success 'am --resolved works' ' test_expect_success 'am --resolved works' '
echo goodbye >expected &&
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout lorem2^^ && git checkout lorem2^^ &&
test_must_fail git am lorem-move.patch && test_must_fail git am lorem-move.patch &&
test -d .git/rebase-apply && test -d .git/rebase-apply &&
@ -242,22 +331,29 @@ test_expect_success 'am --resolved works' '
git add file && git add file &&
git am --resolved && git am --resolved &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test goodbye = "$(cat another)" test_cmp expected another
' '
test_expect_success 'am takes patches from a Pine mailbox' ' test_expect_success 'am takes patches from a Pine mailbox' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
cat pine patch1 | git am && cat pine patch1 | git am &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test -z "$(git diff master^..HEAD)" git diff --exit-code master^..HEAD
' '
test_expect_success 'am fails on mail without patch' ' test_expect_success 'am fails on mail without patch' '
rm -fr .git/rebase-apply &&
git reset --hard &&
test_must_fail git am <failmail && test_must_fail git am <failmail &&
rm -r .git/rebase-apply/ git am --abort &&
! test -d .git/rebase-apply
' '
test_expect_success 'am fails on empty patch' ' test_expect_success 'am fails on empty patch' '
rm -fr .git/rebase-apply &&
git reset --hard &&
echo "---" >>failmail && echo "---" >>failmail &&
test_must_fail git am <failmail && test_must_fail git am <failmail &&
git am --skip && git am --skip &&
@ -266,28 +362,34 @@ test_expect_success 'am fails on empty patch' '
test_expect_success 'am works from stdin in subdirectory' ' test_expect_success 'am works from stdin in subdirectory' '
rm -fr subdir && rm -fr subdir &&
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
( (
mkdir -p subdir && mkdir -p subdir &&
cd subdir && cd subdir &&
git am <../patch1 git am <../patch1
) && ) &&
test -z "$(git diff second)" git diff --exit-code second
' '
test_expect_success 'am works from file (relative path given) in subdirectory' ' test_expect_success 'am works from file (relative path given) in subdirectory' '
rm -fr subdir && rm -fr subdir &&
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
( (
mkdir -p subdir && mkdir -p subdir &&
cd subdir && cd subdir &&
git am ../patch1 git am ../patch1
) && ) &&
test -z "$(git diff second)" git diff --exit-code second
' '
test_expect_success 'am works from file (absolute path given) in subdirectory' ' test_expect_success 'am works from file (absolute path given) in subdirectory' '
rm -fr subdir && rm -fr subdir &&
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
P=$(pwd) && P=$(pwd) &&
( (
@ -295,27 +397,31 @@ test_expect_success 'am works from file (absolute path given) in subdirectory' '
cd subdir && cd subdir &&
git am "$P/patch1" git am "$P/patch1"
) && ) &&
test -z "$(git diff second)" git diff --exit-code second
' '
test_expect_success 'am --committer-date-is-author-date' ' test_expect_success 'am --committer-date-is-author-date' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
test_tick && test_tick &&
git am --committer-date-is-author-date patch1 && git am --committer-date-is-author-date patch1 &&
git cat-file commit HEAD | sed -e "/^\$/q" >head1 && git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
at=$(sed -ne "/^author /s/.*> //p" head1) && sed -ne "/^author /s/.*> //p" head1 >at &&
ct=$(sed -ne "/^committer /s/.*> //p" head1) && sed -ne "/^committer /s/.*> //p" head1 >ct &&
test "$at" = "$ct" test_cmp at ct
' '
test_expect_success 'am without --committer-date-is-author-date' ' test_expect_success 'am without --committer-date-is-author-date' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
test_tick && test_tick &&
git am patch1 && git am patch1 &&
git cat-file commit HEAD | sed -e "/^\$/q" >head1 && git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
at=$(sed -ne "/^author /s/.*> //p" head1) && sed -ne "/^author /s/.*> //p" head1 >at &&
ct=$(sed -ne "/^committer /s/.*> //p" head1) && sed -ne "/^committer /s/.*> //p" head1 >ct &&
test "$at" != "$ct" ! test_cmp at ct
' '
# This checks for +0000 because TZ is set to UTC and that should # This checks for +0000 because TZ is set to UTC and that should
@ -323,30 +429,38 @@ test_expect_success 'am without --committer-date-is-author-date' '
# by test_tick that uses -0700 timezone; if this feature does not # by test_tick that uses -0700 timezone; if this feature does not
# work, we will see that instead of +0000. # work, we will see that instead of +0000.
test_expect_success 'am --ignore-date' ' test_expect_success 'am --ignore-date' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
test_tick && test_tick &&
git am --ignore-date patch1 && git am --ignore-date patch1 &&
git cat-file commit HEAD | sed -e "/^\$/q" >head1 && git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
at=$(sed -ne "/^author /s/.*> //p" head1) && sed -ne "/^author /s/.*> //p" head1 >at &&
echo "$at" | grep "+0000" grep "+0000" at
' '
test_expect_success 'am into an unborn branch' ' test_expect_success 'am into an unborn branch' '
git rev-parse first^{tree} >expected &&
rm -fr .git/rebase-apply &&
git reset --hard &&
rm -fr subdir && rm -fr subdir &&
mkdir -p subdir && mkdir subdir &&
git format-patch --numbered-files -o subdir -1 first && git format-patch --numbered-files -o subdir -1 first &&
( (
cd subdir && cd subdir &&
git init && git init &&
git am 1 git am 1
) && ) &&
result=$( (
cd subdir && git rev-parse HEAD^{tree} cd subdir &&
git rev-parse HEAD^{tree} >../actual
) && ) &&
test "z$result" = "z$(git rev-parse first^{tree})" test_cmp expected actual
' '
test_expect_success 'am newline in subject' ' test_expect_success 'am newline in subject' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
test_tick && test_tick &&
sed -e "s/second/second \\\n foo/" patch1 >patchnl && sed -e "s/second/second \\\n foo/" patch1 >patchnl &&
@ -355,6 +469,8 @@ test_expect_success 'am newline in subject' '
' '
test_expect_success 'am -q is quiet' ' test_expect_success 'am -q is quiet' '
rm -fr .git/rebase-apply &&
git reset --hard &&
git checkout first && git checkout first &&
test_tick && test_tick &&
git am -q <patch1 >output.out 2>&1 && git am -q <patch1 >output.out 2>&1 &&

Просмотреть файл

@ -256,6 +256,10 @@ q_to_cr () {
tr Q '\015' tr Q '\015'
} }
q_to_tab () {
tr Q '\011'
}
append_cr () { append_cr () {
sed -e 's/$/Q/' | tr Q '\015' sed -e 's/$/Q/' | tr Q '\015'
} }