Skip to content

Commit 175f6e5

Browse files
dschogitster
authored andcommitted
checkout: respect diff.ignoreSubmodules setting
When 'git checkout' reports uncommitted changes, it also does so for submodules. The default mode is now to look really hard into submodules, not only for different commits, but also for modified files. Since this can be pretty expensive when there are a lot (and large) submodules, there is the diff.ignoreSubmodules option. Let's respect that setting when 'git checkout' reports the uncommitted changes, since it does nothing else than a 'git diff --name-status'. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 90e1452 commit 175f6e5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

builtin/checkout.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "xdiff-interface.h"
1919
#include "ll-merge.h"
2020
#include "resolve-undo.h"
21+
#include "submodule.h"
2122

2223
static const char * const checkout_usage[] = {
2324
"git checkout [options] <branch>",
@@ -36,6 +37,7 @@ struct checkout_opts {
3637
const char *new_orphan_branch;
3738
int new_branch_log;
3839
enum branch_track track;
40+
struct diff_options diff_options;
3941
};
4042

4143
static int post_checkout_hook(struct commit *old, struct commit *new,
@@ -274,12 +276,13 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
274276
return errs;
275277
}
276278

277-
static void show_local_changes(struct object *head)
279+
static void show_local_changes(struct object *head, struct diff_options *opts)
278280
{
279281
struct rev_info rev;
280282
/* I think we want full paths, even if we're in a subdirectory. */
281283
init_revisions(&rev, NULL);
282284
rev.abbrev = 0;
285+
rev.diffopt.flags = opts->flags;
283286
rev.diffopt.output_format |= DIFF_FORMAT_NAME_STATUS;
284287
if (diff_setup_done(&rev.diffopt) < 0)
285288
die("diff_setup_done failed");
@@ -456,7 +459,7 @@ static int merge_working_tree(struct checkout_opts *opts,
456459
die("unable to write new index file");
457460

458461
if (!opts->force && !opts->quiet)
459-
show_local_changes(&new->commit->object);
462+
show_local_changes(&new->commit->object, &opts->diff_options);
460463

461464
return 0;
462465
}
@@ -600,7 +603,12 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
600603

601604
static int git_checkout_config(const char *var, const char *value, void *cb)
602605
{
603-
return git_xmerge_config(var, value, cb);
606+
if (!strcmp(var, "diff.ignoresubmodules")) {
607+
struct checkout_opts *opts = cb;
608+
handle_ignore_submodules_arg(&opts->diff_options, value);
609+
return 0;
610+
}
611+
return git_xmerge_config(var, value, NULL);
604612
}
605613

606614
static int interactive_checkout(const char *revision, const char **pathspec,
@@ -681,7 +689,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
681689
memset(&opts, 0, sizeof(opts));
682690
memset(&new, 0, sizeof(new));
683691

684-
git_config(git_checkout_config, NULL);
692+
git_config(git_checkout_config, &opts);
685693

686694
opts.track = BRANCH_TRACK_UNSPECIFIED;
687695

0 commit comments

Comments
 (0)