t / t3505-cherry-pick-empty.shon commit doc: promote "git restore" (80f537f)
   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-message-branch &&
  15        echo third >> file1 &&
  16        git add file1 &&
  17        test_tick &&
  18        git commit --allow-empty-message -m "" &&
  19
  20        git checkout master &&
  21        git checkout -b empty-change-branch &&
  22        test_tick &&
  23        git commit --allow-empty -m "empty"
  24
  25'
  26
  27test_expect_success 'cherry-pick an empty commit' '
  28        git checkout master &&
  29        test_expect_code 1 git cherry-pick empty-change-branch
  30'
  31
  32test_expect_success 'index lockfile was removed' '
  33        test ! -f .git/index.lock
  34'
  35
  36test_expect_success 'cherry-pick a commit with an empty message' '
  37        test_when_finished "git reset --hard empty-message-branch~1" &&
  38        git checkout master &&
  39        git cherry-pick empty-message-branch
  40'
  41
  42test_expect_success 'index lockfile was removed' '
  43        test ! -f .git/index.lock
  44'
  45
  46test_expect_success 'cherry-pick a commit with an empty message with --allow-empty-message' '
  47        git checkout -f master &&
  48        git cherry-pick --allow-empty-message empty-message-branch
  49'
  50
  51test_expect_success 'cherry pick an empty non-ff commit without --allow-empty' '
  52        git checkout master &&
  53        echo fourth >>file2 &&
  54        git add file2 &&
  55        git commit -m "fourth" &&
  56        test_must_fail git cherry-pick empty-change-branch
  57'
  58
  59test_expect_success 'cherry pick an empty non-ff commit with --allow-empty' '
  60        git checkout master &&
  61        git cherry-pick --allow-empty empty-change-branch
  62'
  63
  64test_expect_success 'cherry pick with --keep-redundant-commits' '
  65        git checkout master &&
  66        git cherry-pick --keep-redundant-commits HEAD^
  67'
  68
  69test_expect_success 'cherry-pick a commit that becomes no-op (prep)' '
  70        git checkout master &&
  71        git branch fork &&
  72        echo foo >file2 &&
  73        git add file2 &&
  74        test_tick &&
  75        git commit -m "add file2 on master" &&
  76
  77        git checkout fork &&
  78        echo foo >file2 &&
  79        git add file2 &&
  80        test_tick &&
  81        git commit -m "add file2 on the side"
  82'
  83
  84test_expect_success 'cherry-pick a no-op without --keep-redundant' '
  85        git reset --hard &&
  86        git checkout fork^0 &&
  87        test_must_fail git cherry-pick master
  88'
  89
  90test_expect_success 'cherry-pick a no-op with --keep-redundant' '
  91        git reset --hard &&
  92        git checkout fork^0 &&
  93        git cherry-pick --keep-redundant-commits master &&
  94        git show -s --format=%s >actual &&
  95        echo "add file2 on master" >expect &&
  96        test_cmp expect actual
  97'
  98
  99test_done