@@ -12,8 +12,15 @@ static int add_submodule_odb(const char *path)
12
12
struct strbuf objects_directory = STRBUF_INIT ;
13
13
struct alternate_object_database * alt_odb ;
14
14
int ret = 0 ;
15
+ const char * git_dir ;
15
16
16
- strbuf_addf (& objects_directory , "%s/.git/objects/" , path );
17
+ strbuf_addf (& objects_directory , "%s/.git" , path );
18
+ git_dir = read_gitfile_gently (objects_directory .buf );
19
+ if (git_dir ) {
20
+ strbuf_reset (& objects_directory );
21
+ strbuf_addstr (& objects_directory , git_dir );
22
+ }
23
+ strbuf_addstr (& objects_directory , "/objects/" );
17
24
if (!is_directory (objects_directory .buf )) {
18
25
ret = -1 ;
19
26
goto done ;
@@ -132,7 +139,6 @@ void show_submodule_summary(FILE *f, const char *path,
132
139
133
140
unsigned is_submodule_modified (const char * path , int ignore_untracked )
134
141
{
135
- int i ;
136
142
ssize_t len ;
137
143
struct child_process cp ;
138
144
const char * argv [] = {
@@ -141,38 +147,33 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
141
147
NULL ,
142
148
NULL ,
143
149
};
144
- const char * env [LOCAL_REPO_ENV_SIZE + 3 ];
145
150
struct strbuf buf = STRBUF_INIT ;
146
151
unsigned dirty_submodule = 0 ;
147
152
const char * line , * next_line ;
153
+ const char * git_dir ;
148
154
149
- for ( i = 0 ; i < LOCAL_REPO_ENV_SIZE ; i ++ )
150
- env [ i ] = local_repo_env [ i ] ;
151
-
152
- strbuf_addf ( & buf , "%s/.git/" , path ) ;
153
- if (!is_directory (buf . buf )) {
155
+ strbuf_addf ( & buf , "%s/.git" , path );
156
+ git_dir = read_gitfile_gently ( buf . buf ) ;
157
+ if (! git_dir )
158
+ git_dir = buf . buf ;
159
+ if (!is_directory (git_dir )) {
154
160
strbuf_release (& buf );
155
161
/* The submodule is not checked out, so it is not modified */
156
162
return 0 ;
157
163
158
164
}
159
165
strbuf_reset (& buf );
160
166
161
- strbuf_addf (& buf , "GIT_WORK_TREE=%s" , path );
162
- env [i ++ ] = strbuf_detach (& buf , NULL );
163
- strbuf_addf (& buf , "GIT_DIR=%s/.git" , path );
164
- env [i ++ ] = strbuf_detach (& buf , NULL );
165
- env [i ] = NULL ;
166
-
167
167
if (ignore_untracked )
168
168
argv [2 ] = "-uno" ;
169
169
170
170
memset (& cp , 0 , sizeof (cp ));
171
171
cp .argv = argv ;
172
- cp .env = env ;
172
+ cp .env = local_repo_env ;
173
173
cp .git_cmd = 1 ;
174
174
cp .no_stdin = 1 ;
175
175
cp .out = -1 ;
176
+ cp .dir = path ;
176
177
if (start_command (& cp ))
177
178
die ("Could not run git status --porcelain" );
178
179
@@ -201,8 +202,6 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
201
202
if (finish_command (& cp ))
202
203
die ("git status --porcelain failed" );
203
204
204
- for (i = LOCAL_REPO_ENV_SIZE ; env [i ]; i ++ )
205
- free ((char * )env [i ]);
206
205
strbuf_release (& buf );
207
206
return dirty_submodule ;
208
207
}
0 commit comments