]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6409-merge-subtree.sh
Merge branch 'jk/rev-list-disk-usage'
[thirdparty/git.git] / t / t6409-merge-subtree.sh
CommitLineData
1736855c
JH
1#!/bin/sh
2
3test_description='subtree merge strategy'
4
5902f5f4 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
1736855c
JH
8. ./test-lib.sh
9
10test_expect_success setup '
11
a48fcd83 12 s="1 2 3 4 5 6 7 8" &&
1736855c
JH
13 for i in $s; do echo $i; done >hello &&
14 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 &&
5902f5f4 20 git checkout main &&
1736855c
JH
21 for i in mundo $s; do echo $i; done >hello &&
22 git add hello &&
5902f5f4 23 git commit -m main
1736855c
JH
24
25'
26
27test_expect_success 'subtree available and works like recursive' '
28
29 git merge -s subtree side &&
30 for i in mundo $s world; do echo $i; done >expect &&
82ebb0b6 31 test_cmp expect hello
1736855c
JH
32
33'
34
2ec41507
JK
35test_expect_success 'setup branch sub' '
36 git checkout --orphan sub &&
37 git rm -rf . &&
38 test_commit foo
39'
40
538228ed 41test_expect_success 'setup topic branch' '
5902f5f4 42 git checkout -b topic main &&
2ec41507
JK
43 git merge -s ours --no-commit --allow-unrelated-histories sub &&
44 git read-tree --prefix=dir/ -u sub &&
538228ed 45 git commit -m "initial merge of sub into topic" &&
2ec41507
JK
46 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
538228ed
JS
55test_expect_success 'update topic branch' '
56 git checkout topic &&
57 git merge -s subtree sub -m "second merge of sub into topic" &&
2ec41507
JK
58 test_path_is_file dir/bar.t &&
59 test_path_is_file dir/foo.t &&
60 test_path_is_file hello
61'
62
419e3833
MV
63test_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 &&
5902f5f4
JS
83 git merge -s ours --no-commit --allow-unrelated-histories gui/main &&
84 git read-tree --prefix=git-gui/ -u gui/main &&
419e3833 85 git commit -m "Merge git-gui as our subdirectory" &&
e3cba962 86 git checkout -b work &&
419e3833
MV
87 git ls-files -s >actual &&
88 (
c8ce3763 89 echo "100644 $o1 0 git-gui/git-gui.sh" &&
419e3833
MV
90 echo "100644 $o2 0 git.c"
91 ) >expected &&
3af82863 92 test_cmp expected actual
419e3833
MV
93'
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 &&
b6211b89 100 git checkout -b topic_2 &&
419e3833
MV
101 git commit -m "update git-gui" &&
102 cd ../git &&
b6211b89 103 git pull -s subtree gui topic_2 &&
419e3833
MV
104 git ls-files -s >actual &&
105 (
c8ce3763 106 echo "100644 $o3 0 git-gui/git-gui.sh" &&
419e3833
MV
107 echo "100644 $o2 0 git.c"
108 ) >expected &&
3af82863 109 test_cmp expected actual
419e3833
MV
110'
111
e3cba962
AP
112test_expect_success 'initial ambiguous subtree' '
113 cd ../git &&
5902f5f4 114 git reset --hard main &&
b6211b89 115 git checkout -b topic_2 &&
5902f5f4
JS
116 git merge -s ours --no-commit gui/main &&
117 git read-tree --prefix=git-gui2/ -u gui/main &&
e3cba962
AP
118 git commit -m "Merge git-gui2 as our subdirectory" &&
119 git checkout -b work2 &&
120 git ls-files -s >actual &&
121 (
c8ce3763
ES
122 echo "100644 $o1 0 git-gui/git-gui.sh" &&
123 echo "100644 $o1 0 git-gui2/git-gui.sh" &&
e3cba962
AP
124 echo "100644 $o2 0 git.c"
125 ) >expected &&
126 test_cmp expected actual
127'
128
129test_expect_success 'merge using explicit' '
130 cd ../git &&
b6211b89
JS
131 git reset --hard topic_2 &&
132 git pull -Xsubtree=git-gui gui topic_2 &&
e3cba962
AP
133 git ls-files -s >actual &&
134 (
c8ce3763
ES
135 echo "100644 $o3 0 git-gui/git-gui.sh" &&
136 echo "100644 $o1 0 git-gui2/git-gui.sh" &&
e3cba962
AP
137 echo "100644 $o2 0 git.c"
138 ) >expected &&
139 test_cmp expected actual
140'
141
142test_expect_success 'merge2 using explicit' '
143 cd ../git &&
b6211b89
JS
144 git reset --hard topic_2 &&
145 git pull -Xsubtree=git-gui2 gui topic_2 &&
e3cba962
AP
146 git ls-files -s >actual &&
147 (
c8ce3763
ES
148 echo "100644 $o1 0 git-gui/git-gui.sh" &&
149 echo "100644 $o3 0 git-gui2/git-gui.sh" &&
e3cba962
AP
150 echo "100644 $o2 0 git.c"
151 ) >expected &&
152 test_cmp expected actual
153'
154
1736855c 155test_done