`pcs.Repo`'s `_check_for_github_url()` and `_check_remote_branch_status()` fail when locally cached repo has floating head (i.e., no branch checked out)
Closed this issue · 2 comments
@nickjalbert I'm hitting a bug when trying to use your WIP PR #370 which is surfacing because the OpenAI github repo gets initially checked without being on a specific branch, i.e.,
> cd /Users/andyk/.agentos/cache/repos_cache/openai/gym.git/4ede9280f9c477f1ca09929d10cdc1e1ba1129f1
> git branch
* (no branch)
master
This causes an error in our code that checks if the current remote for the repo contains "github" or not. The code is here:
Line 175 in 9e4428b
We use:
try:
remote, url = porcelain.get_remote_repo(self.porcelain_repo)
except IndexError:
<this is getting run>
...and I don't think that porcelain function get_remote_repo can handle the case where the branch in the repo is floating, since it ultimately ends up running this code in dulwich/porcelain.py
.
...which is where our IndexError is getting raised. Which makes sense because the repo isn't on an active branch (because we checked out a specific git commit hash)
It's this specific dulwich line that checks to see that we aren't on a floating HEAD:
active_ref = r.refs.follow(b"HEAD")[0][1]
...since the first element of the tuple that refs.follow() returns (i.e. r.refs.follow(b"HEAD")[0]) is a list of the symbolic references that were followed to get to the git hash id. And if there is no branch checked out (i.e. if HEAD is floating), then that list only has one element, thus IndexError.
I'm a little surprised we haven't hit this before, but actually, it might be because of the recent change to how we use checkout()
.
The same problem seems to exist in _check_remote_branch_status
:
Line 190 in 9e4428b
I believe the script being run here is a slightly modified version of documentation/demos/demo_papag_in_py_repl.py
.
#379 should fix this, you can give it a try in my current working branch nj_ilya_bench3
!
Fixed in #379