@@ -60,8 +60,9 @@ def status(self):
60
60
if not os .path .exists (os .path .join (smpath , ".git" )):
61
61
rootgit = GitInterface (self .root_dir , self .logger )
62
62
# submodule commands use path, not name
63
- tags = rootgit .git_operation ("ls-remote" , "--tags" , self .url )
64
- result = rootgit .git_operation ("submodule" ,"status" ,smpath ).split ()
63
+ status , tags = rootgit .git_operation ("ls-remote" , "--tags" , self .url )
64
+ status , result = rootgit .git_operation ("submodule" ,"status" ,smpath )
65
+ result = result .split ()
65
66
66
67
if result :
67
68
ahash = result [0 ][1 :]
@@ -80,9 +81,9 @@ def status(self):
80
81
result = f"e { self .name :>20} not checked out, aligned at tag { self .fxtag } { optional } "
81
82
needsupdate = True
82
83
elif self .fxtag :
83
- ahash = rootgit .git_operation (
84
+ status , ahash = rootgit .git_operation (
84
85
"submodule" , "status" , "{}" .format (self .path )
85
- ). rstrip ()
86
+ )
86
87
ahash = ahash [1 : len (self .fxtag ) + 1 ]
87
88
if self .fxtag == ahash :
88
89
result = f"e { self .name :>20} not checked out, aligned at hash { ahash } { optional } "
@@ -96,14 +97,15 @@ def status(self):
96
97
else :
97
98
with utils .pushd (smpath ):
98
99
git = GitInterface (smpath , self .logger )
99
- remote = git .git_operation ("remote" ). rstrip ( )
100
+ status , remote = git .git_operation ("remote" )
100
101
if remote == '' :
101
102
result = f"e { self .name :>20} has no associated remote"
102
103
testfails = True
103
104
needsupdate = True
104
105
return result , needsupdate , localmods , testfails
105
- rurl = git .git_operation ("ls-remote" ,"--get-url" ).rstrip ()
106
- line = git .git_operation ("log" , "--pretty=format:\" %h %d\" " ).partition ('\n ' )[0 ]
106
+ status , rurl = git .git_operation ("ls-remote" ,"--get-url" )
107
+ status , lines = git .git_operation ("log" , "--pretty=format:\" %h %d\" " )
108
+ line = lines .partition ('\n ' )[0 ]
107
109
parts = line .split ()
108
110
ahash = parts [0 ][1 :]
109
111
atag = None
@@ -120,7 +122,7 @@ def status(self):
120
122
121
123
122
124
#print(f"line is {line} ahash is {ahash} atag is {atag} {parts}")
123
- # atag = git.git_operation("describe", "--tags", "--always").rstrip()
125
+ # atag = git.git_operation("describe", "--tags", "--always")
124
126
# ahash = git.git_operation("rev-list", "HEAD").partition("\n")[0]
125
127
126
128
recurse = False
@@ -149,10 +151,10 @@ def status(self):
149
151
result = f"e { self .name :>20} has no fxtag defined in .gitmodules, module at { ahash } "
150
152
testfails = False
151
153
152
- status = git .git_operation ("status" , "--ignore-submodules" , "-uno" )
153
- if "nothing to commit" not in status :
154
+ status , output = git .git_operation ("status" , "--ignore-submodules" , "-uno" )
155
+ if "nothing to commit" not in output :
154
156
localmods = True
155
- result = "M" + textwrap .indent (status , " " )
157
+ result = "M" + textwrap .indent (output , " " )
156
158
# print(f"result {result} needsupdate {needsupdate} localmods {localmods} testfails {testfails}")
157
159
return result , needsupdate , localmods , testfails
158
160
@@ -171,10 +173,11 @@ def _add_remote(self, git):
171
173
Returns:
172
174
str: The name of the new remote if added, or the name of the existing remote that matches the submodule's URL.
173
175
"""
174
- remotes = git .git_operation ("remote" , "-v" ).splitlines ()
176
+ status , remotes = git .git_operation ("remote" , "-v" )
177
+ remotes = remotes .splitlines ()
175
178
upstream = None
176
179
if remotes :
177
- upstream = git .git_operation ("ls-remote" , "--get-url" ). rstrip ( )
180
+ status , upstream = git .git_operation ("ls-remote" , "--get-url" )
178
181
newremote = "newremote.00"
179
182
tmpurl = self .url .replace ("git@github.com:" , "https://github.com/" )
180
183
line = next ((s for s in remotes if self .url in s or tmpurl in s ), None )
@@ -183,7 +186,7 @@ def _add_remote(self, git):
183
186
return newremote
184
187
else :
185
188
i = 0
186
- while " newremote" in remotes :
189
+ while newremote in remotes :
187
190
i = i + 1
188
191
newremote = f"newremote.{ i :02d} "
189
192
else :
@@ -214,12 +217,19 @@ def sparse_checkout(self):
214
217
"""
215
218
self .logger .info ("Called sparse_checkout for {}" .format (self .name ))
216
219
rgit = GitInterface (self .root_dir , self .logger )
217
- superroot = rgit .git_operation ("rev-parse" , "--show-superproject-working-tree" )
220
+ status , superroot = rgit .git_operation ("rev-parse" , "--show-superproject-working-tree" )
218
221
if superroot :
219
222
gitroot = superroot .strip ()
220
223
else :
221
- gitroot = self .root_dir .strip ()
222
- assert os .path .isdir (os .path .join (gitroot , ".git" ))
224
+ gitroot = self .root_dir
225
+ # Now need to move the .git dir to the submodule location
226
+ rootdotgit = os .path .join (self .root_dir , ".git" )
227
+ while os .path .isfile (rootdotgit ):
228
+ with open (rootdotgit ) as f :
229
+ line = f .readline ().rstrip ()
230
+ if line .startswith ("gitdir: " ):
231
+ rootdotgit = os .path .abspath (os .path .join (self .root_dir ,line [8 :]))
232
+ assert os .path .isdir (rootdotgit )
223
233
# first create the module directory
224
234
if not os .path .isdir (os .path .join (self .root_dir , self .path )):
225
235
os .makedirs (os .path .join (self .root_dir , self .path ))
@@ -244,8 +254,8 @@ def sparse_checkout(self):
244
254
# set the repository remote
245
255
246
256
self .logger .info ("Setting remote origin in {}/{}" .format (self .root_dir , self .path ))
247
- status = sprepo_git .git_operation ("remote" , "-v" )
248
- if self .url not in status :
257
+ status , remotes = sprepo_git .git_operation ("remote" , "-v" )
258
+ if self .url not in remotes :
249
259
sprepo_git .git_operation ("remote" , "add" , "origin" , self .url )
250
260
251
261
topgit = os .path .join (gitroot , ".git" )
@@ -256,46 +266,46 @@ def sparse_checkout(self):
256
266
os .path .join (self .root_dir , f .read ().split ()[1 ]),
257
267
start = os .path .join (self .root_dir , self .path ),
258
268
)
259
- topgit = os .path .join (gitpath , "modules" )
269
+ rootdotgit = os .path .join (gitpath , "modules" , self . name )
260
270
else :
261
- topgit = os .path .relpath (
262
- os .path .join (self .root_dir , ".git" , "modules" ),
271
+ rootdotgit = os .path .relpath (
272
+ os .path .join (self .root_dir , ".git" , "modules" , self . name ),
263
273
start = os .path .join (self .root_dir , self .path ),
264
274
)
265
275
266
- with utils .pushd (sprep_repo ):
267
- if not os .path .isdir (topgit ):
268
- os .makedirs (topgit )
269
- topgit += os .sep + self .name
270
-
271
276
if os .path .isdir (os .path .join (self .root_dir , self .path , ".git" )):
272
277
with utils .pushd (sprep_repo ):
273
- if os .path .isdir (os .path .join (topgit ,".git" )):
274
- shutil .rmtree (os .path .join (topgit ,".git" ))
275
- shutil .move (".git" , topgit )
278
+ if os .path .isdir (os .path .join (rootdotgit ,".git" )):
279
+ shutil .rmtree (os .path .join (rootdotgit ,".git" ))
280
+ shutil .move (".git" , rootdotgit )
276
281
with open (".git" , "w" ) as f :
277
- f .write ("gitdir: " + os .path .relpath (topgit ))
278
- # assert(os.path.isdir(os.path.relpath(topgit, start=sprep_repo)))
279
- gitsparse = os .path .abspath (os .path .join (topgit , "info" , "sparse-checkout" ))
282
+ f .write ("gitdir: " + os .path .relpath (rootdotgit ))
283
+ infodir = os .path .join (rootdotgit , "info" )
284
+ if not os .path .isdir (infodir ):
285
+ os .makedirs (infodir )
286
+ gitsparse = os .path .abspath (os .path .join (infodir , "sparse-checkout" ))
280
287
if os .path .isfile (gitsparse ):
281
288
self .logger .warning (
282
- "submodule {} is already initialized {}" .format (self .name , topgit )
289
+ "submodule {} is already initialized {}" .format (self .name , rootdotgit )
283
290
)
284
291
return
285
292
286
293
with utils .pushd (sprep_repo ):
287
294
if os .path .isfile (self .fxsparse ):
295
+
288
296
shutil .copy (self .fxsparse , gitsparse )
289
297
290
298
291
299
# Finally checkout the repo
292
300
sprepo_git .git_operation ("fetch" , "origin" , "--tags" )
293
- sprepo_git .git_operation ("checkout" , self .fxtag )
294
-
295
- print (f"Successfully checked out { self .name :>20} at { self .fxtag } " )
296
- rgit .config_set_value (f'submodule "{ self .name } "' , "active" , "true" )
297
- rgit .config_set_value (f'submodule "{ self .name } "' , "url" , self .url )
298
- rgit .config_set_value (f'submodule "{ self .name } "' , "path" , self .path )
301
+ status ,_ = sprepo_git .git_operation ("checkout" , self .fxtag )
302
+ if status :
303
+ print (f"Error checking out { self .name :>20} at { self .fxtag } " )
304
+ else :
305
+ print (f"Successfully checked out { self .name :>20} at { self .fxtag } " )
306
+ rgit .config_set_value ('submodule.' + self .name , "active" , "true" )
307
+ rgit .config_set_value ('submodule.' + self .name , "url" , self .url )
308
+ rgit .config_set_value ('submodule.' + self .name , "path" , self .path )
299
309
300
310
def update (self ):
301
311
"""
@@ -342,15 +352,15 @@ def update(self):
342
352
git .git_operation ("clone" , self .url , self .path )
343
353
smgit = GitInterface (repodir , self .logger )
344
354
if not tag :
345
- tag = smgit .git_operation ("describe" , "--tags" , "--always" ). rstrip ( )
355
+ status , tag = smgit .git_operation ("describe" , "--tags" , "--always" )
346
356
smgit .git_operation ("checkout" , tag )
347
357
# Now need to move the .git dir to the submodule location
348
358
rootdotgit = os .path .join (self .root_dir , ".git" )
349
359
if os .path .isfile (rootdotgit ):
350
360
with open (rootdotgit ) as f :
351
361
line = f .readline ()
352
362
if line .startswith ("gitdir: " ):
353
- rootdotgit = line [8 :]. rstrip ()
363
+ rootdotgit = line [8 :]
354
364
355
365
newpath = os .path .abspath (os .path .join (self .root_dir , rootdotgit , "modules" , self .name ))
356
366
if os .path .exists (newpath ):
@@ -393,15 +403,16 @@ def update(self):
393
403
git = GitInterface (submoddir , self .logger )
394
404
# first make sure the url is correct
395
405
newremote = self ._add_remote (git )
396
- tags = git .git_operation ("tag" , "-l" )
406
+ status , tags = git .git_operation ("tag" , "-l" )
397
407
fxtag = self .fxtag
398
408
if fxtag and fxtag not in tags :
399
409
git .git_operation ("fetch" , newremote , "--tags" )
400
- atag = git .git_operation ("describe" , "--tags" , "--always" ). rstrip ( )
410
+ status , atag = git .git_operation ("describe" , "--tags" , "--always" )
401
411
if fxtag and fxtag != atag :
402
412
try :
403
- git .git_operation ("checkout" , fxtag )
404
- print (f"{ self .name :>20} updated to { fxtag } " )
413
+ status , _ = git .git_operation ("checkout" , fxtag )
414
+ if not status :
415
+ print (f"{ self .name :>20} updated to { fxtag } " )
405
416
except Exception as error :
406
417
print (error )
407
418
0 commit comments