t / t3506-cherry-pick-ff.shon commit apply: register conflicted stages to the index (4f4a6cb)
   1#!/bin/sh
   2
   3test_description='test cherry-picking with --ff option'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8        echo first > file1 &&
   9        git add file1 &&
  10        test_tick &&
  11        git commit -m "first" &&
  12        git tag first &&
  13
  14        git checkout -b other &&
  15        echo second >> file1 &&
  16        git add file1 &&
  17        test_tick &&
  18        git commit -m "second" &&
  19        git tag second
  20'
  21
  22test_expect_success 'cherry-pick using --ff fast forwards' '
  23        git checkout master &&
  24        git reset --hard first &&
  25        test_tick &&
  26        git cherry-pick --ff second &&
  27        test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify second)"
  28'
  29
  30test_expect_success 'cherry-pick not using --ff does not fast forwards' '
  31        git checkout master &&
  32        git reset --hard first &&
  33        test_tick &&
  34        git cherry-pick second &&
  35        test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify second)"
  36'
  37
  38#
  39# We setup the following graph:
  40#
  41#             B---C
  42#            /   /
  43#       first---A
  44#
  45# (This has been taken from t3502-cherry-pick-merge.sh)
  46#
  47test_expect_success 'merge setup' '
  48        git checkout master &&
  49        git reset --hard first &&
  50        echo new line >A &&
  51        git add A &&
  52        test_tick &&
  53        git commit -m "add line to A" A &&
  54        git tag A &&
  55        git checkout -b side first &&
  56        echo new line >B &&
  57        git add B &&
  58        test_tick &&
  59        git commit -m "add line to B" B &&
  60        git tag B &&
  61        git checkout master &&
  62        git merge side &&
  63        git tag C &&
  64        git checkout -b new A
  65'
  66
  67test_expect_success 'cherry-pick a non-merge with --ff and -m should fail' '
  68        git reset --hard A -- &&
  69        test_must_fail git cherry-pick --ff -m 1 B &&
  70        git diff --exit-code A --
  71'
  72
  73test_expect_success 'cherry pick a merge with --ff but without -m should fail' '
  74        git reset --hard A -- &&
  75        test_must_fail git cherry-pick --ff C &&
  76        git diff --exit-code A --
  77'
  78
  79test_expect_success 'cherry pick with --ff a merge (1)' '
  80        git reset --hard A -- &&
  81        git cherry-pick --ff -m 1 C &&
  82        git diff --exit-code C &&
  83        test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify C)"
  84'
  85
  86test_expect_success 'cherry pick with --ff a merge (2)' '
  87        git reset --hard B -- &&
  88        git cherry-pick --ff -m 2 C &&
  89        git diff --exit-code C &&
  90        test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify C)"
  91'
  92
  93test_expect_success 'cherry pick a merge relative to nonexistent parent with --ff should fail' '
  94        git reset --hard B -- &&
  95        test_must_fail git cherry-pick --ff -m 3 C
  96'
  97
  98test_expect_success 'cherry pick a root commit with --ff' '
  99        git reset --hard first -- &&
 100        git rm file1 &&
 101        echo first >file2 &&
 102        git add file2 &&
 103        git commit --amend -m "file2" &&
 104        git cherry-pick --ff first &&
 105        test "$(git rev-parse --verify HEAD)" = "1df192cd8bc58a2b275d842cede4d221ad9000d1"
 106'
 107
 108test_done