cli icon indicating copy to clipboard operation
cli copied to clipboard

`pr create` push detection should work in repositories that are tracking only a single branch

Open jwodder opened this issue 5 years ago • 6 comments

I have a shell script that is run as part of a GitHub Actions workflow that, on occasion, clones a repository, creates, commits to, and pushes a branch, and then creates (or at least tries to) a pull request for the branch using gh pr create. However, gh is failing with "aborted: you must first push the current branch to a remote, or use the --head flag" despite the fact that the command immediately before it is "git push -u origin "$branch_name" (tried with & without the -u option).

  • The repository is public.
  • The remote URL used to check out the repository is of the form https://x-access-token:[email protected]/$OWNER/$REPO, where the same token is also set as the $GITHUB_TOKEN environment variable.
  • The command succeeds if the --head option is used.

jwodder avatar Feb 16 '21 13:02 jwodder

Thanks for reporting!

  1. After you push the branch, is the remote-tracking branch created? Check with cat .git/refs/remotes/origin/<branch-name>
  2. Do you have multiple git remotes in this repository?
  3. Is your gh up-to-date?

mislav avatar Feb 16 '21 15:02 mislav

@mislav

  1. I can't check now, but I assume that the remote tracking branch is created when using git push with the -u option
  2. No.
  3. It's whatever version is currently on the Github Actions ubuntu-latest (18.04.5) image (According to this page, version 1.5.0).

jwodder avatar Feb 16 '21 15:02 jwodder

@mislav OK, I set up this workflow as an MVCE. The run fails on your cat command, so apparently the remote tracking branch is not getting created. That is not how I understand Git to work; do you know how to fix this?

EDIT: OK, I fixed it. The problem was due to the use of --depth 1, and adding --no-single-branch to the git clone command got rid of the error.

jwodder avatar Feb 16 '21 15:02 jwodder

@jwodder Thank you for checking! I will reopen this and keep it filed as a bug report because I believe that ideally, pr create should work even in repositories that were cloned with --depth 1 or are tracking just a single branch.

mislav avatar Feb 17 '21 11:02 mislav

I just try to use the --depth 1 when creating a PR right after. It still fails :( I think it's a really important thing as some repo can be huge and take a few minutes to clone

vschoener avatar May 03 '22 14:05 vschoener

Perhaps worth mentioning, Since git release 1.8.3.2, using --depth ignores remote branches unless --no-single-branch is also specified.

StevenACoffman avatar Jul 29 '22 18:07 StevenACoffman