OSDN Git Service

Merge branch 'pt/am-tests'
authorJunio C Hamano <gitster@pobox.com>
Mon, 3 Aug 2015 18:01:26 +0000 (11:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 3 Aug 2015 18:01:27 +0000 (11:01 -0700)
* pt/am-tests:
  t3901: test git-am encoding conversion
  t3418: non-interactive rebase --continue with rerere enabled
  t4150: tests for am --[no-]scissors
  t4150: am with post-applypatch hook
  t4150: am with pre-applypatch hook
  t4150: am with applypatch-msg hook
  t4150: am --resolved fails if index has unmerged entries
  t4150: am --resolved fails if index has no changes
  t4150: am refuses patches when paused
  t4151: am --abort will keep dirty index intact
  t4150: am fails if index is dirty
  t4150: am.messageid really adds the message id

1  2 
t/t4150-am.sh

diff --cc t/t4150-am.sh
@@@ -104,39 -117,21 +117,53 @@@ test_expect_success setup 
                echo "X-Fake-Field: Line Three" &&
                git format-patch --stdout first | sed -e "1d"
        } > patch1-ws.eml &&
 +      {
 +              sed -ne "1p" msg &&
 +              echo &&
 +              echo "From: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" &&
 +              echo "Date: $GIT_AUTHOR_DATE" &&
 +              echo &&
 +              sed -e "1,2d" msg &&
 +              echo &&
 +              echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" &&
 +              echo "---" &&
 +              git diff-tree --no-commit-id --stat -p second
 +      } >patch1-stgit.eml &&
 +      mkdir stgit-series &&
 +      cp patch1-stgit.eml stgit-series/patch &&
 +      {
 +              echo "# This series applies on GIT commit $(git rev-parse first)" &&
 +              echo "patch"
 +      } >stgit-series/series &&
 +      {
 +              echo "# HG changeset patch" &&
 +              echo "# User $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" &&
 +              echo "# Date $test_tick 25200" &&
 +              echo "#      $(git show --pretty="%aD" -s second)" &&
 +              echo "# Node ID $_z40" &&
 +              echo "# Parent  $_z40" &&
 +              cat msg &&
 +              echo &&
 +              echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" &&
 +              echo &&
 +              git diff-tree --no-commit-id -p second
 +      } >patch1-hg.eml &&
 +
  
+       echo scissors-file >scissors-file &&
+       git add scissors-file &&
+       git commit -F scissors-msg &&
+       git tag scissors &&
+       git format-patch --stdout scissors^ >scissors-patch.eml &&
+       git reset --hard HEAD^ &&
+       echo no-scissors-file >no-scissors-file &&
+       git add no-scissors-file &&
+       git commit -F no-scissors-msg &&
+       git tag no-scissors &&
+       git format-patch --stdout no-scissors^ >no-scissors-patch.eml &&
+       git reset --hard HEAD^ &&
        sed -n -e "3,\$p" msg >file &&
        git add file &&
        test_tick &&
@@@ -219,56 -226,133 +258,183 @@@ test_expect_success 'am applies patch e
        test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
  '
  
 +test_expect_success 'am applies stgit patch' '
 +      rm -fr .git/rebase-apply &&
 +      git checkout -f first &&
 +      git am patch1-stgit.eml &&
 +      test_path_is_missing .git/rebase-apply &&
 +      git diff --exit-code second &&
 +      test_cmp_rev second HEAD &&
 +      test_cmp_rev second^ HEAD^
 +'
 +
 +test_expect_success 'am --patch-format=stgit applies stgit patch' '
 +      rm -fr .git/rebase-apply &&
 +      git checkout -f first &&
 +      git am --patch-format=stgit <patch1-stgit.eml &&
 +      test_path_is_missing .git/rebase-apply &&
 +      git diff --exit-code second &&
 +      test_cmp_rev second HEAD &&
 +      test_cmp_rev second^ HEAD^
 +'
 +
 +test_expect_success 'am applies stgit series' '
 +      rm -fr .git/rebase-apply &&
 +      git checkout -f first &&
 +      git am stgit-series/series &&
 +      test_path_is_missing .git/rebase-apply &&
 +      git diff --exit-code second &&
 +      test_cmp_rev second HEAD &&
 +      test_cmp_rev second^ HEAD^
 +'
 +
 +test_expect_success 'am applies hg patch' '
 +      rm -fr .git/rebase-apply &&
 +      git checkout -f first &&
 +      git am patch1-hg.eml &&
 +      test_path_is_missing .git/rebase-apply &&
 +      git diff --exit-code second &&
 +      test_cmp_rev second HEAD &&
 +      test_cmp_rev second^ HEAD^
 +'
 +
 +test_expect_success 'am --patch-format=hg applies hg patch' '
 +      rm -fr .git/rebase-apply &&
 +      git checkout -f first &&
 +      git am --patch-format=hg <patch1-hg.eml &&
 +      test_path_is_missing .git/rebase-apply &&
 +      git diff --exit-code second &&
 +      test_cmp_rev second HEAD &&
 +      test_cmp_rev second^ HEAD^
 +'
 +
+ test_expect_success 'am with applypatch-msg hook' '
+       test_when_finished "rm -f .git/hooks/applypatch-msg" &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout first &&
+       mkdir -p .git/hooks &&
+       write_script .git/hooks/applypatch-msg <<-\EOF &&
+       cat "$1" >actual-msg &&
+       echo hook-message >"$1"
+       EOF
+       git am patch1 &&
+       test_path_is_missing .git/rebase-apply &&
+       git diff --exit-code second &&
+       echo hook-message >expected &&
+       git log -1 --format=format:%B >actual &&
+       test_cmp expected actual &&
+       git log -1 --format=format:%B second >expected &&
+       test_cmp expected actual-msg
+ '
+ test_expect_success 'am with failing applypatch-msg hook' '
+       test_when_finished "rm -f .git/hooks/applypatch-msg" &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout first &&
+       mkdir -p .git/hooks &&
+       write_script .git/hooks/applypatch-msg <<-\EOF &&
+       exit 1
+       EOF
+       test_must_fail git am patch1 &&
+       test_path_is_dir .git/rebase-apply &&
+       git diff --exit-code first &&
+       test_cmp_rev first HEAD
+ '
+ test_expect_success 'am with pre-applypatch hook' '
+       test_when_finished "rm -f .git/hooks/pre-applypatch" &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout first &&
+       mkdir -p .git/hooks &&
+       write_script .git/hooks/pre-applypatch <<-\EOF &&
+       git diff first >diff.actual
+       exit 0
+       EOF
+       git am patch1 &&
+       test_path_is_missing .git/rebase-apply &&
+       git diff --exit-code second &&
+       test_cmp_rev second HEAD &&
+       git diff first..second >diff.expected &&
+       test_cmp diff.expected diff.actual
+ '
+ test_expect_success 'am with failing pre-applypatch hook' '
+       test_when_finished "rm -f .git/hooks/pre-applypatch" &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout first &&
+       mkdir -p .git/hooks &&
+       write_script .git/hooks/pre-applypatch <<-\EOF &&
+       exit 1
+       EOF
+       test_must_fail git am patch1 &&
+       test_path_is_dir .git/rebase-apply &&
+       git diff --exit-code second &&
+       test_cmp_rev first HEAD
+ '
+ test_expect_success 'am with post-applypatch hook' '
+       test_when_finished "rm -f .git/hooks/post-applypatch" &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout first &&
+       mkdir -p .git/hooks &&
+       write_script .git/hooks/post-applypatch <<-\EOF &&
+       git rev-parse HEAD >head.actual
+       git diff second >diff.actual
+       exit 0
+       EOF
+       git am patch1 &&
+       test_path_is_missing .git/rebase-apply &&
+       test_cmp_rev second HEAD &&
+       git rev-parse second >head.expected &&
+       test_cmp head.expected head.actual &&
+       git diff second >diff.expected &&
+       test_cmp diff.expected diff.actual
+ '
+ test_expect_success 'am with failing post-applypatch hook' '
+       test_when_finished "rm -f .git/hooks/post-applypatch" &&
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout first &&
+       mkdir -p .git/hooks &&
+       write_script .git/hooks/post-applypatch <<-\EOF &&
+       git rev-parse HEAD >head.actual
+       exit 1
+       EOF
+       git am patch1 &&
+       test_path_is_missing .git/rebase-apply &&
+       git diff --exit-code second &&
+       test_cmp_rev second HEAD &&
+       git rev-parse second >head.expected &&
+       test_cmp head.expected head.actual
+ '
+ test_expect_success 'am --scissors cuts the message at the scissors line' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout second &&
+       git am --scissors scissors-patch.eml &&
+       test_path_is_missing .git/rebase-apply &&
+       git diff --exit-code scissors &&
+       test_cmp_rev scissors HEAD
+ '
+ test_expect_success 'am --no-scissors overrides mailinfo.scissors' '
+       rm -fr .git/rebase-apply &&
+       git reset --hard &&
+       git checkout second &&
+       test_config mailinfo.scissors true &&
+       git am --no-scissors no-scissors-patch.eml &&
+       test_path_is_missing .git/rebase-apply &&
+       git diff --exit-code no-scissors &&
+       test_cmp_rev no-scissors HEAD
+ '
  test_expect_success 'setup: new author and committer' '
        GIT_AUTHOR_NAME="Another Thor" &&
        GIT_AUTHOR_EMAIL="a.thor@example.com" &&