Skip to content

Commit 29b9932

Browse files
committed
Do not modify an existing repo
1 parent 71f79f6 commit 29b9932

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

management_instance/runbooks/shared_scripts/fork_repo_github.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,12 @@ def fork_repo(git_executable, token, cac_org, new_repo, template_repo):
236236
+ 'github.com/' + cac_org + '/' + template_repo + '.git'],
237237
cwd=new_repo)
238238
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)
240240

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)
254245

255246
# Hard reset it to the template main branch.
256247
execute([git_executable, 'reset', '--hard', 'upstream/' + branch], cwd=new_repo)
@@ -333,10 +324,12 @@ def ensure_git_exists():
333324
set_octopusvariable('NewRepo', 'https://github.com/' + cac_org + '/' + new_repo)
334325

335326
verify_template_repo(token, cac_org, template_repo)
327+
336328
if not verify_new_repo(token, cac_org, new_repo):
337329
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

Comments
 (0)