submodule: Search for merges only at end of recursive merge
The submodule merge search is not useful during virtual merges because the results cannot be used automatically. Furthermore any suggestions made by the search may apply to commits different than HEAD:sub and MERGE_HEAD:sub, thus confusing the user. Skip searching for submodule merges during a virtual merge such as that between B and C while merging the heads of: B---BC / \ / A X \ / \ C---CB Run the search only when the recursion level is zero (!o->call_depth). This fixes known breakage tested in t7405-submodule-merge. Signed-off-by: Brad King <brad.king@kitware.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brad King committed
Oct 13, 2011 at 08:59 UTC
80988783c8c417c5e914256b43ed3604cc8fa4c3
4 files changed
+11
-5
merge-recursive.c
+4
-2
@@ -946,8 +946,10 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
946
free(result_buf.ptr);
947
result.clean = (merge_status == 0);
948
} 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);
953
} else if (S_ISLNK(a->mode)) {
954
hashcpy(result.sha, a->sha1);
955
submodule.c
+5
-1
@@ -794,7 +794,7 @@ static void print_commit(struct commit *commit)
794
795
int merge_submodule(unsigned char result[20], const char *path,
796
const unsigned char base[20], const unsigned char a[20],
797
- const unsigned char b[20])
797
+ const unsigned char b[20], int search)
798
{
799
struct commit *commit_base, *commit_a, *commit_b;
800
int parent_count;
@@ -849,6 +849,10 @@ int merge_submodule(unsigned char result[20], const char *path,
849
* user needs to confirm the resolution.
850
*/
851
852
+ /* Skip the search if makes no sense to the calling context. */
853
+ if (!search)
854
+ return 0;
855
+
856
/* find commit which merges them */
857
parent_count = find_first_merges(&merges, path, commit_a, commit_b);
858
switch (parent_count) {
submodule.h
+1
-1
@@ -28,7 +28,7 @@ int fetch_populated_submodules(int num_options, const char **options,
28
int quiet);
29
unsigned is_submodule_modified(const char *path, int ignore_untracked);
30
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);
32
int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remotes_name);
33
34
#endif
t/t7405-submodule-merge.sh
+1
-1
@@ -269,7 +269,7 @@ test_expect_success 'setup for recursive merge with submodule' '
269
'
270
271
# merge should leave submodule unmerged in index
272
-test_expect_failure 'recursive merge with submodule' '
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 &&