@@ -27,14 +27,25 @@ static struct oid_array ref_tips_before_fetch;
27
27
static struct oid_array ref_tips_after_fetch ;
28
28
29
29
/*
30
- * The following flag is set if the .gitmodules file is unmerged. We then
31
- * disable recursion for all submodules where .git/config doesn't have a
32
- * matching config entry because we can't guess what might be configured in
33
- * .gitmodules unless the user resolves the conflict. When a command line
34
- * option is given (which always overrides configuration) this flag will be
35
- * ignored.
30
+ * Check if the .gitmodules file is unmerged. Parsing of the .gitmodules file
31
+ * will be disabled because we can't guess what might be configured in
32
+ * .gitmodules unless the user resolves the conflict.
36
33
*/
37
- static int gitmodules_is_unmerged ;
34
+ int is_gitmodules_unmerged (const struct index_state * istate )
35
+ {
36
+ int pos = index_name_pos (istate , GITMODULES_FILE , strlen (GITMODULES_FILE ));
37
+ if (pos < 0 ) { /* .gitmodules not found or isn't merged */
38
+ pos = -1 - pos ;
39
+ if (istate -> cache_nr > pos ) { /* there is a .gitmodules */
40
+ const struct cache_entry * ce = istate -> cache [pos ];
41
+ if (ce_namelen (ce ) == strlen (GITMODULES_FILE ) &&
42
+ !strcmp (ce -> name , GITMODULES_FILE ))
43
+ return 1 ;
44
+ }
45
+ }
46
+
47
+ return 0 ;
48
+ }
38
49
39
50
/*
40
51
* Check if the .gitmodules file has unstaged modifications. This must be
@@ -71,7 +82,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
71
82
if (!file_exists (GITMODULES_FILE )) /* Do nothing without .gitmodules */
72
83
return -1 ;
73
84
74
- if (gitmodules_is_unmerged )
85
+ if (is_gitmodules_unmerged ( & the_index ) )
75
86
die (_ ("Cannot change unmerged .gitmodules, resolve merge conflicts first" ));
76
87
77
88
submodule = submodule_from_path (null_sha1 , oldpath );
@@ -105,7 +116,7 @@ int remove_path_from_gitmodules(const char *path)
105
116
if (!file_exists (GITMODULES_FILE )) /* Do nothing without .gitmodules */
106
117
return -1 ;
107
118
108
- if (gitmodules_is_unmerged )
119
+ if (is_gitmodules_unmerged ( & the_index ) )
109
120
die (_ ("Cannot change unmerged .gitmodules, resolve merge conflicts first" ));
110
121
111
122
submodule = submodule_from_path (null_sha1 , path );
@@ -156,7 +167,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
156
167
if (submodule ) {
157
168
if (submodule -> ignore )
158
169
handle_ignore_submodules_arg (diffopt , submodule -> ignore );
159
- else if (gitmodules_is_unmerged )
170
+ else if (is_gitmodules_unmerged ( & the_index ) )
160
171
DIFF_OPT_SET (diffopt , IGNORE_SUBMODULES );
161
172
}
162
173
}
@@ -224,23 +235,12 @@ void gitmodules_config(void)
224
235
const char * work_tree = get_git_work_tree ();
225
236
if (work_tree ) {
226
237
struct strbuf gitmodules_path = STRBUF_INIT ;
227
- int pos ;
228
238
strbuf_addstr (& gitmodules_path , work_tree );
229
239
strbuf_addstr (& gitmodules_path , "/" GITMODULES_FILE );
230
240
if (read_cache () < 0 )
231
241
die ("index file corrupt" );
232
- pos = cache_name_pos (GITMODULES_FILE , 11 );
233
- if (pos < 0 ) { /* .gitmodules not found or isn't merged */
234
- pos = -1 - pos ;
235
- if (active_nr > pos ) { /* there is a .gitmodules */
236
- const struct cache_entry * ce = active_cache [pos ];
237
- if (ce_namelen (ce ) == 11 &&
238
- !memcmp (ce -> name , GITMODULES_FILE , 11 ))
239
- gitmodules_is_unmerged = 1 ;
240
- }
241
- }
242
242
243
- if (!gitmodules_is_unmerged )
243
+ if (!is_gitmodules_unmerged ( & the_index ) )
244
244
git_config_from_file (git_modules_config ,
245
245
gitmodules_path .buf , NULL );
246
246
strbuf_release (& gitmodules_path );
@@ -1198,8 +1198,7 @@ static int get_next_submodule(struct child_process *cp,
1198
1198
default_argv = "on-demand" ;
1199
1199
}
1200
1200
} else {
1201
- if ((spf -> default_option == RECURSE_SUBMODULES_OFF ) ||
1202
- gitmodules_is_unmerged )
1201
+ if (spf -> default_option == RECURSE_SUBMODULES_OFF )
1203
1202
continue ;
1204
1203
if (spf -> default_option == RECURSE_SUBMODULES_ON_DEMAND ) {
1205
1204
if (!unsorted_string_list_lookup (& changed_submodule_paths , ce -> name ))
0 commit comments