ezyang / ghstack

Submit stacked diffs to GitHub on the command line

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ghstack can be put into a bad state if PR is not ready to merge

achew22 opened this issue · comments

First, thanks for making such a neat tool! I've been looking for something like this that works with GitHub for a long time. Thanks for doing the hard work to make it real.

Before making this a critical part of my workflow, I wanted to see what happens when I make the inevitable mistakes that I already know I'm going to do. One of the most likely ones I can think of is accidentally copying the wrong PR # in 1 stack and trying to submit the another chain when running land. I set up an experiment where I had an outstanding and unreviewed PR and then I tried landing it immediately, without any review, into the main branch by running

ghstack land $URL_TO_PR

I was hoping that ghstack would error out before attempting anything with some kind of notice like "you need to have this be reviewed before submitting", but it plowed forward with

Now, my repo seems to be in a bad state. When I try to upload, now I get errors like this:

$ git rev-parse origin/gh/achew22/1/head
fatal: ambiguous argument 'origin/gh/achew22/1/head': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
ERROR: Fatal exception
Traceback (most recent call last):
  File "/Users/achew/Projects/ghstack/lib/python3.10/site-packages/ghstack/logs.py", line 107, in manager
    yield
  File "/Users/achew/Projects/ghstack/lib/python3.10/site-packages/ghstack/__main__.py", line 101, in main
    ghstack.submit.main(
  File "/Users/achew/Projects/ghstack/lib/python3.10/site-packages/ghstack/submit.py", line 203, in main
    submitter.prepare_updates()
  File "/Users/achew/Projects/ghstack/lib/python3.10/site-packages/ghstack/submit.py", line 924, in prepare_updates
    self.skip_commit(d)
  File "/Users/achew/Projects/ghstack/lib/python3.10/site-packages/ghstack/submit.py", line 538, in skip_commit
    self.base_commit = GitCommitHash(self.sh.git(
  File "/Users/achew/Projects/ghstack/lib/python3.10/site-packages/ghstack/shell.py", line 273, in git
    return self._maybe_rstrip(self.sh(*(("git",) + args), **kwargs))
  File "/Users/achew/Projects/ghstack/lib/python3.10/site-packages/ghstack/shell.py", line 210, in sh
    raise RuntimeError(
RuntimeError: git rev-parse origin/gh/achew22/1/head failed with exit code 128

I think I understand the git-fu necessary to undo this, which is to delete local references to origin/gh/achew22/1/{head,base,orig} with something like git reflog delete origin/gh/achew22/1/head, but I'm curious if there is a better strategy that can either:

  1. Save me from my inevitable stupidity and prevent this from happening in the future?
  2. Clean it up quickly/easily if the repo state gets messed up again.

Thanks so much!

There's a feature request to have ghstack check review status and review to land if not reviewed; I'd be quite happy to take a patch that does this by default.

ghstack deletes the branches after landing, which means it's invalid to try to use the same PR again. You can use ghstack unlink to unlink your commit with the PR, so that when you submit it it gets a new PR.

Improved remediation at #191