Skip to content

Commit f01802b

Browse files
committed
checkout into known directory
1 parent ef300a2 commit f01802b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

management_instance/runbooks/shared_scripts/fork_repo_gitea.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,35 +175,36 @@ def init_argparse():
175175
urllib.request.urlopen(request)
176176

177177
# Clone the repo and add the upstream repo
178+
repo_dir = 'repo'
178179
execute(['git', 'clone', parser.git_protocol + '://' + parser.cac_username + ':' + parser.cac_password + '@'
179-
+ parser.git_host + '/' + parser.git_organization + '/' + new_repo + '.git'])
180+
+ parser.git_host + '/' + parser.git_organization + '/' + new_repo + '.git', repo_dir])
180181
execute(
181182
['git', 'remote', 'add', 'upstream',
182183
parser.git_protocol + '://' + parser.cac_username + ':' + parser.cac_password + '@'
183184
+ parser.git_host + '/' + parser.git_organization + '/' + template_repo + '.git'],
184-
cwd=new_repo)
185-
execute(['git', 'fetch', '--all'], cwd=new_repo)
186-
_, _, show_branch_result = execute(['git', 'show-branch', 'remotes/origin/' + branch], cwd=new_repo)
185+
cwd=repo_dir)
186+
execute(['git', 'fetch', '--all'], cwd=repo_dir)
187+
_, _, show_branch_result = execute(['git', 'show-branch', 'remotes/origin/' + branch], cwd=repo_dir)
187188

188189
if show_branch_result == 0:
189190
# Checkout the local branch.
190191
if branch != 'master' and branch != 'main':
191-
execute(['git', 'checkout', '-b', branch, 'origin/' + branch], cwd=new_repo)
192+
execute(['git', 'checkout', '-b', branch, 'origin/' + branch], cwd=repo_dir)
192193
else:
193-
execute(['git', 'checkout', branch], cwd=new_repo)
194+
execute(['git', 'checkout', branch], cwd=repo_dir)
194195

195196
if os.path.exists(new_repo + '/.octopus'):
196197
print('The repo has already been forked.')
197198
sys.exit(0)
198199

199200
# Create a new branch representing the forked main branch.
200-
execute(['git', 'checkout', '-b', branch], cwd=new_repo)
201+
execute(['git', 'checkout', '-b', branch], cwd=repo_dir)
201202

202203
# Hard reset it to the template main branch.
203-
execute(['git', 'reset', '--hard', 'upstream/' + branch], cwd=new_repo)
204+
execute(['git', 'reset', '--hard', 'upstream/' + branch], cwd=repo_dir)
204205

205206
# Push the changes.
206-
execute(['git', 'push', 'origin', branch], cwd=new_repo)
207+
execute(['git', 'push', 'origin', branch], cwd=repo_dir)
207208

208209
print(
209210
'Repo was forked from ' + parser.git_protocol + '://' + parser.git_host + '/' + parser.git_organization + '/' + template_repo + ' to '

0 commit comments

Comments
 (0)