3 test_description='subtree merge strategy'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success setup '
12 s="1 2 3 4 5 6 7 8" &&
13 for i in $s; do echo $i; done >hello &&
15 git commit -m initial &&
16 git checkout -b side &&
19 git commit -m second &&
21 for i in mundo $s; do echo $i; done >hello &&
27 test_expect_success 'subtree available and works like recursive' '
29 git merge -s subtree side &&
30 for i in mundo $s world; do echo $i; done >expect &&
35 test_expect_success 'setup branch sub' '
36 git checkout --orphan sub &&
41 test_expect_success 'setup topic branch' '
42 git checkout -b topic main &&
43 git merge -s ours --no-commit --allow-unrelated-histories sub &&
44 git read-tree --prefix=dir/ -u sub &&
45 git commit -m "initial merge of sub into topic" &&
46 test_path_is_file dir/foo.t &&
47 test_path_is_file hello
50 test_expect_success 'update branch sub' '
55 test_expect_success 'update topic branch' '
57 git merge -s subtree sub -m "second merge of sub into topic" &&
58 test_path_is_file dir/bar.t &&
59 test_path_is_file dir/foo.t &&
60 test_path_is_file hello
63 test_expect_success 'setup' '
67 echo git-gui > git-gui.sh &&
68 o1=$(git hash-object git-gui.sh) &&
70 git commit -m "initial git-gui" &&
76 o2=$(git hash-object git.c) &&
78 git commit -m "initial git"
81 test_expect_success 'initial merge' '
82 git remote add -f gui ../git-gui &&
83 git merge -s ours --no-commit --allow-unrelated-histories gui/main &&
84 git read-tree --prefix=git-gui/ -u gui/main &&
85 git commit -m "Merge git-gui as our subdirectory" &&
86 git checkout -b work &&
87 git ls-files -s >actual &&
89 echo "100644 $o1 0 git-gui/git-gui.sh" &&
90 echo "100644 $o2 0 git.c"
92 test_cmp expected actual
95 test_expect_success 'merge update' '
97 echo git-gui2 > git-gui.sh &&
98 o3=$(git hash-object git-gui.sh) &&
100 git checkout -b topic_2 &&
101 git commit -m "update git-gui" &&
103 git pull -s subtree gui topic_2 &&
104 git ls-files -s >actual &&
106 echo "100644 $o3 0 git-gui/git-gui.sh" &&
107 echo "100644 $o2 0 git.c"
109 test_cmp expected actual
112 test_expect_success 'initial ambiguous subtree' '
114 git reset --hard main &&
115 git checkout -b topic_2 &&
116 git merge -s ours --no-commit gui/main &&
117 git read-tree --prefix=git-gui2/ -u gui/main &&
118 git commit -m "Merge git-gui2 as our subdirectory" &&
119 git checkout -b work2 &&
120 git ls-files -s >actual &&
122 echo "100644 $o1 0 git-gui/git-gui.sh" &&
123 echo "100644 $o1 0 git-gui2/git-gui.sh" &&
124 echo "100644 $o2 0 git.c"
126 test_cmp expected actual
129 test_expect_success 'merge using explicit' '
131 git reset --hard topic_2 &&
132 git pull -Xsubtree=git-gui gui topic_2 &&
133 git ls-files -s >actual &&
135 echo "100644 $o3 0 git-gui/git-gui.sh" &&
136 echo "100644 $o1 0 git-gui2/git-gui.sh" &&
137 echo "100644 $o2 0 git.c"
139 test_cmp expected actual
142 test_expect_success 'merge2 using explicit' '
144 git reset --hard topic_2 &&
145 git pull -Xsubtree=git-gui2 gui topic_2 &&
146 git ls-files -s >actual &&
148 echo "100644 $o1 0 git-gui/git-gui.sh" &&
149 echo "100644 $o3 0 git-gui2/git-gui.sh" &&
150 echo "100644 $o2 0 git.c"
152 test_cmp expected actual