t / t3511-cherry-pick-x.shon commit sequencer.c: recognize "(cherry picked from ..." as part of s-o-b footer (cd650a4)
   1#!/bin/sh
   2
   3test_description='Test cherry-pick -x and -s'
   4
   5. ./test-lib.sh
   6
   7pristine_detach () {
   8        git cherry-pick --quit &&
   9        git checkout -f "$1^0" &&
  10        git read-tree -u --reset HEAD &&
  11        git clean -d -f -f -q -x
  12}
  13
  14mesg_one_line='base: commit message'
  15
  16mesg_no_footer="$mesg_one_line
  17
  18OneWordBodyThatsNotA-S-o-B"
  19
  20mesg_with_footer="$mesg_no_footer
  21
  22Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
  23Signed-off-by: A.U. Thor <author@example.com>
  24Signed-off-by: B.U. Thor <buthor@example.com>"
  25
  26mesg_broken_footer="$mesg_no_footer
  27
  28The signed-off-by string should begin with the words Signed-off-by followed
  29by a colon and space, and then the signers name and email address. e.g.
  30Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
  31
  32mesg_with_footer_sob="$mesg_with_footer
  33Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
  34
  35mesg_with_cherry_footer="$mesg_with_footer_sob
  36(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
  37Tested-by: C.U. Thor <cuthor@example.com>"
  38
  39
  40test_expect_success setup '
  41        git config advice.detachedhead false &&
  42        echo unrelated >unrelated &&
  43        git add unrelated &&
  44        test_commit initial foo a &&
  45        test_commit "$mesg_one_line" foo b mesg-one-line &&
  46        git reset --hard initial &&
  47        test_commit "$mesg_no_footer" foo b mesg-no-footer &&
  48        git reset --hard initial &&
  49        test_commit "$mesg_broken_footer" foo b mesg-broken-footer &&
  50        git reset --hard initial &&
  51        test_commit "$mesg_with_footer" foo b mesg-with-footer &&
  52        git reset --hard initial &&
  53        test_commit "$mesg_with_footer_sob" foo b mesg-with-footer-sob &&
  54        git reset --hard initial &&
  55        test_commit "$mesg_with_cherry_footer" foo b mesg-with-cherry-footer &&
  56        pristine_detach initial &&
  57        test_commit conflicting unrelated
  58'
  59
  60test_expect_success 'cherry-pick -s inserts blank line after one line subject' '
  61        pristine_detach initial &&
  62        git cherry-pick -s mesg-one-line &&
  63        cat <<-EOF >expect &&
  64                $mesg_one_line
  65
  66                Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
  67        EOF
  68        git log -1 --pretty=format:%B >actual &&
  69        test_cmp expect actual
  70'
  71
  72test_expect_failure 'cherry-pick -s inserts blank line after non-conforming footer' '
  73        pristine_detach initial &&
  74        git cherry-pick -s mesg-broken-footer &&
  75        cat <<-EOF >expect &&
  76                $mesg_broken_footer
  77
  78                Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
  79        EOF
  80        git log -1 --pretty=format:%B >actual &&
  81        test_cmp expect actual
  82'
  83
  84test_expect_success 'cherry-pick -s inserts blank line when conforming footer not found' '
  85        pristine_detach initial &&
  86        git cherry-pick -s mesg-no-footer &&
  87        cat <<-EOF >expect &&
  88                $mesg_no_footer
  89
  90                Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
  91        EOF
  92        git log -1 --pretty=format:%B >actual &&
  93        test_cmp expect actual
  94'
  95
  96test_expect_success 'cherry-pick -s adds sob when last sob doesnt match committer' '
  97        pristine_detach initial &&
  98        git cherry-pick -s mesg-with-footer &&
  99        cat <<-EOF >expect &&
 100                $mesg_with_footer
 101                Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
 102        EOF
 103        git log -1 --pretty=format:%B >actual &&
 104        test_cmp expect actual
 105'
 106
 107test_expect_success 'cherry-pick -x -s adds sob when last sob doesnt match committer' '
 108        pristine_detach initial &&
 109        sha1=`git rev-parse mesg-with-footer^0` &&
 110        git cherry-pick -x -s mesg-with-footer &&
 111        cat <<-EOF >expect &&
 112                $mesg_with_footer
 113                (cherry picked from commit $sha1)
 114                Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
 115        EOF
 116        git log -1 --pretty=format:%B >actual &&
 117        test_cmp expect actual
 118'
 119
 120test_expect_success 'cherry-pick -s refrains from adding duplicate trailing sob' '
 121        pristine_detach initial &&
 122        git cherry-pick -s mesg-with-footer-sob &&
 123        cat <<-EOF >expect &&
 124                $mesg_with_footer_sob
 125        EOF
 126        git log -1 --pretty=format:%B >actual &&
 127        test_cmp expect actual
 128'
 129
 130test_expect_success 'cherry-pick -x -s adds sob even when trailing sob exists for committer' '
 131        pristine_detach initial &&
 132        sha1=`git rev-parse mesg-with-footer-sob^0` &&
 133        git cherry-pick -x -s mesg-with-footer-sob &&
 134        cat <<-EOF >expect &&
 135                $mesg_with_footer_sob
 136                (cherry picked from commit $sha1)
 137                Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
 138        EOF
 139        git log -1 --pretty=format:%B >actual &&
 140        test_cmp expect actual
 141'
 142
 143test_expect_success 'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
 144        pristine_detach initial &&
 145        sha1=`git rev-parse mesg-with-cherry-footer^0` &&
 146        git cherry-pick -x mesg-with-cherry-footer &&
 147        cat <<-EOF >expect &&
 148                $mesg_with_cherry_footer
 149                (cherry picked from commit $sha1)
 150        EOF
 151        git log -1 --pretty=format:%B >actual &&
 152        test_cmp expect actual
 153'
 154
 155test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part of footer' '
 156        pristine_detach initial &&
 157        git cherry-pick -s mesg-with-cherry-footer &&
 158        cat <<-EOF >expect &&
 159                $mesg_with_cherry_footer
 160                Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
 161        EOF
 162        git log -1 --pretty=format:%B >actual &&
 163        test_cmp expect actual
 164'
 165
 166test_done