Description
I've run across people / repositories where they have workflows that for varying reasons end up asking the checkout
action (typically actions/checkout@v4
) for a branch/tag/reference that doesn't exist:
If one uses git
directly:
Cloning into 'checkout-missing-reference-0'...
warning: Could not find remote branch hello-world to clone.
fatal: Remote branch hello-world not found in upstream origin
Error: Process completed with exit code 128
If one uses actions/checkout@v4
, one sees exit code 1
but this isn't particularly helpful:
Fetching the repository
/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +refs/heads/hello-world*:refs/remotes/origin/hello-world* +refs/tags/hello-world*:refs/tags/hello-world*
The process '/usr/bin/git' failed with exit code 1
Waiting 15 seconds before trying again
/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +refs/heads/hello-world*:refs/remotes/origin/hello-world* +refs/tags/hello-world*:refs/tags/hello-world*
The process '/usr/bin/git' failed with exit code 1
Waiting 20 seconds before trying again
/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +refs/heads/hello-world*:refs/remotes/origin/hello-world* +refs/tags/hello-world*:refs/tags/hello-world*
Error: The process '/usr/bin/git' failed with exit code 1
Note that users are using actions/checkout@v4
, they aren't using git ... fetch
and there's no reason to expect end users to understand implementation details of git ... fetch
-- that's why they're using actions/checkout@...
.
It is possible to improve the user experience -- consider these changes:
/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +refs/heads/hello-world*:refs/remotes/origin/hello-world* +refs/tags/hello-world*:refs/tags/hello-world*
The process '/usr/bin/git' failed with exit code 1
Waiting 10 seconds before trying again
/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +refs/heads/hello-world*:refs/remotes/origin/hello-world* +refs/tags/hello-world*:refs/tags/hello-world*
The process '/usr/bin/git' failed with exit code 1
Waiting 14 seconds before trying again
/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin +refs/heads/hello-world*:refs/remotes/origin/hello-world* +refs/tags/hello-world*:refs/tags/hello-world*
/usr/bin/git -c protocol.version=2 ls-remote origin +refs/heads/hello-world*:refs/remotes/origin/hello-world* +refs/tags/hello-world*:refs/tags/hello-world*
Warning: No objects found matching refSpec +refs/heads/hello-world*:refs/remotes/origin/hello-world*,+refs/tags/hello-world*:refs/tags/hello-world* -- this is why checkout failed
Error: The process '/usr/bin/git' failed with exit code 1
https://github.com/check-spelling-sandbox/checkout-missing-reference-0/actions/runs/8694496977
Note: the error handling and reporting is much better when a repository doesn't exist.