Skip to content

Commit cc34bb0

Browse files
committed
Merge branch 'jl/submodule-ignore-diff'
* jl/submodule-ignore-diff: Add tests for the diff.ignoreSubmodules config option Add the 'diff.ignoreSubmodules' config setting Submodules: Use "ignore" settings from .gitmodules too for diff and status Submodules: Add the new "ignore" config option for diff and status Conflicts: diff.c
2 parents 06d11b2 + 90e1452 commit cc34bb0

17 files changed

+526
-21
lines changed

Documentation/config.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,11 @@ diff.renames::
826826
will enable basic rename detection. If set to "copies" or
827827
"copy", it will detect copies, as well.
828828

829+
diff.ignoreSubmodules::
830+
Sets the default value of --ignore-submodules. Note that this
831+
affects only 'git diff' Porcelain, and not lower level 'diff'
832+
commands such as 'git diff-files'.
833+
829834
diff.suppressBlankEmpty::
830835
A boolean to inhibit the standard behavior of printing a space
831836
before each empty output line. Defaults to false.
@@ -1749,6 +1754,19 @@ submodule.<name>.update::
17491754
URL and other values found in the `.gitmodules` file. See
17501755
linkgit:git-submodule[1] and linkgit:gitmodules[5] for details.
17511756

1757+
submodule.<name>.ignore::
1758+
Defines under what circumstances "git status" and the diff family show
1759+
a submodule as modified. When set to "all", it will never be considered
1760+
modified, "dirty" will ignore all changes to the submodules work tree and
1761+
takes only differences between the HEAD of the submodule and the commit
1762+
recorded in the superproject into account. "untracked" will additionally
1763+
let submodules with modified tracked files in their work tree show up.
1764+
Using "none" (the default when this option is not set) also shows
1765+
submodules that have untracked files in their work tree as changed.
1766+
This setting overrides any setting made in .gitmodules for this submodule,
1767+
both settings can be overriden on the command line by using the
1768+
"--ignore-submodules" option.
1769+
17521770
tar.umask::
17531771
This variable can be used to restrict the permission bits of
17541772
tar archive entries. The default is 0002, which turns off the

Documentation/diff-options.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,11 @@ endif::git-format-patch[]
355355

356356
--ignore-submodules[=<when>]::
357357
Ignore changes to submodules in the diff generation. <when> can be
358-
either "untracked", "dirty" or "all", which is the default. When
358+
either "none", "untracked", "dirty" or "all", which is the default
359+
Using "none" will consider the submodule modified when it either contains
360+
untracked or modified files or its HEAD differs from the commit recorded
361+
in the superproject and can be used to override any settings of the
362+
'ignore' option in linkgit:git-config[1] or linkgit:gitmodules[5]. When
359363
"untracked" is used submodules are not considered dirty when they only
360364
contain untracked content (but they are still scanned for modified
361365
content). Using "dirty" ignores all changes to the work tree of submodules,

Documentation/git-status.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ specified.
5555

5656
--ignore-submodules[=<when>]::
5757
Ignore changes to submodules when looking for changes. <when> can be
58-
either "untracked", "dirty" or "all", which is the default. When
58+
either "none", "untracked", "dirty" or "all", which is the default.
59+
Using "none" will consider the submodule modified when it either contains
60+
untracked or modified files or its HEAD differs from the commit recorded
61+
in the superproject and can be used to override any settings of the
62+
'ignore' option in linkgit:git-config[1] or linkgit:gitmodules[5]. When
5963
"untracked" is used submodules are not considered dirty when they only
6064
contain untracked content (but they are still scanned for modified
6165
content). Using "dirty" ignores all changes to the work tree of submodules,

Documentation/gitmodules.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ submodule.<name>.update::
4444
This config option is overridden if 'git submodule update' is given
4545
the '--merge' or '--rebase' options.
4646

47+
submodule.<name>.ignore::
48+
Defines under what circumstances "git status" and the diff family show
49+
a submodule as modified. When set to "all", it will never be considered
50+
modified, "dirty" will ignore all changes to the submodules work tree and
51+
takes only differences between the HEAD of the submodule and the commit
52+
recorded in the superproject into account. "untracked" will additionally
53+
let submodules with modified tracked files in their work tree show up.
54+
Using "none" (the default when this option is not set) also shows
55+
submodules that have untracked files in their work tree as changed.
56+
If this option is also present in the submodules entry in .git/config of
57+
the superproject, the setting there will override the one found in
58+
.gitmodules.
59+
Both settings can be overriden on the command line by using the
60+
"--ignore-submodule" option.
61+
4762

4863
EXAMPLES
4964
--------

builtin/commit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "rerere.h"
2626
#include "unpack-trees.h"
2727
#include "quote.h"
28+
#include "submodule.h"
2829

2930
static const char * const builtin_commit_usage[] = {
3031
"git commit [options] [--] <filepattern>...",
@@ -1073,6 +1074,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
10731074
status_format = STATUS_FORMAT_PORCELAIN;
10741075

10751076
wt_status_prepare(&s);
1077+
gitmodules_config();
10761078
git_config(git_status_config, &s);
10771079
in_merge = file_exists(git_path("MERGE_HEAD"));
10781080
argc = parse_options(argc, argv, prefix,

builtin/diff-files.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "commit.h"
99
#include "revision.h"
1010
#include "builtin.h"
11+
#include "submodule.h"
1112

1213
static const char diff_files_usage[] =
1314
"git diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]"
@@ -20,6 +21,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
2021
unsigned options = 0;
2122

2223
init_revisions(&rev, prefix);
24+
gitmodules_config();
2325
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2426
rev.abbrev = 0;
2527

builtin/diff-index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "commit.h"
44
#include "revision.h"
55
#include "builtin.h"
6+
#include "submodule.h"
67

78
static const char diff_cache_usage[] =
89
"git diff-index [-m] [--cached] "
@@ -17,6 +18,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
1718
int result;
1819

1920
init_revisions(&rev, prefix);
21+
gitmodules_config();
2022
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2123
rev.abbrev = 0;
2224

builtin/diff-tree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "commit.h"
44
#include "log-tree.h"
55
#include "builtin.h"
6+
#include "submodule.h"
67

78
static struct rev_info log_tree_opt;
89

@@ -112,6 +113,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
112113
int read_stdin = 0;
113114

114115
init_revisions(opt, prefix);
116+
gitmodules_config();
115117
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
116118
opt->abbrev = 0;
117119
opt->diff = 1;

builtin/diff.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "revision.h"
1414
#include "log-tree.h"
1515
#include "builtin.h"
16+
#include "submodule.h"
1617

1718
struct blobinfo {
1819
unsigned char sha1[20];
@@ -279,6 +280,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
279280
*/
280281

281282
prefix = setup_git_directory_gently(&nongit);
283+
gitmodules_config();
282284
git_config(git_diff_ui_config, NULL);
283285

284286
if (diff_use_color_default == -1)

diff-lib.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ static int match_stat_with_submodule(struct diff_options *diffopt,
6868
unsigned ce_option, unsigned *dirty_submodule)
6969
{
7070
int changed = ce_match_stat(ce, st, ce_option);
71-
if (S_ISGITLINK(ce->ce_mode)
72-
&& !DIFF_OPT_TST(diffopt, IGNORE_SUBMODULES)
73-
&& !DIFF_OPT_TST(diffopt, IGNORE_DIRTY_SUBMODULES)
74-
&& (!changed || DIFF_OPT_TST(diffopt, DIRTY_SUBMODULES))) {
75-
*dirty_submodule = is_submodule_modified(ce->name, DIFF_OPT_TST(diffopt, IGNORE_UNTRACKED_IN_SUBMODULES));
71+
if (S_ISGITLINK(ce->ce_mode)) {
72+
unsigned orig_flags = diffopt->flags;
73+
if (!DIFF_OPT_TST(diffopt, OVERRIDE_SUBMODULE_CONFIG))
74+
set_diffopt_flags_from_submodule_config(diffopt, ce->name);
75+
if (DIFF_OPT_TST(diffopt, IGNORE_SUBMODULES))
76+
changed = 0;
77+
else if (!DIFF_OPT_TST(diffopt, IGNORE_DIRTY_SUBMODULES)
78+
&& (!changed || DIFF_OPT_TST(diffopt, DIRTY_SUBMODULES)))
79+
*dirty_submodule = is_submodule_modified(ce->name, DIFF_OPT_TST(diffopt, IGNORE_UNTRACKED_IN_SUBMODULES));
80+
diffopt->flags = orig_flags;
7681
}
7782
return changed;
7883
}

0 commit comments

Comments
 (0)