The eleventh batch
[alt-git.git] / t / t6409-merge-subtree.sh
blob528615b981f899f1b02c3ab96bc6c794724700be
1 #!/bin/sh
3 test_description='subtree merge strategy'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success setup '
13 s="1 2 3 4 5 6 7 8" &&
14 test_write_lines $s >hello &&
15 git add hello &&
16 git commit -m initial &&
17 git checkout -b side &&
18 echo >>hello world &&
19 git add hello &&
20 git commit -m second &&
21 git checkout main &&
22 test_write_lines mundo $s >hello &&
23 git add hello &&
24 git commit -m main
28 test_expect_success 'subtree available and works like recursive' '
30 git merge -s subtree side &&
31 test_write_lines mundo $s world >expect &&
32 test_cmp expect hello
36 test_expect_success 'setup branch sub' '
37 git checkout --orphan sub &&
38 git rm -rf . &&
39 test_commit foo
42 test_expect_success 'setup topic branch' '
43 git checkout -b topic main &&
44 git merge -s ours --no-commit --allow-unrelated-histories sub &&
45 git read-tree --prefix=dir/ -u sub &&
46 git commit -m "initial merge of sub into topic" &&
47 test_path_is_file dir/foo.t &&
48 test_path_is_file hello
51 test_expect_success 'update branch sub' '
52 git checkout sub &&
53 test_commit bar
56 test_expect_success 'update topic branch' '
57 git checkout topic &&
58 git merge -s subtree sub -m "second merge of sub into topic" &&
59 test_path_is_file dir/bar.t &&
60 test_path_is_file dir/foo.t &&
61 test_path_is_file hello
64 test_expect_success 'setup' '
65 mkdir git-gui &&
66 cd git-gui &&
67 git init &&
68 echo git-gui > git-gui.sh &&
69 o1=$(git hash-object git-gui.sh) &&
70 git add git-gui.sh &&
71 git commit -m "initial git-gui" &&
72 cd .. &&
73 mkdir git &&
74 cd git &&
75 git init &&
76 echo git >git.c &&
77 o2=$(git hash-object git.c) &&
78 git add git.c &&
79 git commit -m "initial git"
82 test_expect_success 'initial merge' '
83 git remote add -f gui ../git-gui &&
84 git merge -s ours --no-commit --allow-unrelated-histories gui/main &&
85 git read-tree --prefix=git-gui/ -u gui/main &&
86 git commit -m "Merge git-gui as our subdirectory" &&
87 git checkout -b work &&
88 git ls-files -s >actual &&
90 echo "100644 $o1 0 git-gui/git-gui.sh" &&
91 echo "100644 $o2 0 git.c"
92 ) >expected &&
93 test_cmp expected actual
96 test_expect_success 'merge update' '
97 cd ../git-gui &&
98 echo git-gui2 > git-gui.sh &&
99 o3=$(git hash-object git-gui.sh) &&
100 git add git-gui.sh &&
101 git checkout -b topic_2 &&
102 git commit -m "update git-gui" &&
103 cd ../git &&
104 git pull --no-rebase -s subtree gui topic_2 &&
105 git ls-files -s >actual &&
107 echo "100644 $o3 0 git-gui/git-gui.sh" &&
108 echo "100644 $o2 0 git.c"
109 ) >expected &&
110 test_cmp expected actual
113 test_expect_success 'initial ambiguous subtree' '
114 cd ../git &&
115 git reset --hard main &&
116 git checkout -b topic_2 &&
117 git merge -s ours --no-commit gui/main &&
118 git read-tree --prefix=git-gui2/ -u gui/main &&
119 git commit -m "Merge git-gui2 as our subdirectory" &&
120 git checkout -b work2 &&
121 git ls-files -s >actual &&
123 echo "100644 $o1 0 git-gui/git-gui.sh" &&
124 echo "100644 $o1 0 git-gui2/git-gui.sh" &&
125 echo "100644 $o2 0 git.c"
126 ) >expected &&
127 test_cmp expected actual
130 test_expect_success 'merge using explicit' '
131 cd ../git &&
132 git reset --hard topic_2 &&
133 git pull --no-rebase -Xsubtree=git-gui gui topic_2 &&
134 git ls-files -s >actual &&
136 echo "100644 $o3 0 git-gui/git-gui.sh" &&
137 echo "100644 $o1 0 git-gui2/git-gui.sh" &&
138 echo "100644 $o2 0 git.c"
139 ) >expected &&
140 test_cmp expected actual
143 test_expect_success 'merge2 using explicit' '
144 cd ../git &&
145 git reset --hard topic_2 &&
146 git pull --no-rebase -Xsubtree=git-gui2 gui topic_2 &&
147 git ls-files -s >actual &&
149 echo "100644 $o1 0 git-gui/git-gui.sh" &&
150 echo "100644 $o3 0 git-gui2/git-gui.sh" &&
151 echo "100644 $o2 0 git.c"
152 ) >expected &&
153 test_cmp expected actual
156 test_done