@@ -57,7 +57,7 @@ def get_octopusvariable_quiet(variable):
57
57
return ''
58
58
59
59
60
- def execute (args , cwd = None , env = None , print_args = None , print_output = printverbose_noansi ):
60
+ def execute (args , cwd = None , env = None , print_args = None , print_output = printverbose_noansi , raise_on_non_zero = False ):
61
61
"""
62
62
The execute method provides the ability to execute external processes while capturing and returning the
63
63
output to std err and std out and exit code.
@@ -71,6 +71,9 @@ def execute(args, cwd=None, env=None, print_args=None, print_output=printverbose
71
71
stdout , stderr = process .communicate ()
72
72
retcode = process .returncode
73
73
74
+ if not retcode == 0 and raise_on_non_zero :
75
+ raise Exception ('command returned exit code ' + retcode )
76
+
74
77
if print_args is not None :
75
78
print_output (' ' .join (args ))
76
79
@@ -231,29 +234,60 @@ def create_new_repo(token, cac_org, new_repo):
231
234
232
235
def fork_repo (git_executable , token , cac_org , new_repo , template_repo ):
233
236
# Clone the repo and add the upstream repo
234
- execute ([git_executable , 'clone' , 'https://' + 'x-access-token:' + token + '@'
235
- + 'github.com/' + cac_org + '/' + new_repo + '.git' ])
236
- execute (
237
+ _ , _ , retcode = execute ([git_executable , 'clone' , 'https://' + 'x-access-token:' + token + '@'
238
+ + 'github.com/' + cac_org + '/' + new_repo + '.git' ])
239
+
240
+ if not retcode == 0 :
241
+ print ('Failed to clone repo ' + 'https://github.com/' + cac_org + '/' + new_repo + '.git.' +
242
+ ' Check the verbose logs for details.' )
243
+ sys .exit (1 )
244
+
245
+ _ , _ , retcode = execute (
237
246
[git_executable , 'remote' , 'add' , 'upstream' , 'https://' + 'x-access-token:' + token + '@'
238
247
+ 'github.com/' + cac_org + '/' + template_repo + '.git' ],
239
248
cwd = new_repo )
240
- execute ([git_executable , 'fetch' , '--all' ], cwd = new_repo )
241
- execute (['git' , 'checkout' , '-b' , 'upstream-' + branch , 'upstream/' + branch ], cwd = new_repo )
249
+
250
+ if not retcode == 0 :
251
+ print ('Failed to add remote ' + 'https://github.com/' + cac_org + '/' + template_repo + '.git. ' +
252
+ 'Check the verbose logs for details.' )
253
+ sys .exit (1 )
254
+
255
+ _ , _ , retcode = execute ([git_executable , 'fetch' , '--all' ], cwd = new_repo )
256
+
257
+ if not retcode == 0 :
258
+ print ('Failed to fetch. Check the verbose logs for details.' )
259
+ sys .exit (1 )
260
+
261
+ _ , _ , retcode = execute (['git' , 'checkout' , '-b' , 'upstream-' + branch , 'upstream/' + branch ], cwd = new_repo )
262
+
263
+ if not retcode == 0 :
264
+ print ('Failed to checkout branch ' + branch + '. Check the verbose logs for details.' )
265
+ sys .exit (1 )
242
266
243
267
if branch != 'master' and branch != 'main' :
244
268
_ , _ , retcode = execute (['git' , 'checkout' , '-b' , branch , 'origin/' + branch ], cwd = new_repo )
245
269
else :
246
- _ , _ , retcode = execute (['git' , 'checkout' , branch ], cwd = new_repo )
270
+ _ , _ , retcode = execute (['git' , 'checkout' , branch ], cwd = new_repo )
247
271
248
272
if not retcode == 0 :
249
- print ('Failed to checkout branch ' + branch )
273
+ print ('Failed to checkout branch ' + branch + '. Check the verbose logs for details.' )
250
274
sys .exit (1 )
251
275
252
276
# Hard reset it to the template main branch.
253
- execute ([git_executable , 'reset' , '--hard' , 'upstream/' + branch ], cwd = new_repo )
277
+ _ , _ , retcode = execute ([git_executable , 'reset' , '--hard' , 'upstream/' + branch ], cwd = new_repo )
278
+
279
+ if not retcode == 0 :
280
+ print (
281
+ 'Failed to perform a hard reset against branch upstream/' + branch + '.'
282
+ + ' Check the verbose logs for details.' )
283
+ sys .exit (1 )
254
284
255
285
# Push the changes.
256
- execute ([git_executable , 'push' , 'origin' , branch ], cwd = new_repo )
286
+ _ , _ , retcode = execute ([git_executable , 'push' , 'origin' , branch ], cwd = new_repo )
287
+
288
+ if not retcode == 0 :
289
+ print ('Failed to push changes. Check the verbose logs for details.' )
290
+ sys .exit (1 )
257
291
258
292
259
293
def is_windows ():
0 commit comments