diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-05-05 20:32:19 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-05-05 20:32:19 +0200 |
| commit | 22d80eda906d1958dfde5072717a12995ee6df2d (patch) | |
| tree | 2a27f0f621404fce50594a4c5c6ad547cf51e9ab /pkg/rtree/index.go | |
| parent | e1022c29c33363bd3c2471b7cef2d37dbd704dca (diff) | |
| download | gofu-22d80eda906d1958dfde5072717a12995ee6df2d.tar.gz | |
implement rtree drop
rtree is functionally complete, but the implementation is very messy
now. :(
Diffstat (limited to 'pkg/rtree/index.go')
| -rw-r--r-- | pkg/rtree/index.go | 34 |
1 files changed, 34 insertions, 0 deletions
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 +} |
