From: Junio C Hamano Date: Mon, 5 Mar 2012 07:35:12 +0000 (-0800) Subject: Merge branch 'jc/am-3-nonstandard-popt' X-Git-Tag: v1.7.10-rc0~17 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/250f0a074a0bf7194c6a99c481211b0c9d8590a7?ds=inline;hp=-c Merge branch 'jc/am-3-nonstandard-popt' * jc/am-3-nonstandard-popt: test: "am -3" can accept non-standard -p am -3: allow nonstandard -p option --- 250f0a074a0bf7194c6a99c481211b0c9d8590a7 diff --combined git-am.sh index 906f91f188,d5d168fc51..0bd290b4ae --- a/git-am.sh +++ b/git-am.sh @@@ -15,7 -15,6 +15,7 @@@ q,quiet be quie s,signoff add a Signed-off-by line to the commit message u,utf8 recode into utf8 (default) k,keep pass -k flag to git-mailinfo +keep-non-patch pass -b flag to git-mailinfo keep-cr pass --keep-cr flag to git-mailsplit for mbox format no-keep-cr do not pass --keep-cr flag to git-mailsplit independent of am.keepcr c,scissors strip everything before a scissors line @@@ -128,15 -127,18 +128,18 @@@ fall_back_3way () mkdir "$dotest/patch-merge-tmp-dir" # First see if the patch records the index info that we can use. - git apply --build-fake-ancestor "$dotest/patch-merge-tmp-index" \ - "$dotest/patch" && + cmd="git apply $git_apply_opt --build-fake-ancestor" && + cmd="$cmd "'"$dotest/patch-merge-tmp-index" "$dotest/patch"' && + eval "$cmd" && GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \ git write-tree >"$dotest/patch-merge-base+" || cannot_fallback "$(gettext "Repository lacks necessary blobs to fall back on 3-way merge.")" say Using index info to reconstruct a base tree... - if GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \ - git apply --cached <"$dotest/patch" + + cmd='GIT_INDEX_FILE="$dotest/patch-merge-tmp-index"' + cmd="$cmd git apply --cached $git_apply_opt"' <"$dotest/patch"' + if eval "$cmd" then mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base" mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index" @@@ -202,7 -204,7 +205,7 @@@ check_patch_format () l1= while test -z "$l1" do - read l1 + read l1 || break done read l2 read l3 @@@ -388,8 -390,6 +391,8 @@@ d utf8= ;; -k|--keep) keep=t ;; + --keep-non-patch) + keep=b ;; -c|--scissors) scissors=t ;; --no-scissors) @@@ -568,25 -568,16 +571,25 @@@ case "$resolved" i fi esac +# Now, decide what command line options we will give to the git +# commands we invoke, based on the result of parsing command line +# options and previous invocation state stored in $dotest/ files. + if test "$(cat "$dotest/utf8")" = t then utf8=-u else utf8=-n fi -if test "$(cat "$dotest/keep")" = t -then - keep=-k -fi +keep=$(cat "$dotest/keep") +case "$keep" in +t) + keep=-k ;; +b) + keep=-b ;; +*) + keep= ;; +esac case "$(cat "$dotest/scissors")" in t) scissors=--scissors ;; diff --combined t/t4150-am.sh index 6f77fffee6,e1d381c43b..ccc0280f52 --- a/t/t4150-am.sh +++ b/t/t4150-am.sh @@@ -123,6 -123,7 +123,7 @@@ test_expect_success setup git commit -m "added another file" && git format-patch --stdout master >lorem-move.patch && + git format-patch --no-prefix --stdout master >lorem-zero.patch && git checkout -b rename && git mv file renamed && @@@ -136,7 -137,7 +137,7 @@@ git format-patch -M --stdout lorem^ >rename-add.patch && # reset time - unset test_tick && + sane_unset test_tick && test_tick ' @@@ -237,7 -238,7 +238,7 @@@ test_expect_success 'am stays in branch test_expect_success 'am --signoff does not add Signed-off-by: line if already there' ' 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] [foo," patch3 >patch4 && rm -fr .git/rebase-apply && git reset --hard && git checkout HEAD^ && @@@ -259,17 -260,7 +260,17 @@@ test_expect_success 'am --keep really k git am --keep patch4 && ! test -d .git/rebase-apply && git cat-file commit HEAD >actual && - grep "Re: Re: Re: \[PATCH 1/5 v2\] third" actual + grep "Re: Re: Re: \[PATCH 1/5 v2\] \[foo\] third" actual +' + +test_expect_success 'am --keep-non-patch really keeps the non-patch part' ' + rm -fr .git/rebase-apply && + git reset --hard && + git checkout HEAD^ && + git am --keep-non-patch patch4 && + ! test -d .git/rebase-apply && + git cat-file commit HEAD >actual && + grep "^\[foo\] third" actual ' test_expect_success 'am -3 falls back to 3-way merge' ' @@@ -286,6 -277,20 +287,20 @@@ git diff --exit-code lorem ' + test_expect_success 'am -3 -p0 can read --no-prefix patch' ' + rm -fr .git/rebase-apply && + git reset --hard && + git checkout -b lorem3 master2 && + sed -n -e "3,\$p" msg >file && + head -n 9 msg >>file && + git add file && + test_tick && + git commit -m "copied stuff" && + git am -3 -p0 lorem-zero.patch && + ! test -d .git/rebase-apply && + git diff --exit-code lorem + ' + test_expect_success 'am can rename a file' ' grep "^rename from" rename.patch && rm -fr .git/rebase-apply && @@@ -505,14 -510,4 +520,14 @@@ test_expect_success 'am -q is quiet' ! test -s output.out ' +test_expect_success 'am empty-file does not infloop' ' + rm -fr .git/rebase-apply && + git reset --hard && + touch empty-file && + test_tick && + { git am empty-file > actual 2>&1 && false || :; } && + echo Patch format detection failed. >expected && + test_cmp expected actual +' + test_done