Skip to content

Commit 302ad7a

Browse files
jlehmanngitster
authored andcommitted
Submodules: Use "ignore" settings from .gitmodules too for diff and status
The .gitmodules file is parsed for "submodule.<name>.ignore" entries before looking for them in .git/config. Thus settings found in .git/config will override those from .gitmodules, thereby allowing the local developer to ignore settings given by the remote side while also letting upstream set defaults for those users who don't have special needs. Signed-off-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aee9c7d commit 302ad7a

File tree

13 files changed

+209
-10
lines changed

13 files changed

+209
-10
lines changed

Documentation/config.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,9 @@ submodule.<name>.ignore::
17521752
let submodules with modified tracked files in their work tree show up.
17531753
Using "none" (the default when this option is not set) also shows
17541754
submodules that have untracked files in their work tree as changed.
1755+
This setting overrides any setting made in .gitmodules for this submodule,
1756+
both settings can be overriden on the command line by using the
1757+
"--ignore-submodule" option.
17551758

17561759
tar.umask::
17571760
This variable can be used to restrict the permission bits of

Documentation/diff-options.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ endif::git-format-patch[]
334334
Using "none" will consider the submodule modified when it either contains
335335
untracked or modified files or its HEAD differs from the commit recorded
336336
in the superproject and can be used to override any settings of the
337-
'ignore' option in linkgit:git-config[1]. When
337+
'ignore' option in linkgit:git-config[1] or linkgit:gitmodules[5]. When
338338
"untracked" is used submodules are not considered dirty when they only
339339
contain untracked content (but they are still scanned for modified
340340
content). Using "dirty" ignores all changes to the work tree of submodules,

Documentation/git-status.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ specified.
5959
Using "none" will consider the submodule modified when it either contains
6060
untracked or modified files or its HEAD differs from the commit recorded
6161
in the superproject and can be used to override any settings of the
62-
'ignore' option in linkgit:git-config[1]. When
62+
'ignore' option in linkgit:git-config[1] or linkgit:gitmodules[5]. When
6363
"untracked" is used submodules are not considered dirty when they only
6464
contain untracked content (but they are still scanned for modified
6565
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)

submodule.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
6262
}
6363
}
6464

65+
static int submodule_config(const char *var, const char *value, void *cb)
66+
{
67+
if (!prefixcmp(var, "submodule."))
68+
return parse_submodule_config_option(var, value);
69+
return 0;
70+
}
71+
72+
void gitmodules_config(void)
73+
{
74+
const char *work_tree = get_git_work_tree();
75+
if (work_tree) {
76+
struct strbuf gitmodules_path = STRBUF_INIT;
77+
strbuf_addstr(&gitmodules_path, work_tree);
78+
strbuf_addstr(&gitmodules_path, "/.gitmodules");
79+
git_config_from_file(submodule_config, gitmodules_path.buf, NULL);
80+
strbuf_release(&gitmodules_path);
81+
}
82+
}
83+
6584
int parse_submodule_config_option(const char *var, const char *value)
6685
{
6786
int len;

0 commit comments

Comments
 (0)