t / t3505-cherry-pick-empty.shon commit Merge branch 'sb/checkout-explit-detach-no-advice' (e6dab9f)
   1#!/bin/sh
   2
   3test_description='test cherry-picking an empty commit'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8
   9        echo first > file1 &&
  10        git add file1 &&
  11        test_tick &&
  12        git commit -m "first" &&
  13
  14        git checkout -b empty-branch &&
  15        test_tick &&
  16        git commit --allow-empty -m "empty" &&
  17
  18        echo third >> file1 &&
  19        git add file1 &&
  20        test_tick &&
  21        git commit --allow-empty-message -m "" &&
  22
  23        git checkout master &&
  24        git checkout -b empty-branch2 &&
  25        test_tick &&
  26        git commit --allow-empty -m "empty"
  27
  28'
  29
  30test_expect_success 'cherry-pick an empty commit' '
  31        git checkout master &&
  32        test_expect_code 1 git cherry-pick empty-branch^
  33'
  34
  35test_expect_success 'index lockfile was removed' '
  36        test ! -f .git/index.lock
  37'
  38
  39test_expect_success 'cherry-pick a commit with an empty message' '
  40        git checkout master &&
  41        test_expect_code 1 git cherry-pick empty-branch
  42'
  43
  44test_expect_success 'index lockfile was removed' '
  45        test ! -f .git/index.lock
  46'
  47
  48test_expect_success 'cherry-pick a commit with an empty message with --allow-empty-message' '
  49        git checkout -f master &&
  50        git cherry-pick --allow-empty-message empty-branch
  51'
  52
  53test_expect_success 'cherry pick an empty non-ff commit without --allow-empty' '
  54        git checkout master &&
  55        echo fourth >>file2 &&
  56        git add file2 &&
  57        git commit -m "fourth" &&
  58        test_must_fail git cherry-pick empty-branch2
  59'
  60
  61test_expect_success 'cherry pick an empty non-ff commit with --allow-empty' '
  62        git checkout master &&
  63        git cherry-pick --allow-empty empty-branch2
  64'
  65
  66test_expect_success 'cherry pick with --keep-redundant-commits' '
  67        git checkout master &&
  68        git cherry-pick --keep-redundant-commits HEAD^
  69'
  70
  71test_expect_success 'cherry-pick a commit that becomes no-op (prep)' '
  72        git checkout master &&
  73        git branch fork &&
  74        echo foo >file2 &&
  75        git add file2 &&
  76        test_tick &&
  77        git commit -m "add file2 on master" &&
  78
  79        git checkout fork &&
  80        echo foo >file2 &&
  81        git add file2 &&
  82        test_tick &&
  83        git commit -m "add file2 on the side"
  84'
  85
  86test_expect_success 'cherry-pick a no-op without --keep-redundant' '
  87        git reset --hard &&
  88        git checkout fork^0 &&
  89        test_must_fail git cherry-pick master
  90'
  91
  92test_expect_success 'cherry-pick a no-op with --keep-redundant' '
  93        git reset --hard &&
  94        git checkout fork^0 &&
  95        git cherry-pick --keep-redundant-commits master &&
  96        git show -s --format=%s >actual &&
  97        echo "add file2 on master" >expect &&
  98        test_cmp expect actual
  99'
 100
 101test_done