Skip to content

Commit c6811c0

Browse files
committed
Detect when a submodule repo can't be fetched from.
In my case this was caused by a refs/remote/origin/HEAD ref referring to origin/master, after origin/master was renamed to origin/main. More generally, this will print a louder and more explicit error if go-git is refusing to fetch for some reason other than the ref not existing. go-git/go-git#165
1 parent d377420 commit c6811c0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

subtrac/subtrac.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,17 @@ func (c *Cache) tryFetchFromSubmodules(path string, hash plumbing.Hash) (*NotPre
483483
if err != nil {
484484
return nil, fmt.Errorf("submodule %v: CreateRemote: %v", absremotename, err)
485485
}
486+
_, err = remote.List(&git.ListOptions{})
487+
if err != nil {
488+
return nil, fmt.Errorf("submodule %v: List() failed, repo corrupted! %v", absremotename, err)
489+
}
486490
err = remote.Fetch(&git.FetchOptions{
487491
RemoteName: "anonymous",
488492
RefSpecs: []config.RefSpec{
489493
config.RefSpec(brrefname + ":TRAC_FETCH_HEAD"),
490494
},
491495
})
492-
if err != nil {
496+
if err != nil && err != git.NoErrAlreadyUpToDate {
493497
return nil, fmt.Errorf("submodule %v: fetch: %v", absremotename, err)
494498
}
495499
// Fetch worked!

0 commit comments

Comments
 (0)