blob: f4159246e1e35d615bca2191393ea19427088dc0 [file] [log] [blame]
Alexander Gladyshf433f702010-07-09 07:10:52 -06001#!/bin/sh
2
3test_description='Test cherry-pick with directory/file conflicts'
Johannes Schindelincbc75a12020-11-18 23:44:26 +00004GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00005export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
Alexander Gladyshf433f702010-07-09 07:10:52 -06007. ./test-lib.sh
8
Pat Thoyts899663f2011-02-03 15:31:42 +00009test_expect_success 'Initialize repository' '
Alexander Gladyshf433f702010-07-09 07:10:52 -060010 mkdir a &&
11 >a/f &&
12 git add a &&
Pat Thoyts899663f2011-02-03 15:31:42 +000013 git commit -m a
14'
Alexander Gladyshf433f702010-07-09 07:10:52 -060015
Johannes Sixt622f98e2013-06-07 22:53:32 +020016test_expect_success 'Setup rename across paths each below D/F conflicts' '
Alexander Gladyshf433f702010-07-09 07:10:52 -060017 mkdir b &&
Johannes Sixt622f98e2013-06-07 22:53:32 +020018 test_ln_s_add ../a b/a &&
Alexander Gladyshf433f702010-07-09 07:10:52 -060019 git commit -m b &&
20
21 git checkout -b branch &&
22 rm b/a &&
Johannes Sixt622f98e2013-06-07 22:53:32 +020023 git mv a b/a &&
24 test_ln_s_add b/a a &&
Alexander Gladyshf433f702010-07-09 07:10:52 -060025 git commit -m swap &&
26
27 >f1 &&
28 git add f1 &&
29 git commit -m f1
30'
31
Johannes Sixt622f98e2013-06-07 22:53:32 +020032test_expect_success 'Cherry-pick succeeds with rename across D/F conflicts' '
Alexander Gladyshf433f702010-07-09 07:10:52 -060033 git reset --hard &&
Johannes Schindelincbc75a12020-11-18 23:44:26 +000034 git checkout main^0 &&
Alexander Gladyshf433f702010-07-09 07:10:52 -060035 git cherry-pick branch
36'
37
Elijah Newren56bfd762010-09-08 00:40:40 -060038test_expect_success 'Setup rename with file on one side matching directory name on other' '
39 git checkout --orphan nick-testcase &&
40 git rm -rf . &&
41
42 >empty &&
43 git add empty &&
44 git commit -m "Empty file" &&
45
46 git checkout -b simple &&
47 mv empty file &&
48 mkdir empty &&
49 mv file empty &&
50 git add empty/file &&
51 git commit -m "Empty file under empty dir" &&
52
53 echo content >newfile &&
54 git add newfile &&
55 git commit -m "New file"
56'
57
58test_expect_success 'Cherry-pick succeeds with was_a_dir/file -> was_a_dir (resolve)' '
59 git reset --hard &&
60 git checkout -q nick-testcase^0 &&
61 git cherry-pick --strategy=resolve simple
62'
63
Elijah Newren86273e52010-09-08 00:40:41 -060064test_expect_success 'Cherry-pick succeeds with was_a_dir/file -> was_a_dir (recursive)' '
Elijah Newren56bfd762010-09-08 00:40:40 -060065 git reset --hard &&
66 git checkout -q nick-testcase^0 &&
67 git cherry-pick --strategy=recursive simple
68'
69
70test_expect_success 'Setup rename with file on one side matching different dirname on other' '
71 git reset --hard &&
72 git checkout --orphan mergeme &&
73 git rm -rf . &&
74
75 mkdir sub &&
76 mkdir othersub &&
77 echo content > sub/file &&
78 echo foo > othersub/whatever &&
79 git add -A &&
Junio C Hamanoa316b952013-09-04 15:28:45 -070080 git commit -m "Common commit" &&
Elijah Newren56bfd762010-09-08 00:40:40 -060081
82 git rm -rf othersub &&
83 git mv sub/file othersub &&
84 git commit -m "Commit to merge" &&
85
86 git checkout -b newhead mergeme~1 &&
87 >independent-change &&
88 git add independent-change &&
89 git commit -m "Completely unrelated change"
90'
91
92test_expect_success 'Cherry-pick with rename to different D/F conflict succeeds (resolve)' '
93 git reset --hard &&
94 git checkout -q newhead^0 &&
95 git cherry-pick --strategy=resolve mergeme
96'
97
Elijah Newren86273e52010-09-08 00:40:41 -060098test_expect_success 'Cherry-pick with rename to different D/F conflict succeeds (recursive)' '
Elijah Newren56bfd762010-09-08 00:40:40 -060099 git reset --hard &&
100 git checkout -q newhead^0 &&
101 git cherry-pick --strategy=recursive mergeme
102'
103
Alexander Gladyshf433f702010-07-09 07:10:52 -0600104test_done