@@ -236,21 +236,12 @@ def fork_repo(git_executable, token, cac_org, new_repo, template_repo):
236
236
+ 'github.com/' + cac_org + '/' + template_repo + '.git' ],
237
237
cwd = new_repo )
238
238
execute ([git_executable , 'fetch' , '--all' ], cwd = new_repo )
239
- _ , _ , show_branch_result = execute ([ git_executable , 'show-branch' , 'remotes/origin /' + branch ], cwd = new_repo )
239
+ execute ([ 'git' , 'checkout' , '-b' , 'upstream-' + branch , 'upstream /' + branch ], cwd = new_repo )
240
240
241
- if show_branch_result == 0 :
242
- # Checkout the local branch.
243
- if branch != 'master' and branch != 'main' :
244
- execute ([git_executable , 'checkout' , '-b' , branch , 'origin/' + branch ], cwd = new_repo )
245
- else :
246
- execute ([git_executable , 'checkout' , branch ], cwd = new_repo )
247
-
248
- if os .path .exists (new_repo + '/.octopus' ):
249
- print ('The repo https://github.com/' + cac_org + '/' + new_repo + ' has already been forked.' )
250
- sys .exit (0 )
251
-
252
- # Create a new branch representing the forked main branch.
253
- execute ([git_executable , 'checkout' , '-b' , branch ], cwd = new_repo )
241
+ if branch != 'master' and branch != 'main' :
242
+ execute (['git' , 'checkout' , '-b' , branch , 'origin/' + branch ], cwd = new_repo )
243
+ else :
244
+ execute (['git' , 'checkout' , branch ], cwd = new_repo )
254
245
255
246
# Hard reset it to the template main branch.
256
247
execute ([git_executable , 'reset' , '--hard' , 'upstream/' + branch ], cwd = new_repo )
@@ -333,10 +324,12 @@ def ensure_git_exists():
333
324
set_octopusvariable ('NewRepo' , 'https://github.com/' + cac_org + '/' + new_repo )
334
325
335
326
verify_template_repo (token , cac_org , template_repo )
327
+
336
328
if not verify_new_repo (token , cac_org , new_repo ):
337
329
create_new_repo (token , cac_org , new_repo )
338
- fork_repo (git_executable , token , cac_org , new_repo , template_repo )
339
-
340
- print (
341
- 'Repo was forked from ' + 'https://github.com/' + cac_org + '/' + template_repo + ' to '
342
- + 'https://github.com/' + cac_org + '/' + new_repo )
330
+ fork_repo (git_executable , token , cac_org , new_repo , template_repo )
331
+ print (
332
+ 'Repo was forked from ' + 'https://github.com/' + cac_org + '/' + template_repo + ' to '
333
+ + 'https://github.com/' + cac_org + '/' + new_repo )
334
+ else :
335
+ print ('Repo at https://github.com/' + cac_org + '/' + new_repo + ' already exists and has not been modified' )
0 commit comments