aboutsummaryrefslogtreecommitdiff
path: root/pkg/rtree/repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/rtree/repo.go')
-rw-r--r--pkg/rtree/repo.go30
1 files changed, 30 insertions, 0 deletions
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 {