Skip to content

Commit cda36e7

Browse files
committed
Added validation when checking out a branch
1 parent 591fe22 commit cda36e7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

management_instance/runbooks/shared_scripts/fork_repo_github.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,13 @@ def fork_repo(git_executable, token, cac_org, new_repo, template_repo):
241241
execute(['git', 'checkout', '-b', 'upstream-' + branch, 'upstream/' + branch], cwd=new_repo)
242242

243243
if branch != 'master' and branch != 'main':
244-
execute(['git', 'checkout', '-b', branch, 'origin/' + branch], cwd=new_repo)
244+
_, _, retcode = execute(['git', 'checkout', '-b', branch, 'origin/' + branch], cwd=new_repo)
245245
else:
246-
execute(['git', 'checkout', branch], cwd=new_repo)
246+
_, _, retcode = execute(['git', 'checkout', branch], cwd=new_repo)
247+
248+
if not retcode == 0:
249+
print('Failed to checkout branch ' + branch)
250+
sys.exit(1)
247251

248252
# Hard reset it to the template main branch.
249253
execute([git_executable, 'reset', '--hard', 'upstream/' + branch], cwd=new_repo)

0 commit comments

Comments
 (0)