josh-project/josh

`fatal: couldn't find remote ref HEAD` on recent versions

Closed this issue · 10 comments

Note: the rm .git command below will break your repository, make sure to use an empty one.

# r23.12.04
$ josh-proxy --local ~/.cache/rust-analyzer-josh/ --remote https://github.com --port 42042 --no-background

$ mkdir foo; cd foo
$ git init
$ git fetch "http://localhost:42042/rust-lang/rust.git@97bf25c8cf6c7c97c851c6e8bc94fd0824885e6f:rev(55d9a533b309119c8acd13061581b43ae8840823:prefix=src/tools/rust-analyzer):/src/tools/rust-analyzer.git"
# does stuff

# clean up a little
$ rm -rf ~/.cache/rust-analyzer-josh/ # need to clear the cache, otherwise it works
# $ rm -rf .git; git init # you can do this to start from scratch, but it's not needed

# b28d490d1683ff8ad5b63333f692ee15f603139c, but also before #1329
$ josh-proxy --local ~/.cache/rust-analyzer-josh/ --remote https://github.com --port 42042 --no-background

$ git fetch "http://localhost:42042/rust-lang/rust.git@97bf25c8cf6c7c97c851c6e8bc94fd0824885e6f:rev(55d9a533b309119c8acd13061581b43ae8840823:prefix=src/tools/rust-analyzer):/src/tools/rust-analyzer.git"
fatal: couldn't find remote ref HEAD

CC rust-lang/rust-analyzer#17025 (comment), @RalfJung.

I'm running it there in my RA clone, but it still seems to reproduce in an empty repository.

rm -rf .git ~/.cache/rust-analyzer-josh/

Can you please remove the .git from this? These are very dangerous commands you are giving us here. I just deleted the .git folder of my josh checkout...

I can confirm, this reproduces here.
It seems to have to do with the @97bf25c8cf6c7c97c851c6e8bc94fd0824885e6f syntax, when I remove that part it works.

git fetch "http://localhost:42042/rust-lang/rust.git:rev(55d9a533b309119c8acd13061581b43ae8840823:prefix=src/tools/rust-analyzer):/src/tools/rust-analyzer.git"

But we need to know which upstream commit we fetched from so that syntax is required for us.

Curiously, after running the command without the @..., then the command with @... also succeeds.

Sorry for that, I added a note at the top.

Clearing .git is entirely irrelevant to reproduce the problem, you can fetch into any repo. So IMO it'd be better to just remove that part.

I would also recommend adding --no-background to the josh invocation as otherwise josh does $STUFF in the background, which makes it "immune" to Ctrl-C and also may affect the issue.

A bisect points at

a22ab2a29699085ad7b0813fd077cb9b73348aa8 is the first bad commit
commit a22ab2a29699085ad7b0813fd077cb9b73348aa8
Author: Christian Schilling <christian.schilling.de@gmail.com>
Date:   Wed Feb 21 17:40:08 2024 +0100

    Don't forward fetches with sha in want (#1313)
    
    Most upstreams don't support this, so it only ever worked
    when the commit was fetched before.
    
    Change: no-sha-want

Cc #1313 @christian-schilling

This has in fact worked properly before at least with github as the remote, so the "it only ever worked" part isn't true.

I'm going to revert #1313 (#1333) it causes more problems than it fixed.

Fixed in #1333, thanks!