From 22d80eda906d1958dfde5072717a12995ee6df2d Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Fri, 5 May 2017 20:32:19 +0200 Subject: implement rtree drop rtree is functionally complete, but the implementation is very messy now. :( --- pkg/rtree/index.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'pkg/rtree/index.go') diff --git a/pkg/rtree/index.go b/pkg/rtree/index.go index 2edc452..f6ee2f4 100644 --- a/pkg/rtree/index.go +++ b/pkg/rtree/index.go @@ -108,6 +108,17 @@ func (i *Index) Write() { path := indexPath() util.FatalIfError(os.MkdirAll(filepath.Dir(path), 0755)) util.FatalIfError(ioutil.WriteFile(path, buf, 0644)) + + //perform sanity check (TODO: do this instead when rebuilding the index) + seen := make(map[string]bool) + warned := make(map[string]bool) + for _, repo := range i.Repos { + if seen[repo.CheckoutPath] && !warned[repo.CheckoutPath] { + fmt.Fprintf(os.Stderr, "warning: repo %s appears multiple times in the index file!\n", repo.AbsolutePath()) + warned[repo.CheckoutPath] = true + } + seen[repo.CheckoutPath] = true + } } //InteractiveRebuild implements the `rtree index` subcommand. @@ -235,6 +246,7 @@ func (i *Index) InteractiveFindRepo(remoteURL string, allowClone bool) *Repo { } if !allowClone { + util.ShowError(errors.New("no such remote in index (you can validate the index with `rtree index`)")) return nil } @@ -347,3 +359,25 @@ func (i *Index) InteractiveImportRepo(dirPath string) { util.FatalIfError(repo.Move(checkoutPath, true)) i.Repos = append(i.Repos, &repo) } + +//InteractiveDropRepo deletes the given repo from the rtree and removes it from +//the index. +func (i *Index) InteractiveDropRepo(repo *Repo) { + ok := repo.InteractiveExec("git", "status") + if !ok { + return + } + if !cli.Confirm(">> Drop this repo?") { + return + } + + util.FatalIfError(os.RemoveAll(repo.AbsolutePath())) + + reposNew := make([]*Repo, 0, len(i.Repos)-1) + for _, r := range i.Repos { + if r.CheckoutPath != repo.CheckoutPath { + reposNew = append(reposNew, r) + } + } + i.Repos = reposNew +} -- cgit v1.3.1