Skip to content

Commit

Permalink
submodule: Search for merges only at end of recursive merge
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Brad King authored and Junio C Hamano committed Oct 13, 2011
1 parent 72251b7 commit 8098878
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions merge-recursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,10 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
free(result_buf.ptr);
result.clean = (merge_status == 0);
} else if (S_ISGITLINK(a->mode)) {
result.clean = merge_submodule(result.sha, one->path, one->sha1,
a->sha1, b->sha1);
result.clean = merge_submodule(result.sha,
one->path, one->sha1,
a->sha1, b->sha1,
!o->call_depth);
} else if (S_ISLNK(a->mode)) {
hashcpy(result.sha, a->sha1);

Expand Down
6 changes: 5 additions & 1 deletion submodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ static void print_commit(struct commit *commit)

int merge_submodule(unsigned char result[20], const char *path,
const unsigned char base[20], const unsigned char a[20],
const unsigned char b[20])
const unsigned char b[20], int search)
{
struct commit *commit_base, *commit_a, *commit_b;
int parent_count;
Expand Down Expand Up @@ -849,6 +849,10 @@ int merge_submodule(unsigned char result[20], const char *path,
* user needs to confirm the resolution.
*/

/* Skip the search if makes no sense to the calling context. */
if (!search)
return 0;

/* find commit which merges them */
parent_count = find_first_merges(&merges, path, commit_a, commit_b);
switch (parent_count) {
Expand Down
2 changes: 1 addition & 1 deletion submodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int fetch_populated_submodules(int num_options, const char **options,
int quiet);
unsigned is_submodule_modified(const char *path, int ignore_untracked);
int merge_submodule(unsigned char result[20], const char *path, const unsigned char base[20],
const unsigned char a[20], const unsigned char b[20]);
const unsigned char a[20], const unsigned char b[20], int search);
int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remotes_name);

#endif
2 changes: 1 addition & 1 deletion t/t7405-submodule-merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ test_expect_success 'setup for recursive merge with submodule' '
'

# merge should leave submodule unmerged in index
test_expect_failure 'recursive merge with submodule' '
test_expect_success 'recursive merge with submodule' '
(cd merge-recursive &&
test_must_fail git merge top-bc &&
echo "160000 $(git rev-parse top-cb:sub) 2 sub" > expect2 &&
Expand Down

0 comments on commit 8098878

Please sign in to comment.