Skip to content

gh pr merge fails to delete remote branch if $PWD is not a git repository #2833

@joe-sharp

Description

@joe-sharp

Describe the bug

I wanted to quick merge a PR I had a link to and didn't bother changing directories, so I ran the merge from my home directory. I am not sure what would have happened if I was in different repository at the time, but needless to say my home directory is not a git repository. I hoped I would still be able to merge and to my delight I could, but I got an error trying to delete the local branch and as a result the remote branch was not deleted.

~ $ gh --version
gh version 1.5.0 (2021-01-21)
https://github.com/cli/cli/releases/tag/v1.5.0

Steps to reproduce the behavior

  1. Type this gh pr merge <pull request url>, from home directory (not a git repo)
  2. Choose to delete remote and local (despite only really wanting to delete remote)
  3. See error could not determine current branch: fatal: not a git repository (or any of the parent directories): .git /usr/bin/git: exit status 128

Expected vs actual behavior

The remote branch was not deleted, presumably because it tries to remove the local one first and fails.
I would expect it to delete the remote anyway. If that is undesirable for reasons I hadn't considered it would be nice to have a remote-only delete or to have only been prompted for a remote delete since I was not in a repo.

Logs

~ $ gh pr merge https://github.com/joe-sharp/old-arduino-projects/pull/3
? What merge method would you like to use? Create a merge commit
? Delete the branch locally and on GitHub? Yes
? Submit? Yes
✔ Merged pull request #3 (Update README.md)
could not determine current branch: fatal: not a git repository (or any of the parent directories): .git
/usr/bin/git: exit status 128

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority-2Affects more than a few users but doesn't prevent core functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions