blob: e9ba6f1690d015d06e13c69db2c1190ef8436443 [file] [log] [blame]
Junio C Hamano17368552008-02-23 11:08:25 -08001#!/bin/sh
2
3test_description='subtree merge strategy'
4
Johannes Schindelin5902f5f2020-11-18 23:44:38 +00005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00006export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
Junio C Hamano17368552008-02-23 11:08:25 -08008. ./test-lib.sh
9
10test_expect_success setup '
11
Jonathan Niedera48fcd82010-10-30 20:46:54 -050012 s="1 2 3 4 5 6 7 8" &&
Eric Sunshine08495412021-12-09 00:11:05 -050013 test_write_lines $s >hello &&
Junio C Hamano17368552008-02-23 11:08:25 -080014 git add hello &&
15 git commit -m initial &&
16 git checkout -b side &&
17 echo >>hello world &&
18 git add hello &&
19 git commit -m second &&
Johannes Schindelin5902f5f2020-11-18 23:44:38 +000020 git checkout main &&
Eric Sunshine08495412021-12-09 00:11:05 -050021 test_write_lines mundo $s >hello &&
Junio C Hamano17368552008-02-23 11:08:25 -080022 git add hello &&
Johannes Schindelin5902f5f2020-11-18 23:44:38 +000023 git commit -m main
Junio C Hamano17368552008-02-23 11:08:25 -080024
25'
26
27test_expect_success 'subtree available and works like recursive' '
28
29 git merge -s subtree side &&
Eric Sunshine08495412021-12-09 00:11:05 -050030 test_write_lines mundo $s world >expect &&
Jeff King82ebb0b2008-03-12 17:36:36 -040031 test_cmp expect hello
Junio C Hamano17368552008-02-23 11:08:25 -080032
33'
34
Jeff King2ec41502018-08-02 14:58:21 -040035test_expect_success 'setup branch sub' '
36 git checkout --orphan sub &&
37 git rm -rf . &&
38 test_commit foo
39'
40
Johannes Schindelin538228e2020-10-08 10:13:47 +000041test_expect_success 'setup topic branch' '
Johannes Schindelin5902f5f2020-11-18 23:44:38 +000042 git checkout -b topic main &&
Jeff King2ec41502018-08-02 14:58:21 -040043 git merge -s ours --no-commit --allow-unrelated-histories sub &&
44 git read-tree --prefix=dir/ -u sub &&
Johannes Schindelin538228e2020-10-08 10:13:47 +000045 git commit -m "initial merge of sub into topic" &&
Jeff King2ec41502018-08-02 14:58:21 -040046 test_path_is_file dir/foo.t &&
47 test_path_is_file hello
48'
49
50test_expect_success 'update branch sub' '
51 git checkout sub &&
52 test_commit bar
53'
54
Johannes Schindelin538228e2020-10-08 10:13:47 +000055test_expect_success 'update topic branch' '
56 git checkout topic &&
57 git merge -s subtree sub -m "second merge of sub into topic" &&
Jeff King2ec41502018-08-02 14:58:21 -040058 test_path_is_file dir/bar.t &&
59 test_path_is_file dir/foo.t &&
60 test_path_is_file hello
61'
62
Miklos Vajna419e3832008-02-28 13:36:54 +010063test_expect_success 'setup' '
64 mkdir git-gui &&
65 cd git-gui &&
66 git init &&
67 echo git-gui > git-gui.sh &&
68 o1=$(git hash-object git-gui.sh) &&
69 git add git-gui.sh &&
70 git commit -m "initial git-gui" &&
71 cd .. &&
72 mkdir git &&
73 cd git &&
74 git init &&
75 echo git >git.c &&
76 o2=$(git hash-object git.c) &&
77 git add git.c &&
78 git commit -m "initial git"
79'
80
81test_expect_success 'initial merge' '
82 git remote add -f gui ../git-gui &&
Johannes Schindelin5902f5f2020-11-18 23:44:38 +000083 git merge -s ours --no-commit --allow-unrelated-histories gui/main &&
84 git read-tree --prefix=git-gui/ -u gui/main &&
Miklos Vajna419e3832008-02-28 13:36:54 +010085 git commit -m "Merge git-gui as our subdirectory" &&
Avery Pennarune3cba962009-11-25 21:23:59 -050086 git checkout -b work &&
Miklos Vajna419e3832008-02-28 13:36:54 +010087 git ls-files -s >actual &&
88 (
Eric Sunshinec8ce3762018-07-01 20:24:02 -040089 echo "100644 $o1 0 git-gui/git-gui.sh" &&
Miklos Vajna419e3832008-02-28 13:36:54 +010090 echo "100644 $o2 0 git.c"
91 ) >expected &&
Junio C Hamano3af82862008-05-23 22:28:56 -070092 test_cmp expected actual
Miklos Vajna419e3832008-02-28 13:36:54 +010093'
94
95test_expect_success 'merge update' '
96 cd ../git-gui &&
97 echo git-gui2 > git-gui.sh &&
98 o3=$(git hash-object git-gui.sh) &&
99 git add git-gui.sh &&
Johannes Schindelinb6211b82020-09-26 21:04:21 +0000100 git checkout -b topic_2 &&
Miklos Vajna419e3832008-02-28 13:36:54 +0100101 git commit -m "update git-gui" &&
102 cd ../git &&
Elijah Newren031e2f72021-07-22 05:04:48 +0000103 git pull --no-rebase -s subtree gui topic_2 &&
Miklos Vajna419e3832008-02-28 13:36:54 +0100104 git ls-files -s >actual &&
105 (
Eric Sunshinec8ce3762018-07-01 20:24:02 -0400106 echo "100644 $o3 0 git-gui/git-gui.sh" &&
Miklos Vajna419e3832008-02-28 13:36:54 +0100107 echo "100644 $o2 0 git.c"
108 ) >expected &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700109 test_cmp expected actual
Miklos Vajna419e3832008-02-28 13:36:54 +0100110'
111
Avery Pennarune3cba962009-11-25 21:23:59 -0500112test_expect_success 'initial ambiguous subtree' '
113 cd ../git &&
Johannes Schindelin5902f5f2020-11-18 23:44:38 +0000114 git reset --hard main &&
Johannes Schindelinb6211b82020-09-26 21:04:21 +0000115 git checkout -b topic_2 &&
Johannes Schindelin5902f5f2020-11-18 23:44:38 +0000116 git merge -s ours --no-commit gui/main &&
117 git read-tree --prefix=git-gui2/ -u gui/main &&
Avery Pennarune3cba962009-11-25 21:23:59 -0500118 git commit -m "Merge git-gui2 as our subdirectory" &&
119 git checkout -b work2 &&
120 git ls-files -s >actual &&
121 (
Eric Sunshinec8ce3762018-07-01 20:24:02 -0400122 echo "100644 $o1 0 git-gui/git-gui.sh" &&
123 echo "100644 $o1 0 git-gui2/git-gui.sh" &&
Avery Pennarune3cba962009-11-25 21:23:59 -0500124 echo "100644 $o2 0 git.c"
125 ) >expected &&
126 test_cmp expected actual
127'
128
129test_expect_success 'merge using explicit' '
130 cd ../git &&
Johannes Schindelinb6211b82020-09-26 21:04:21 +0000131 git reset --hard topic_2 &&
Elijah Newren031e2f72021-07-22 05:04:48 +0000132 git pull --no-rebase -Xsubtree=git-gui gui topic_2 &&
Avery Pennarune3cba962009-11-25 21:23:59 -0500133 git ls-files -s >actual &&
134 (
Eric Sunshinec8ce3762018-07-01 20:24:02 -0400135 echo "100644 $o3 0 git-gui/git-gui.sh" &&
136 echo "100644 $o1 0 git-gui2/git-gui.sh" &&
Avery Pennarune3cba962009-11-25 21:23:59 -0500137 echo "100644 $o2 0 git.c"
138 ) >expected &&
139 test_cmp expected actual
140'
141
142test_expect_success 'merge2 using explicit' '
143 cd ../git &&
Johannes Schindelinb6211b82020-09-26 21:04:21 +0000144 git reset --hard topic_2 &&
Elijah Newren031e2f72021-07-22 05:04:48 +0000145 git pull --no-rebase -Xsubtree=git-gui2 gui topic_2 &&
Avery Pennarune3cba962009-11-25 21:23:59 -0500146 git ls-files -s >actual &&
147 (
Eric Sunshinec8ce3762018-07-01 20:24:02 -0400148 echo "100644 $o1 0 git-gui/git-gui.sh" &&
149 echo "100644 $o3 0 git-gui2/git-gui.sh" &&
Avery Pennarune3cba962009-11-25 21:23:59 -0500150 echo "100644 $o2 0 git.c"
151 ) >expected &&
152 test_cmp expected actual
153'
154
Junio C Hamano17368552008-02-23 11:08:25 -0800155test_done