Skip to content

Commit 02377cf

Browse files
committed
Merge branch 'jl/submodule-ignore-diff'
* jl/submodule-ignore-diff: checkout: Use submodule.*.ignore settings from .git/config and .gitmodules checkout: Add test for diff.ignoreSubmodules checkout: respect diff.ignoreSubmodules setting Conflicts: builtin/checkout.c
2 parents a2c6726 + 23b4c7b commit 02377cf

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

Documentation/config.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,8 @@ diff.renames::
829829
diff.ignoreSubmodules::
830830
Sets the default value of --ignore-submodules. Note that this
831831
affects only 'git diff' Porcelain, and not lower level 'diff'
832-
commands such as 'git diff-files'.
832+
commands such as 'git diff-files'. 'git checkout' also honors
833+
this setting when reporting uncommitted changes.
833834

834835
diff.suppressBlankEmpty::
835836
A boolean to inhibit the standard behavior of printing a space

builtin/checkout.c

Lines changed: 17 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>",
@@ -40,6 +41,7 @@ struct checkout_opts {
4041
const char *new_orphan_branch;
4142
int new_branch_log;
4243
enum branch_track track;
44+
struct diff_options diff_options;
4345
};
4446

4547
static int post_checkout_hook(struct commit *old, struct commit *new,
@@ -282,11 +284,12 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
282284
return errs;
283285
}
284286

285-
static void show_local_changes(struct object *head)
287+
static void show_local_changes(struct object *head, struct diff_options *opts)
286288
{
287289
struct rev_info rev;
288290
/* I think we want full paths, even if we're in a subdirectory. */
289291
init_revisions(&rev, NULL);
292+
rev.diffopt.flags = opts->flags;
290293
rev.diffopt.output_format |= DIFF_FORMAT_NAME_STATUS;
291294
if (diff_setup_done(&rev.diffopt) < 0)
292295
die("diff_setup_done failed");
@@ -470,7 +473,7 @@ static int merge_working_tree(struct checkout_opts *opts,
470473
die("unable to write new index file");
471474

472475
if (!opts->force && !opts->quiet)
473-
show_local_changes(&new->commit->object);
476+
show_local_changes(&new->commit->object, &opts->diff_options);
474477

475478
return 0;
476479
}
@@ -618,7 +621,16 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
618621

619622
static int git_checkout_config(const char *var, const char *value, void *cb)
620623
{
621-
return git_xmerge_config(var, value, cb);
624+
if (!strcmp(var, "diff.ignoresubmodules")) {
625+
struct checkout_opts *opts = cb;
626+
handle_ignore_submodules_arg(&opts->diff_options, value);
627+
return 0;
628+
}
629+
630+
if (!prefixcmp(var, "submodule."))
631+
return parse_submodule_config_option(var, value);
632+
633+
return git_xmerge_config(var, value, NULL);
622634
}
623635

624636
static int interactive_checkout(const char *revision, const char **pathspec,
@@ -702,7 +714,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
702714
memset(&opts, 0, sizeof(opts));
703715
memset(&new, 0, sizeof(new));
704716

705-
git_config(git_checkout_config, NULL);
717+
gitmodules_config();
718+
git_config(git_checkout_config, &opts);
706719

707720
opts.track = BRANCH_TRACK_UNSPECIFIED;
708721

t/t2013-checkout-submodule.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,27 @@ test_expect_success '"checkout <submodule>" updates the index only' '
3939
git diff-files --quiet
4040
'
4141

42+
test_expect_success '"checkout <submodule>" honors diff.ignoreSubmodules' '
43+
git config diff.ignoreSubmodules dirty &&
44+
echo x> submodule/untracked &&
45+
git checkout HEAD >actual 2>&1 &&
46+
! test -s actual
47+
'
48+
49+
test_expect_success '"checkout <submodule>" honors submodule.*.ignore from .gitmodules' '
50+
git config diff.ignoreSubmodules none &&
51+
git config -f .gitmodules submodule.submodule.path submodule &&
52+
git config -f .gitmodules submodule.submodule.ignore untracked &&
53+
git checkout HEAD >actual 2>&1 &&
54+
! test -s actual
55+
'
56+
57+
test_expect_success '"checkout <submodule>" honors submodule.*.ignore from .git/config' '
58+
git config -f .gitmodules submodule.submodule.ignore none &&
59+
git config submodule.submodule.path submodule &&
60+
git config submodule.submodule.ignore all &&
61+
git checkout HEAD >actual 2>&1 &&
62+
! test -s actual
63+
'
64+
4265
test_done

0 commit comments

Comments
 (0)