diff options
| author | Sandro Jäckel <sandro.jaeckel@gmail.com> | 2023-10-25 16:16:13 +0200 |
|---|---|---|
| committer | Sandro Jäckel <sandro.jaeckel@gmail.com> | 2023-10-25 16:17:57 +0200 |
| commit | eee5e23efe18c59a7e752dc241982947ad186f18 (patch) | |
| tree | 70be6669a48ed268bab66062b22b5c1fdbd19e66 /internal/rtree | |
| parent | f9543a57a8c40e2444715571050824860d127d58 (diff) | |
| download | gofu-eee5e23efe18c59a7e752dc241982947ad186f18.tar.gz | |
Don't add repos which have no remotes
Diffstat (limited to 'internal/rtree')
| -rw-r--r-- | internal/rtree/index.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/internal/rtree/index.go b/internal/rtree/index.go index efc3c1f..ac78d90 100644 --- a/internal/rtree/index.go +++ b/internal/rtree/index.go @@ -152,16 +152,17 @@ func (i *Index) Rebuild() error { remoteURLs = append(remoteURLs, remote.URL.CompactURL()) } + repoPath := filepath.Join(RootPath, repo.CheckoutPath) var selection string if len(remoteURLs) == 0 { selection, err = cli.Interface.Query( - fmt.Sprintf("repository %s has been deleted; no remote to restore from", filepath.Join(RootPath, repo.CheckoutPath)), + fmt.Sprintf("repository %s has been deleted; no remote to restore from", repoPath), cli.Choice{Return: "d", Shortcut: 'd', Text: "delete from index"}, cli.Choice{Return: "s", Shortcut: 's', Text: "skip"}, ) } else { selection, err = cli.Interface.Query( - fmt.Sprintf("repository %s has been deleted", filepath.Join(RootPath, repo.CheckoutPath)), + fmt.Sprintf("repository %s has been deleted", repoPath), cli.Choice{Return: "r", Shortcut: 'r', Text: "restore from " + strings.Join(remoteURLs, " and ")}, cli.Choice{Return: "d", Shortcut: 'd', Text: "delete from index"}, cli.Choice{Return: "s", Shortcut: 's', Text: "skip"}, @@ -193,6 +194,13 @@ func (i *Index) Rebuild() error { //index new repos err := ForeachPhysicalRepo(func(newRepo Repo) error { repo, exists := existingRepos[newRepo.CheckoutPath] + + // if a repo has no remotes, repo is nil which rtree cannot parse back and doesn't make sense to add anyway + if repo == nil || repo.Remotes == nil { + fmt.Printf("repository %s has no remotes; skipping", filepath.Join(RootPath, newRepo.CheckoutPath)) + return nil + } + if exists { //update the existing index entry with the new remotes repo.Remotes = newRepo.Remotes |
