python / cherry-picker

πŸπŸ’β› Utility script for backporting/cherry-picking CPython changes from master into one of the maintenance branches.
Apache License 2.0
46 stars 38 forks source link

"You're not inside a cpython repo right now! πŸ™…" says cherry_picker when I'm in my cpython git repo #99

Open gpshead opened 7 months ago

gpshead commented 7 months ago
python/cpython/gpshead (main)$ cherry_picker a6c1c04d4d2339f0094422974ae3f26f8c7c8565 3.12 --upstream-remote=upstream --pr-remote=origin
🐍 πŸ’ ⛏
You're not inside a cpython repo right now! πŸ™…
python/cpython/gpshead (main)$ cherry_picker --version
cherry_picker, version 2.2.0

It appears that some validation logic was added that doesn't take actual git clone configurations into account.

That logic appears to have been there "forever" (5 years per Blame) but there was a recent change a month-ish ago to the https://github.com/python/cherry-picker/commit/b471da1bebb6de160e34f7127ceaa5b20b600434 that added a get_state_and_verify() call to check_repo(). Related?

The other issue aside from the bug is that the error message is inaccurate and thus unhelpful - It does not provide full details on exactly what it thinks is amiss in the state is detected vs exactly what state expects so I can't tell anything about the nature of the bug or if there's something simple I could do given I am within a git clone of cpython with many remote repos and branches that I've been using for years.

Getting overly creative with pdb, the error message that was suppressed was apparently:

ValueError: Run state cherry-picker.state=BACKPORT_LOOP_START in Git config is not known.
Perhaps it has been set by a newer version of cherry-picker. Try upgrading.
Valid states are: BACKPORT_PAUSED, UNSET. If this looks suspicious, raise an issue at https://github.com/python/cherry-picker/issues/new.
As the last resort you can reset the runtime state stored in Git config using the following command: `git config --local --remove-section cherry-picker`
hugovk commented 7 months ago

Are you using Git worktrees? Maybe it doesn't know how to checkout branches already checked out in other directories.

If so, does it work when you cd to the 3.12 worktree dir first?

gpshead commented 7 months ago

See the swallowed ValueError at the bottom. it was leftover cherry-picker state from some earlier forcably abandoned run due to whatever other things i was hitting.

dpr-0 commented 7 months ago

I use version 2.2.0 cherry_picker and git version 2.39.3 (Apple Git-145). After I run cherry_picker --continue fail, than I saw You're not inside a cpython repo right now! πŸ™… Here is my error message.

Β» cherry_picker --continue
🐍 πŸ’ ⛏
Traceback (most recent call last):
  File "/opt/homebrew/bin/cherry_picker", line 8, in <module>
    sys.exit(cherry_pick_cli())
             ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/cherry_picker/cherry_picker.py", line 802, in cherry_pick_cli
    cherry_picker.continue_cherry_pick()
  File "/opt/homebrew/lib/python3.11/site-packages/cherry_picker/cherry_picker.py", line 591, in continue_cherry_pick
    commits = get_commits_from_backport_branch(base)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/cherry_picker/cherry_picker.py", line 902, in get_commits_from_backport_branch
    output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', 'log', '--format=%H', '3.11..']' returned non-zero exit status 128.
skirpichev commented 7 months ago

@dpr-0, try to look to the .git/config: probably it has some remnants of cherry-picker.state (like BACKPORT_LOOP_START above). Removing related section from that file was a solution for me.

dpr-0 commented 7 months ago

@dpr-0, try to look to the .git/config: probably it has some remnants of cherry-picker.state (like BACKPORT_LOOP_START above). Removing related section from that file was a solution for me.

I have removed it and re-run cherry_picker but I still get subprocess.CalledProcessError like above.

aloisklink commented 5 months ago

subprocess.CalledProcessError: Command '['git', 'log', '--format=%H', '3.11..']' returned non-zero exit status 128.

I had a similar error, since the 3.11 branch did not exist in my local repo. I had to first create the branch with git switch 3.11 (which then printed a message like Branch '3.11' set up to track remote branch '3.11' from 'origin'.

hugovk commented 5 months ago

I suggest we remove the "You're not inside a cpython repo right now! πŸ™…" handling and let the original exception and message bubble up and be displayed.

belm0 commented 4 months ago

I had a similar error, since the 3.11 branch did not exist in my local repo. I had to first create the branch with git switch 3.11 (which then printed a message like Branch '3.11' set up to track remote branch '3.11' from 'origin'.

This worked for me. Shouldn't cherry_picker take care of checking out the release branch?

steverep commented 4 months ago

I got this error and now I cannot get it to go away. Tried adding the remote tracking branches which didn't help. Tried completely removing the backport branch and starting over, still get the error. 😞

belm0 commented 4 months ago

I got this error and now I cannot get it to go away. Tried adding the remote tracking branches which didn't help. Tried completely removing the backport branch and starting over, still get the error. 😞

remove cherry-picker state in .git/config

jaraco commented 3 months ago

I ran into this issue today also. I'd run cherry_picker, then resolved a conflict, then mistakenly committed the change. From there, I tried to --continue, but got an error, then tried to clean things up by deleting the branch, but got stuck on the "not inside a cpython repo" error.

 cpython main @ git-id
3f54d1cfe7
 cpython main @ cherry_picker a2548077614f81f25a2c3465dabb7a0a3885c40c 3.11
🐍 πŸ’ ⛏
You're not inside a cpython repo right now! πŸ™…

I was able to bypass the error by manually cleaning up the .git/config.

jaraco commented 3 months ago

I had a similar error, since the 3.11 branch did not exist in my local repo. I had to first create the branch with git switch 3.11 (which then printed a message like Branch '3.11' set up to track remote branch '3.11' from 'origin'.

This worked for me. Shouldn't cherry_picker take care of checking out the release branch?

I ran into this issue also, but the workaround didn't work for me. I was in the middle of a cherry pick, so couldn't switch to 3.11. I couldn't --abort because of the "not inside" error.

serhiy-storchaka commented 3 months ago

I ran into this issue just now.

119 at least provides more info:

🐍 πŸ’ ⛏
You're not inside a cpython repo right now! πŸ™…
Run state cherry-picker.state=CONTINUATION_STARTED in Git config is not known.
Perhaps it has been set by a newer version of cherry-picker. Try upgrading.
Valid states are: BACKPORT_PAUSED, UNSET. If this looks suspicious, raise an issue at https://github.com/python/cherry-picker/issues/new.
As the last resort you can reset the runtime state stored in Git config using the following command: `git config --local --remove-section cherry-picker`
pitrou commented 3 months ago

remove cherry-picker state in .git/config

This worked for me to suppress the error, but this workaround should be mentioned somewhere in the error message.

ncoghlan commented 4 weeks ago

Just ran into this the exact same way that @jaraco did: resolving a conflict and committing the result.

It's really easy to do when using VSCode, since the conflict resolution UI in there just naturally leads into committing when you've resolved everything.

xyb commented 2 weeks ago

I ran into this issue also. I'm working on my forked cpython repo, but I faced same error message even I'm already added upstream as a remote. Thanks @aloisklink the git switch 3.13 trick saved me. I think cherry-picker should switch to the target branch automatically if it doesn't exist in this situation.