Skip to content

Commit 2201cc8

Browse files
committed
Merge branch 'bk/submodule-in-recursive-merge'
* bk/submodule-in-recursive-merge: submodule: Search for merges only at end of recursive merge submodule: Demonstrate known breakage during recursive merge
2 parents c31b87d + 8098878 commit 2201cc8

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

merge-recursive.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,10 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
946946
free(result_buf.ptr);
947947
result.clean = (merge_status == 0);
948948
} else if (S_ISGITLINK(a->mode)) {
949-
result.clean = merge_submodule(result.sha, one->path, one->sha1,
950-
a->sha1, b->sha1);
949+
result.clean = merge_submodule(result.sha,
950+
one->path, one->sha1,
951+
a->sha1, b->sha1,
952+
!o->call_depth);
951953
} else if (S_ISLNK(a->mode)) {
952954
hashcpy(result.sha, a->sha1);
953955

submodule.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ static void print_commit(struct commit *commit)
794794

795795
int merge_submodule(unsigned char result[20], const char *path,
796796
const unsigned char base[20], const unsigned char a[20],
797-
const unsigned char b[20])
797+
const unsigned char b[20], int search)
798798
{
799799
struct commit *commit_base, *commit_a, *commit_b;
800800
int parent_count;
@@ -849,6 +849,10 @@ int merge_submodule(unsigned char result[20], const char *path,
849849
* user needs to confirm the resolution.
850850
*/
851851

852+
/* Skip the search if makes no sense to the calling context. */
853+
if (!search)
854+
return 0;
855+
852856
/* find commit which merges them */
853857
parent_count = find_first_merges(&merges, path, commit_a, commit_b);
854858
switch (parent_count) {

submodule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int fetch_populated_submodules(int num_options, const char **options,
2828
int quiet);
2929
unsigned is_submodule_modified(const char *path, int ignore_untracked);
3030
int merge_submodule(unsigned char result[20], const char *path, const unsigned char base[20],
31-
const unsigned char a[20], const unsigned char b[20]);
31+
const unsigned char a[20], const unsigned char b[20], int search);
3232
int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remotes_name);
3333

3434
#endif

t/t7405-submodule-merge.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,55 @@ test_expect_success 'merging with a modify/modify conflict between merge bases'
228228
git merge d
229229
'
230230

231+
# canonical criss-cross history in top and submodule
232+
test_expect_success 'setup for recursive merge with submodule' '
233+
mkdir merge-recursive &&
234+
(cd merge-recursive &&
235+
git init &&
236+
mkdir sub &&
237+
(cd sub &&
238+
git init &&
239+
test_commit a &&
240+
git checkout -b sub-b master &&
241+
test_commit b &&
242+
git checkout -b sub-c master &&
243+
test_commit c &&
244+
git checkout -b sub-bc sub-b &&
245+
git merge sub-c &&
246+
git checkout -b sub-cb sub-c &&
247+
git merge sub-b &&
248+
git checkout master) &&
249+
git add sub &&
250+
git commit -m a &&
251+
git checkout -b top-b master &&
252+
(cd sub && git checkout sub-b) &&
253+
git add sub &&
254+
git commit -m b &&
255+
git checkout -b top-c master &&
256+
(cd sub && git checkout sub-c) &&
257+
git add sub &&
258+
git commit -m c &&
259+
git checkout -b top-bc top-b &&
260+
git merge -s ours --no-commit top-c &&
261+
(cd sub && git checkout sub-bc) &&
262+
git add sub &&
263+
git commit -m bc &&
264+
git checkout -b top-cb top-c &&
265+
git merge -s ours --no-commit top-b &&
266+
(cd sub && git checkout sub-cb) &&
267+
git add sub &&
268+
git commit -m cb)
269+
'
270+
271+
# merge should leave submodule unmerged in index
272+
test_expect_success 'recursive merge with submodule' '
273+
(cd merge-recursive &&
274+
test_must_fail git merge top-bc &&
275+
echo "160000 $(git rev-parse top-cb:sub) 2 sub" > expect2 &&
276+
echo "160000 $(git rev-parse top-bc:sub) 3 sub" > expect3 &&
277+
git ls-files -u > actual &&
278+
grep "$(cat expect2)" actual > /dev/null &&
279+
grep "$(cat expect3)" actual > /dev/null)
280+
'
281+
231282
test_done

0 commit comments

Comments
 (0)