1#!/bin/sh
   2test_description='test cherry-picking an empty commit'
   4. ./test-lib.sh
   6test_expect_success setup '
   8        echo first > file1 &&
  10        git add file1 &&
  11        test_tick &&
  12        git commit -m "first" &&
  13        git checkout -b empty-branch &&
  15        test_tick &&
  16        git commit --allow-empty -m "empty" &&
  17        echo third >> file1 &&
  19        git add file1 &&
  20        test_tick &&
  21        git commit --allow-empty-message -m "" &&
  22        git checkout master &&
  24        git checkout -b empty-branch2 &&
  25        test_tick &&
  26        git commit --allow-empty -m "empty"
  27'
  29test_expect_success 'cherry-pick an empty commit' '
  31        git checkout master && {
  32                git cherry-pick empty-branch^
  33                test "$?" = 1
  34        }
  35'
  36test_expect_success 'index lockfile was removed' '
  38        test ! -f .git/index.lock
  40'
  42test_expect_success 'cherry-pick a commit with an empty message' '
  44        git checkout master && {
  45                git cherry-pick empty-branch
  46                test "$?" = 1
  47        }
  48'
  49test_expect_success 'index lockfile was removed' '
  51        test ! -f .git/index.lock
  53'
  55test_expect_success 'cherry-pick a commit with an empty message with --allow-empty-message' '
  57        git checkout -f master &&
  58        git cherry-pick --allow-empty-message empty-branch
  59'
  60test_expect_success 'cherry pick an empty non-ff commit without --allow-empty' '
  62        git checkout master &&
  63        echo fourth >>file2 &&
  64        git add file2 &&
  65        git commit -m "fourth" &&
  66        test_must_fail git cherry-pick empty-branch2
  67'
  68test_expect_success 'cherry pick an empty non-ff commit with --allow-empty' '
  70        git checkout master &&
  71        git cherry-pick --allow-empty empty-branch2
  72'
  73test_expect_success 'cherry pick with --keep-redundant-commits' '
  75        git checkout master &&
  76        git cherry-pick --keep-redundant-commits HEAD^
  77'
  78test_expect_success 'cherry-pick a commit that becomes no-op (prep)' '
  80        git checkout master &&
  81        git branch fork &&
  82        echo foo >file2 &&
  83        git add file2 &&
  84        test_tick &&
  85        git commit -m "add file2 on master" &&
  86        git checkout fork &&
  88        echo foo >file2 &&
  89        git add file2 &&
  90        test_tick &&
  91        git commit -m "add file2 on the side"
  92'
  93test_expect_success 'cherry-pick a no-op without --keep-redundant' '
  95        git reset --hard &&
  96        git checkout fork^0 &&
  97        test_must_fail git cherry-pick master
  98'
  99test_expect_success 'cherry-pick a no-op with --keep-redundant' '
 101        git reset --hard &&
 102        git checkout fork^0 &&
 103        git cherry-pick --keep-redundant-commits master &&
 104        git show -s --format='%s' >actual &&
 105        echo "add file2 on master" >expect &&
 106        test_cmp expect actual
 107'
 108test_done