I tried to do a payu clone, but it errored because there was an existing branch with the same name
Details
```
$ payu clone -b main -B release-1deg_jra55_ryf https://github.com/ACCESS-NRI/access-om2-configs.git 1deg_jra55_ryf
Cloned repository from https://github.com/ACCESS-NRI/access-om2-configs.git to directory: /g/data/tm70/aph502/access-om2-release/bitrepro/1deg_jra55_ryf
Traceback (most recent call last):
File "/g/data/vk83/apps/payu/1.1/bin/payu", line 10, in
sys.exit(parse())
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/cli.py", line 41, in parse
run_cmd(**args)
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/subcommands/clone_cmd.py", line 37, in runcmd
clone(repository=repository,
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/branch.py", line 255, in clone
checkout_branch(is_new_branch=True,
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/branch.py", line 145, in checkout_branch
repo.checkout_branch(branch_name, is_new_branch, start_point)
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/git_utils.py", line 153, in checkout_branch
raise PayuBranchError(
payu.git_utils.PayuBranchError: A branch named main already exists. To checkout this branch, remove the new branch flag '-b' from the checkout command.
```
When I followed the instructions to remedy the problem it threw an error because the previous attempt created the destination directory.
Details
```
payu clone -B release-1deg_jra55_ryf https://github.com/ACCESS-NRI/access-om2-configs.git 1deg_jra55_ryf
Traceback (most recent call last):
File "/g/data/vk83/apps/payu/1.1/bin/payu", line 10, in
sys.exit(parse())
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/cli.py", line 41, in parse
run_cmd(**args)
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/subcommands/clone_cmd.py", line 37, in runcmd
clone(repository=repository,
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/branch.py", line 245, in clone
repo = git_clone(repository, control_path, branch)
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/git_utils.py", line 190, in git_clone
repo = git.Repo.clone_from(repository,
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/git/repo/base.py", line 1328, in clone_from
return cls._clone(
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/git/repo/base.py", line 1237, in _clone
finalize_process(proc, stderr=stderr)
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/git/util.py", line 453, in finalize_process
proc.wait(**kwargs)
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/git/cmd.py", line 600, in wait
raise GitCommandError(remove_password_if_present(self.args), status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
cmdline: git clone -v --branch=release-1deg_jra55_ryf -- https://github.com/ACCESS-NRI/access-om2-configs.git /g/data/tm70/aph502/access-om2-release/bitrepro/1deg_jra55_ryf
stderr: 'fatal: destination path '/g/data/tm70/aph502/access-om2-release/bitrepro/1deg_jra55_ryf' already exists and is not an empty directory.
```
The solution was to remove the existing directory, payu clone without specifying the branch name then worked.
Possible solutions
Enclose the clone command in a try/except block and then:
catch payu.git_utils.PayuBranchError, emit the current error message, but add a message to let the user know they might have to remove the directory, caution that this should be done with care if this was a pre-existing control directory.
before the try/except block check if the path to create already exists, and in the except block emit the current error message but also clean up the directory that was created.
Number 2 seems like the better option. If we know the the directory didn't exist before it seems side-effect free and good practice to clean up an operation that didn't complete cleanly.
Arguably we should check if the destination already exists, because we know it will error and we could give the user some useful advice: clone into a different path, or cd into the existing control directory and use payu checkout.
Problem description:
I tried to do a
payu clone
, but it errored because there was an existing branch with the same nameDetails
``` $ payu clone -b main -B release-1deg_jra55_ryf https://github.com/ACCESS-NRI/access-om2-configs.git 1deg_jra55_ryf Cloned repository from https://github.com/ACCESS-NRI/access-om2-configs.git to directory: /g/data/tm70/aph502/access-om2-release/bitrepro/1deg_jra55_ryf Traceback (most recent call last): File "/g/data/vk83/apps/payu/1.1/bin/payu", line 10, in
sys.exit(parse())
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/cli.py", line 41, in parse
run_cmd(**args)
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/subcommands/clone_cmd.py", line 37, in runcmd
clone(repository=repository,
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/branch.py", line 255, in clone
checkout_branch(is_new_branch=True,
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/branch.py", line 145, in checkout_branch
repo.checkout_branch(branch_name, is_new_branch, start_point)
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/git_utils.py", line 153, in checkout_branch
raise PayuBranchError(
payu.git_utils.PayuBranchError: A branch named main already exists. To checkout this branch, remove the new branch flag '-b' from the checkout command.
```
When I followed the instructions to remedy the problem it threw an error because the previous attempt created the destination directory.
Details
``` payu clone -B release-1deg_jra55_ryf https://github.com/ACCESS-NRI/access-om2-configs.git 1deg_jra55_ryf Traceback (most recent call last): File "/g/data/vk83/apps/payu/1.1/bin/payu", line 10, in
sys.exit(parse())
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/cli.py", line 41, in parse
run_cmd(**args)
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/subcommands/clone_cmd.py", line 37, in runcmd
clone(repository=repository,
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/branch.py", line 245, in clone
repo = git_clone(repository, control_path, branch)
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/payu/git_utils.py", line 190, in git_clone
repo = git.Repo.clone_from(repository,
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/git/repo/base.py", line 1328, in clone_from
return cls._clone(
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/git/repo/base.py", line 1237, in _clone
finalize_process(proc, stderr=stderr)
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/git/util.py", line 453, in finalize_process
proc.wait(**kwargs)
File "/g/data/vk83/apps/payu/1.1/lib/python3.9/site-packages/git/cmd.py", line 600, in wait
raise GitCommandError(remove_password_if_present(self.args), status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
cmdline: git clone -v --branch=release-1deg_jra55_ryf -- https://github.com/ACCESS-NRI/access-om2-configs.git /g/data/tm70/aph502/access-om2-release/bitrepro/1deg_jra55_ryf
stderr: 'fatal: destination path '/g/data/tm70/aph502/access-om2-release/bitrepro/1deg_jra55_ryf' already exists and is not an empty directory.
```
The solution was to remove the existing directory,
payu clone
without specifying the branch name then worked.Possible solutions
Enclose the clone command in a
try/except
block and then:payu.git_utils.PayuBranchError
, emit the current error message, but add a message to let the user know they might have to remove the directory, caution that this should be done with care if this was a pre-existing control directory.try/except
block check if thepath
to create already exists, and in the except block emit the current error message but also clean up the directory that was created.Number 2 seems like the better option. If we know the the directory didn't exist before it seems side-effect free and good practice to clean up an operation that didn't complete cleanly.
Arguably we should check if the destination already exists, because we know it will error and we could give the user some useful advice: clone into a different path, or
cd
into the existing control directory and usepayu checkout
.