1

I have a Go project that uses 2 additional private dependencies. One of them is indirect

MyProj --depends--> MyLib1 --depends--> MyLib2

Problem is when I attempt to go get it returns error like

$ go get my.repo/my-lib1@latest
go: get my.repo/my-lib2@v1.2.3-0.20230320115558-aa11aa11aa11: invalid version: unknown revision aa11aa11aa11

MyProj has go.mod like

require (
    ...
    my.repo/my-lib1 v1.1.1-0.20230714111111-44ff44ff44ff
)

require (
    ...
    my.repo/my-lib2 v1.2.3-0.20230605111111-33bb22bb33bb // indirect
)

At some point MyLib2 was branched out for a new feature. MyLib1 was pointing on this feature branch. Then MyLib2 feature was merged into master and branch was deleted. MyLib1 was also updated to MyLib2's master branch. Schematically it looks like this:

dependencies

And now every time when I have to update MyLib1 to latest, the go get command attempts to fetch deleted branch. Go get command attempts to fetch MyLib1 and MyLib2 GIT repository, tries to cache all commits and fails on pulling deleted MyLib2's aa11aa11aa11 commit. Workaround is to remove indirect MyLib2 from Project's go.mod file and run go mod tidy

How to make go get my.repo/my-lib1@latest to pull only latest revisions of libraries without pulling deleted branches? Is there a way to remove MyLib2's deleted branch aa11aa11aa11 from MyLib1 GIT history so that Go's cache would avoid it?

  • `my-lib1@latest` selects the highest available release version, which is `v1.1.1` (correct?), which most likely points to the old commit. Try to tag a new version for `my-lib1` (for example, `git tag v1.1.2 44ff44ff44ff && git push --tags`). If it does not fix the issue, please share `go.mod` of `my-lib1` and the output of `go get -x my.repo/my-lib1@latest`. – Zeke Lu Jul 19 '23 at 03:40
  • I did tag `my-lib1` to new version but it didn't solve the issue. When I `go clean -modcache` and try to get lib I see that `pkg/mod/cache/download` for `my-lib1` contains `go.mod` files for versions `v1.1.2` and `v1.1.1` – Дмитрий Званчук Jul 19 '23 at 11:02
  • Can you create a reproducer on github? – Zeke Lu Jul 19 '23 at 11:06
  • As for debug output `$ go get -x my.repo/my-lib1@latest` `...` `0.008s # cd /home/user/go/pkg/mod/cache/vcs/1122445566778899aabbccddeeff1234567890abcdef45548118766731130088; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' aa11aa11aa11 --` `# get https://my.repo/my-lib2?go-get=1` `# get https://my.repo/my-lib2?go-get=1: 200 OK (0.350s)` `go: my.repo/my-lib2@v1.2.3-0.20230320115558-aa11aa11aa11: invalid version: unknown revision aa11aa11aa11` The `1122445566...` is GIT repo of `my-lib2` in `vcs` cache – Дмитрий Званчук Jul 19 '23 at 11:06
  • @ZekeLu, thanks for your support. I have started reproducing this issue on GitHub. But then stumbled on this solution and it worked https://stackoverflow.com/questions/3640764/can-i-recover-a-branch-after-its-deletion-in-git – Дмитрий Званчук Jul 19 '23 at 13:21

1 Answers1

0

Solution is to restore deleted branch Can I recover a branch after its deletion in Git?

git checkout -b MyFeature aa11aa11aa11

And then push it and mark as protected to avoid deletion.