7 #include "run-command.h"
10 #include "string-list.h"
11 #include "sha1-array.h"
12 #include "argv-array.h"
14 static struct string_list config_name_for_path
;
15 static struct string_list config_fetch_recurse_submodules_for_name
;
16 static struct string_list config_ignore_for_name
;
17 static int config_fetch_recurse_submodules
= RECURSE_SUBMODULES_ON_DEMAND
;
18 static struct string_list changed_submodule_paths
;
19 static int initialized_fetch_ref_tips
;
20 static struct sha1_array ref_tips_before_fetch
;
21 static struct sha1_array ref_tips_after_fetch
;
24 * The following flag is set if the .gitmodules file is unmerged. We then
25 * disable recursion for all submodules where .git/config doesn't have a
26 * matching config entry because we can't guess what might be configured in
27 * .gitmodules unless the user resolves the conflict. When a command line
28 * option is given (which always overrides configuration) this flag will be
31 static int gitmodules_is_unmerged
;
33 static int add_submodule_odb(const char *path
)
35 struct strbuf objects_directory
= STRBUF_INIT
;
36 struct alternate_object_database
*alt_odb
;
40 strbuf_addf(&objects_directory
, "%s/.git", path
);
41 git_dir
= read_gitfile_gently(objects_directory
.buf
);
43 strbuf_reset(&objects_directory
);
44 strbuf_addstr(&objects_directory
, git_dir
);
46 strbuf_addstr(&objects_directory
, "/objects/");
47 if (!is_directory(objects_directory
.buf
)) {
51 /* avoid adding it twice */
52 for (alt_odb
= alt_odb_list
; alt_odb
; alt_odb
= alt_odb
->next
)
53 if (alt_odb
->name
- alt_odb
->base
== objects_directory
.len
&&
54 !strncmp(alt_odb
->base
, objects_directory
.buf
,
55 objects_directory
.len
))
58 alt_odb
= xmalloc(objects_directory
.len
+ 42 + sizeof(*alt_odb
));
59 alt_odb
->next
= alt_odb_list
;
60 strcpy(alt_odb
->base
, objects_directory
.buf
);
61 alt_odb
->name
= alt_odb
->base
+ objects_directory
.len
;
62 alt_odb
->name
[2] = '/';
63 alt_odb
->name
[40] = '\0';
64 alt_odb
->name
[41] = '\0';
65 alt_odb_list
= alt_odb
;
68 strbuf_release(&objects_directory
);
72 void set_diffopt_flags_from_submodule_config(struct diff_options
*diffopt
,
75 struct string_list_item
*path_option
, *ignore_option
;
76 path_option
= unsorted_string_list_lookup(&config_name_for_path
, path
);
78 ignore_option
= unsorted_string_list_lookup(&config_ignore_for_name
, path_option
->util
);
80 handle_ignore_submodules_arg(diffopt
, ignore_option
->util
);
81 else if (gitmodules_is_unmerged
)
82 DIFF_OPT_SET(diffopt
, IGNORE_SUBMODULES
);
86 int submodule_config(const char *var
, const char *value
, void *cb
)
88 if (!prefixcmp(var
, "submodule."))
89 return parse_submodule_config_option(var
, value
);
90 else if (!strcmp(var
, "fetch.recursesubmodules")) {
91 config_fetch_recurse_submodules
= parse_fetch_recurse_submodules_arg(var
, value
);
97 void gitmodules_config(void)
99 const char *work_tree
= get_git_work_tree();
101 struct strbuf gitmodules_path
= STRBUF_INIT
;
103 strbuf_addstr(&gitmodules_path
, work_tree
);
104 strbuf_addstr(&gitmodules_path
, "/.gitmodules");
105 if (read_cache() < 0)
106 die("index file corrupt");
107 pos
= cache_name_pos(".gitmodules", 11);
108 if (pos
< 0) { /* .gitmodules not found or isn't merged */
110 if (active_nr
> pos
) { /* there is a .gitmodules */
111 const struct cache_entry
*ce
= active_cache
[pos
];
112 if (ce_namelen(ce
) == 11 &&
113 !memcmp(ce
->name
, ".gitmodules", 11))
114 gitmodules_is_unmerged
= 1;
118 if (!gitmodules_is_unmerged
)
119 git_config_from_file(submodule_config
, gitmodules_path
.buf
, NULL
);
120 strbuf_release(&gitmodules_path
);
124 int parse_submodule_config_option(const char *var
, const char *value
)
127 struct string_list_item
*config
;
128 struct strbuf submodname
= STRBUF_INIT
;
130 var
+= 10; /* Skip "submodule." */
133 if ((len
> 5) && !strcmp(var
+ len
- 5, ".path")) {
134 strbuf_add(&submodname
, var
, len
- 5);
135 config
= unsorted_string_list_lookup(&config_name_for_path
, value
);
139 config
= string_list_append(&config_name_for_path
, xstrdup(value
));
140 config
->util
= strbuf_detach(&submodname
, NULL
);
141 strbuf_release(&submodname
);
142 } else if ((len
> 23) && !strcmp(var
+ len
- 23, ".fetchrecursesubmodules")) {
143 strbuf_add(&submodname
, var
, len
- 23);
144 config
= unsorted_string_list_lookup(&config_fetch_recurse_submodules_for_name
, submodname
.buf
);
146 config
= string_list_append(&config_fetch_recurse_submodules_for_name
,
147 strbuf_detach(&submodname
, NULL
));
148 config
->util
= (void *)(intptr_t)parse_fetch_recurse_submodules_arg(var
, value
);
149 strbuf_release(&submodname
);
150 } else if ((len
> 7) && !strcmp(var
+ len
- 7, ".ignore")) {
151 if (strcmp(value
, "untracked") && strcmp(value
, "dirty") &&
152 strcmp(value
, "all") && strcmp(value
, "none")) {
153 warning("Invalid parameter \"%s\" for config option \"submodule.%s.ignore\"", value
, var
);
157 strbuf_add(&submodname
, var
, len
- 7);
158 config
= unsorted_string_list_lookup(&config_ignore_for_name
, submodname
.buf
);
162 config
= string_list_append(&config_ignore_for_name
,
163 strbuf_detach(&submodname
, NULL
));
164 strbuf_release(&submodname
);
165 config
->util
= xstrdup(value
);
171 void handle_ignore_submodules_arg(struct diff_options
*diffopt
,
174 DIFF_OPT_CLR(diffopt
, IGNORE_SUBMODULES
);
175 DIFF_OPT_CLR(diffopt
, IGNORE_UNTRACKED_IN_SUBMODULES
);
176 DIFF_OPT_CLR(diffopt
, IGNORE_DIRTY_SUBMODULES
);
178 if (!strcmp(arg
, "all"))
179 DIFF_OPT_SET(diffopt
, IGNORE_SUBMODULES
);
180 else if (!strcmp(arg
, "untracked"))
181 DIFF_OPT_SET(diffopt
, IGNORE_UNTRACKED_IN_SUBMODULES
);
182 else if (!strcmp(arg
, "dirty"))
183 DIFF_OPT_SET(diffopt
, IGNORE_DIRTY_SUBMODULES
);
184 else if (strcmp(arg
, "none"))
185 die("bad --ignore-submodules argument: %s", arg
);
188 static int prepare_submodule_summary(struct rev_info
*rev
, const char *path
,
189 struct commit
*left
, struct commit
*right
,
190 int *fast_forward
, int *fast_backward
)
192 struct commit_list
*merge_bases
, *list
;
194 init_revisions(rev
, NULL
);
195 setup_revisions(0, NULL
, rev
, NULL
);
197 rev
->first_parent_only
= 1;
198 left
->object
.flags
|= SYMMETRIC_LEFT
;
199 add_pending_object(rev
, &left
->object
, path
);
200 add_pending_object(rev
, &right
->object
, path
);
201 merge_bases
= get_merge_bases(left
, right
, 1);
203 if (merge_bases
->item
== left
)
205 else if (merge_bases
->item
== right
)
208 for (list
= merge_bases
; list
; list
= list
->next
) {
209 list
->item
->object
.flags
|= UNINTERESTING
;
210 add_pending_object(rev
, &list
->item
->object
,
211 sha1_to_hex(list
->item
->object
.sha1
));
213 return prepare_revision_walk(rev
);
216 static void print_submodule_summary(struct rev_info
*rev
, FILE *f
,
217 const char *del
, const char *add
, const char *reset
)
219 static const char format
[] = " %m %s";
220 struct strbuf sb
= STRBUF_INIT
;
221 struct commit
*commit
;
223 while ((commit
= get_revision(rev
))) {
224 struct pretty_print_context ctx
= {0};
225 ctx
.date_mode
= rev
->date_mode
;
226 strbuf_setlen(&sb
, 0);
227 if (commit
->object
.flags
& SYMMETRIC_LEFT
) {
229 strbuf_addstr(&sb
, del
);
232 strbuf_addstr(&sb
, add
);
233 format_commit_message(commit
, format
, &sb
, &ctx
);
235 strbuf_addstr(&sb
, reset
);
236 strbuf_addch(&sb
, '\n');
237 fprintf(f
, "%s", sb
.buf
);
242 int parse_fetch_recurse_submodules_arg(const char *opt
, const char *arg
)
244 switch (git_config_maybe_bool(opt
, arg
)) {
246 return RECURSE_SUBMODULES_ON
;
248 return RECURSE_SUBMODULES_OFF
;
250 if (!strcmp(arg
, "on-demand"))
251 return RECURSE_SUBMODULES_ON_DEMAND
;
252 die("bad %s argument: %s", opt
, arg
);
256 void show_submodule_summary(FILE *f
, const char *path
,
257 unsigned char one
[20], unsigned char two
[20],
258 unsigned dirty_submodule
,
259 const char *del
, const char *add
, const char *reset
)
262 struct commit
*left
= left
, *right
= right
;
263 const char *message
= NULL
;
264 struct strbuf sb
= STRBUF_INIT
;
265 int fast_forward
= 0, fast_backward
= 0;
267 if (is_null_sha1(two
))
268 message
= "(submodule deleted)";
269 else if (add_submodule_odb(path
))
270 message
= "(not checked out)";
271 else if (is_null_sha1(one
))
272 message
= "(new submodule)";
273 else if (!(left
= lookup_commit_reference(one
)) ||
274 !(right
= lookup_commit_reference(two
)))
275 message
= "(commits not present)";
278 prepare_submodule_summary(&rev
, path
, left
, right
,
279 &fast_forward
, &fast_backward
))
280 message
= "(revision walker failed)";
282 if (dirty_submodule
& DIRTY_SUBMODULE_UNTRACKED
)
283 fprintf(f
, "Submodule %s contains untracked content\n", path
);
284 if (dirty_submodule
& DIRTY_SUBMODULE_MODIFIED
)
285 fprintf(f
, "Submodule %s contains modified content\n", path
);
287 if (!hashcmp(one
, two
)) {
292 strbuf_addf(&sb
, "Submodule %s %s..", path
,
293 find_unique_abbrev(one
, DEFAULT_ABBREV
));
294 if (!fast_backward
&& !fast_forward
)
295 strbuf_addch(&sb
, '.');
296 strbuf_addf(&sb
, "%s", find_unique_abbrev(two
, DEFAULT_ABBREV
));
298 strbuf_addf(&sb
, " %s\n", message
);
300 strbuf_addf(&sb
, "%s:\n", fast_backward
? " (rewind)" : "");
301 fwrite(sb
.buf
, sb
.len
, 1, f
);
304 print_submodule_summary(&rev
, f
, del
, add
, reset
);
305 clear_commit_marks(left
, ~0);
306 clear_commit_marks(right
, ~0);
312 void set_config_fetch_recurse_submodules(int value
)
314 config_fetch_recurse_submodules
= value
;
317 static int is_submodule_commit_present(const char *path
, unsigned char sha1
[20])
320 if (!add_submodule_odb(path
) && lookup_commit_reference(sha1
)) {
321 /* Even if the submodule is checked out and the commit is
322 * present, make sure it is reachable from a ref. */
323 struct child_process cp
;
324 const char *argv
[] = {"rev-list", "-n", "1", NULL
, "--not", "--all", NULL
};
325 struct strbuf buf
= STRBUF_INIT
;
327 argv
[3] = sha1_to_hex(sha1
);
328 memset(&cp
, 0, sizeof(cp
));
330 cp
.env
= local_repo_env
;
335 if (!run_command(&cp
) && !strbuf_read(&buf
, cp
.out
, 1024))
339 strbuf_release(&buf
);
344 static void submodule_collect_changed_cb(struct diff_queue_struct
*q
,
345 struct diff_options
*options
,
349 for (i
= 0; i
< q
->nr
; i
++) {
350 struct diff_filepair
*p
= q
->queue
[i
];
351 if (!S_ISGITLINK(p
->two
->mode
))
354 if (S_ISGITLINK(p
->one
->mode
)) {
355 /* NEEDSWORK: We should honor the name configured in
356 * the .gitmodules file of the commit we are examining
357 * here to be able to correctly follow submodules
358 * being moved around. */
359 struct string_list_item
*path
;
360 path
= unsorted_string_list_lookup(&changed_submodule_paths
, p
->two
->path
);
361 if (!path
&& !is_submodule_commit_present(p
->two
->path
, p
->two
->sha1
))
362 string_list_append(&changed_submodule_paths
, xstrdup(p
->two
->path
));
364 /* Submodule is new or was moved here */
365 /* NEEDSWORK: When the .git directories of submodules
366 * live inside the superprojects .git directory some
367 * day we should fetch new submodules directly into
368 * that location too when config or options request
369 * that so they can be checked out from there. */
375 static int add_sha1_to_array(const char *ref
, const unsigned char *sha1
,
376 int flags
, void *data
)
378 sha1_array_append(data
, sha1
);
382 void check_for_new_submodule_commits(unsigned char new_sha1
[20])
384 if (!initialized_fetch_ref_tips
) {
385 for_each_ref(add_sha1_to_array
, &ref_tips_before_fetch
);
386 initialized_fetch_ref_tips
= 1;
389 sha1_array_append(&ref_tips_after_fetch
, new_sha1
);
392 static void add_sha1_to_argv(const unsigned char sha1
[20], void *data
)
394 argv_array_push(data
, sha1_to_hex(sha1
));
397 static void calculate_changed_submodule_paths(void)
400 struct commit
*commit
;
401 struct argv_array argv
= ARGV_ARRAY_INIT
;
403 init_revisions(&rev
, NULL
);
404 argv_array_push(&argv
, "--"); /* argv[0] program name */
405 sha1_array_for_each_unique(&ref_tips_after_fetch
,
406 add_sha1_to_argv
, &argv
);
407 argv_array_push(&argv
, "--not");
408 sha1_array_for_each_unique(&ref_tips_before_fetch
,
409 add_sha1_to_argv
, &argv
);
410 setup_revisions(argv
.argc
, argv
.argv
, &rev
, NULL
);
411 if (prepare_revision_walk(&rev
))
412 die("revision walk setup failed");
415 * Collect all submodules (whether checked out or not) for which new
416 * commits have been recorded upstream in "changed_submodule_paths".
418 while ((commit
= get_revision(&rev
))) {
419 struct commit_list
*parent
= commit
->parents
;
421 struct diff_options diff_opts
;
422 diff_setup(&diff_opts
);
423 diff_opts
.output_format
|= DIFF_FORMAT_CALLBACK
;
424 diff_opts
.format_callback
= submodule_collect_changed_cb
;
425 if (diff_setup_done(&diff_opts
) < 0)
426 die("diff_setup_done failed");
427 diff_tree_sha1(parent
->item
->object
.sha1
, commit
->object
.sha1
, "", &diff_opts
);
428 diffcore_std(&diff_opts
);
429 diff_flush(&diff_opts
);
430 parent
= parent
->next
;
434 argv_array_clear(&argv
);
435 sha1_array_clear(&ref_tips_before_fetch
);
436 sha1_array_clear(&ref_tips_after_fetch
);
437 initialized_fetch_ref_tips
= 0;
440 int fetch_populated_submodules(int num_options
, const char **options
,
441 const char *prefix
, int command_line_option
,
444 int i
, result
= 0, argc
= 0, default_argc
;
445 struct child_process cp
;
447 struct string_list_item
*name_for_path
;
448 const char *work_tree
= get_git_work_tree();
452 if (!the_index
.initialized
)
453 if (read_cache() < 0)
454 die("index file corrupt");
456 /* 6: "fetch" (options) --recurse-submodules-default default "--submodule-prefix" prefix NULL */
457 argv
= xcalloc(num_options
+ 6, sizeof(const char *));
458 argv
[argc
++] = "fetch";
459 for (i
= 0; i
< num_options
; i
++)
460 argv
[argc
++] = options
[i
];
461 argv
[argc
++] = "--recurse-submodules-default";
462 default_argc
= argc
++;
463 argv
[argc
++] = "--submodule-prefix";
465 memset(&cp
, 0, sizeof(cp
));
467 cp
.env
= local_repo_env
;
471 calculate_changed_submodule_paths();
473 for (i
= 0; i
< active_nr
; i
++) {
474 struct strbuf submodule_path
= STRBUF_INIT
;
475 struct strbuf submodule_git_dir
= STRBUF_INIT
;
476 struct strbuf submodule_prefix
= STRBUF_INIT
;
477 struct cache_entry
*ce
= active_cache
[i
];
478 const char *git_dir
, *name
, *default_argv
;
480 if (!S_ISGITLINK(ce
->ce_mode
))
484 name_for_path
= unsorted_string_list_lookup(&config_name_for_path
, ce
->name
);
486 name
= name_for_path
->util
;
488 default_argv
= "yes";
489 if (command_line_option
== RECURSE_SUBMODULES_DEFAULT
) {
490 struct string_list_item
*fetch_recurse_submodules_option
;
491 fetch_recurse_submodules_option
= unsorted_string_list_lookup(&config_fetch_recurse_submodules_for_name
, name
);
492 if (fetch_recurse_submodules_option
) {
493 if ((intptr_t)fetch_recurse_submodules_option
->util
== RECURSE_SUBMODULES_OFF
)
495 if ((intptr_t)fetch_recurse_submodules_option
->util
== RECURSE_SUBMODULES_ON_DEMAND
) {
496 if (!unsorted_string_list_lookup(&changed_submodule_paths
, ce
->name
))
498 default_argv
= "on-demand";
501 if ((config_fetch_recurse_submodules
== RECURSE_SUBMODULES_OFF
) ||
502 gitmodules_is_unmerged
)
504 if (config_fetch_recurse_submodules
== RECURSE_SUBMODULES_ON_DEMAND
) {
505 if (!unsorted_string_list_lookup(&changed_submodule_paths
, ce
->name
))
507 default_argv
= "on-demand";
510 } else if (command_line_option
== RECURSE_SUBMODULES_ON_DEMAND
) {
511 if (!unsorted_string_list_lookup(&changed_submodule_paths
, ce
->name
))
513 default_argv
= "on-demand";
516 strbuf_addf(&submodule_path
, "%s/%s", work_tree
, ce
->name
);
517 strbuf_addf(&submodule_git_dir
, "%s/.git", submodule_path
.buf
);
518 strbuf_addf(&submodule_prefix
, "%s%s/", prefix
, ce
->name
);
519 git_dir
= read_gitfile_gently(submodule_git_dir
.buf
);
521 git_dir
= submodule_git_dir
.buf
;
522 if (is_directory(git_dir
)) {
524 printf("Fetching submodule %s%s\n", prefix
, ce
->name
);
525 cp
.dir
= submodule_path
.buf
;
526 argv
[default_argc
] = default_argv
;
527 argv
[argc
] = submodule_prefix
.buf
;
528 if (run_command(&cp
))
531 strbuf_release(&submodule_path
);
532 strbuf_release(&submodule_git_dir
);
533 strbuf_release(&submodule_prefix
);
537 string_list_clear(&changed_submodule_paths
, 1);
541 unsigned is_submodule_modified(const char *path
, int ignore_untracked
)
544 struct child_process cp
;
545 const char *argv
[] = {
551 struct strbuf buf
= STRBUF_INIT
;
552 unsigned dirty_submodule
= 0;
553 const char *line
, *next_line
;
556 strbuf_addf(&buf
, "%s/.git", path
);
557 git_dir
= read_gitfile_gently(buf
.buf
);
560 if (!is_directory(git_dir
)) {
561 strbuf_release(&buf
);
562 /* The submodule is not checked out, so it is not modified */
568 if (ignore_untracked
)
571 memset(&cp
, 0, sizeof(cp
));
573 cp
.env
= local_repo_env
;
578 if (start_command(&cp
))
579 die("Could not run git status --porcelain");
581 len
= strbuf_read(&buf
, cp
.out
, 1024);
584 if ((line
[0] == '?') && (line
[1] == '?')) {
585 dirty_submodule
|= DIRTY_SUBMODULE_UNTRACKED
;
586 if (dirty_submodule
& DIRTY_SUBMODULE_MODIFIED
)
589 dirty_submodule
|= DIRTY_SUBMODULE_MODIFIED
;
590 if (ignore_untracked
||
591 (dirty_submodule
& DIRTY_SUBMODULE_UNTRACKED
))
594 next_line
= strchr(line
, '\n');
598 len
-= (next_line
- line
);
603 if (finish_command(&cp
))
604 die("git status --porcelain failed");
606 strbuf_release(&buf
);
607 return dirty_submodule
;
610 static int find_first_merges(struct object_array
*result
, const char *path
,
611 struct commit
*a
, struct commit
*b
)
614 struct object_array merges
;
615 struct commit
*commit
;
616 int contains_another
;
618 char merged_revision
[42];
619 const char *rev_args
[] = { "rev-list", "--merges", "--ancestry-path",
620 "--all", merged_revision
, NULL
};
621 struct rev_info revs
;
622 struct setup_revision_opt rev_opts
;
624 memset(&merges
, 0, sizeof(merges
));
625 memset(result
, 0, sizeof(struct object_array
));
626 memset(&rev_opts
, 0, sizeof(rev_opts
));
628 /* get all revisions that merge commit a */
629 snprintf(merged_revision
, sizeof(merged_revision
), "^%s",
630 sha1_to_hex(a
->object
.sha1
));
631 init_revisions(&revs
, NULL
);
632 rev_opts
.submodule
= path
;
633 setup_revisions(sizeof(rev_args
)/sizeof(char *)-1, rev_args
, &revs
, &rev_opts
);
635 /* save all revisions from the above list that contain b */
636 if (prepare_revision_walk(&revs
))
637 die("revision walk setup failed");
638 while ((commit
= get_revision(&revs
)) != NULL
) {
639 struct object
*o
= &(commit
->object
);
640 if (in_merge_bases(b
, &commit
, 1))
641 add_object_array(o
, NULL
, &merges
);
644 /* Now we've got all merges that contain a and b. Prune all
645 * merges that contain another found merge and save them in
648 for (i
= 0; i
< merges
.nr
; i
++) {
649 struct commit
*m1
= (struct commit
*) merges
.objects
[i
].item
;
651 contains_another
= 0;
652 for (j
= 0; j
< merges
.nr
; j
++) {
653 struct commit
*m2
= (struct commit
*) merges
.objects
[j
].item
;
654 if (i
!= j
&& in_merge_bases(m2
, &m1
, 1)) {
655 contains_another
= 1;
660 if (!contains_another
)
661 add_object_array(merges
.objects
[i
].item
,
662 merges
.objects
[i
].name
, result
);
665 free(merges
.objects
);
669 static void print_commit(struct commit
*commit
)
671 struct strbuf sb
= STRBUF_INIT
;
672 struct pretty_print_context ctx
= {0};
673 ctx
.date_mode
= DATE_NORMAL
;
674 format_commit_message(commit
, " %h: %m %s", &sb
, &ctx
);
675 fprintf(stderr
, "%s\n", sb
.buf
);
679 #define MERGE_WARNING(path, msg) \
680 warning("Failed to merge submodule %s (%s)", path, msg);
682 int merge_submodule(unsigned char result
[20], const char *path
,
683 const unsigned char base
[20], const unsigned char a
[20],
684 const unsigned char b
[20])
686 struct commit
*commit_base
, *commit_a
, *commit_b
;
688 struct object_array merges
;
692 /* store a in result in case we fail */
695 /* we can not handle deletion conflicts */
696 if (is_null_sha1(base
))
703 if (add_submodule_odb(path
)) {
704 MERGE_WARNING(path
, "not checked out");
708 if (!(commit_base
= lookup_commit_reference(base
)) ||
709 !(commit_a
= lookup_commit_reference(a
)) ||
710 !(commit_b
= lookup_commit_reference(b
))) {
711 MERGE_WARNING(path
, "commits not present");
715 /* check whether both changes are forward */
716 if (!in_merge_bases(commit_base
, &commit_a
, 1) ||
717 !in_merge_bases(commit_base
, &commit_b
, 1)) {
718 MERGE_WARNING(path
, "commits don't follow merge-base");
722 /* Case #1: a is contained in b or vice versa */
723 if (in_merge_bases(commit_a
, &commit_b
, 1)) {
727 if (in_merge_bases(commit_b
, &commit_a
, 1)) {
733 * Case #2: There are one or more merges that contain a and b in
734 * the submodule. If there is only one, then present it as a
735 * suggestion to the user, but leave it marked unmerged so the
736 * user needs to confirm the resolution.
739 /* find commit which merges them */
740 parent_count
= find_first_merges(&merges
, path
, commit_a
, commit_b
);
741 switch (parent_count
) {
743 MERGE_WARNING(path
, "merge following commits not found");
747 MERGE_WARNING(path
, "not fast-forward");
748 fprintf(stderr
, "Found a possible merge resolution "
749 "for the submodule:\n");
750 print_commit((struct commit
*) merges
.objects
[0].item
);
752 "If this is correct simply add it to the index "
755 " git update-index --cacheinfo 160000 %s \"%s\"\n\n"
756 "which will accept this suggestion.\n",
757 sha1_to_hex(merges
.objects
[0].item
->sha1
), path
);
761 MERGE_WARNING(path
, "multiple merges found");
762 for (i
= 0; i
< merges
.nr
; i
++)
763 print_commit((struct commit
*) merges
.objects
[i
].item
);
766 free(merges
.objects
);