From c69e9f604c47469429a6a8a27ba7ef873134e0a1 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Tue, 2 May 2017 23:05:09 +0200 Subject: initial implementation of "rtree get" command --- pkg/rtree/repo.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'pkg/rtree/repo.go') diff --git a/pkg/rtree/repo.go b/pkg/rtree/repo.go index f231d0a..93ab9d2 100644 --- a/pkg/rtree/repo.go +++ b/pkg/rtree/repo.go @@ -95,6 +95,20 @@ func NewRepoFromAbsolutePath(path string) (repo Repo, err error) { return } +//NewRepoFromRemoteURL initializes a Repo instance for checking out a remote +//for the first time. The checkout does not happen until Checkout() is called. +func NewRepoFromRemoteURL(remoteURL string) Repo { + return Repo{ + CheckoutPath: CheckoutPathForRemoteURL(ExpandRemoteURL(remoteURL)), + Remotes: []Remote{ + { + Name: "origin", + URL: remoteURL, + }, + }, + } +} + var remoteConfigRx = regexp.MustCompile(`remote\.([^=]+)\.url=(.+)`) //ForeachPhysicalRepo walks over the repository tree, executing the action @@ -127,6 +141,22 @@ func ForeachPhysicalRepo(action func(repo Repo) error) error { }) } +//ExistsOnDisk returns true if the top directory of this repo exists. +func (r Repo) ExistsOnDisk() bool { + path := r.AbsolutePath() + fi, err := os.Stat(path) + if err == nil { + if !fi.IsDir() { + util.FatalIfError(fmt.Errorf("expected %s to be a directory, but it is not", path)) + } + return true + } + if !os.IsNotExist(err) { + util.FatalIfError(err) + } + return false +} + //Checkout creates the repo in the given path with the given remotes. The //working copy will only be initialized if there is an "origin" remote. func (r Repo) Checkout() error { -- cgit v1.3.1