diff options
Diffstat (limited to 'pkg/rtree')
| -rw-r--r-- | pkg/rtree/index.go | 34 | ||||
| -rw-r--r-- | pkg/rtree/main.go | 14 |
2 files changed, 47 insertions, 1 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 +} diff --git a/pkg/rtree/main.go b/pkg/rtree/main.go index 4c8fb98..683daeb 100644 --- a/pkg/rtree/main.go +++ b/pkg/rtree/main.go @@ -38,7 +38,10 @@ func Exec(args []string) { } commandGet(args[1]) case "drop": - panic("unimplemented") + if len(args) != 2 { + usageAndExit() + } + commandDrop(args[1]) case "index": if len(args) != 1 { usageAndExit() @@ -88,6 +91,15 @@ func commandGet(url string) { } } +func commandDrop(url string) { + index := ReadIndex() + repo := index.InteractiveFindRepo(url, false) + if repo != nil { + index.InteractiveDropRepo(repo) + index.Write() + } +} + func commandIndex() { index := ReadIndex() util.FatalIfError(index.InteractiveRebuild()) |
