Skip to content

Commit 93a9b9e

Browse files
committed
Closes #43: Detect when tool not installed
1 parent 4de1ea1 commit 93a9b9e

File tree

6 files changed

+36
-0
lines changed

6 files changed

+36
-0
lines changed

bzr.go

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ var bzrDetectURL = regexp.MustCompile("parent branch: (?P<foo>.+)\n")
1616
// NewBzrRepo creates a new instance of BzrRepo. The remote and local directories
1717
// need to be passed in.
1818
func NewBzrRepo(remote, local string) (*BzrRepo, error) {
19+
ins := depInstalled("bzr")
20+
if !ins {
21+
return nil, NewLocalError("bzr is not installed", nil, "")
22+
}
1923
ltype, err := DetectVcsFromFS(local)
2024

2125
// Found a VCS other than Bzr. Need to report an error.

git.go

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import (
1414
// NewGitRepo creates a new instance of GitRepo. The remote and local directories
1515
// need to be passed in.
1616
func NewGitRepo(remote, local string) (*GitRepo, error) {
17+
ins := depInstalled("git")
18+
if !ins {
19+
return nil, NewLocalError("git is not installed", nil, "")
20+
}
1721
ltype, err := DetectVcsFromFS(local)
1822

1923
// Found a VCS other than Git. Need to report an error.

hg.go

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ var hgDetectURL = regexp.MustCompile("default = (?P<foo>.+)\n")
1414
// NewHgRepo creates a new instance of HgRepo. The remote and local directories
1515
// need to be passed in.
1616
func NewHgRepo(remote, local string) (*HgRepo, error) {
17+
ins := depInstalled("hg")
18+
if !ins {
19+
return nil, NewLocalError("hg is not installed", nil, "")
20+
}
1721
ltype, err := DetectVcsFromFS(local)
1822

1923
// Found a VCS other than Hg. Need to report an error.

repo.go

+8
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,11 @@ NextVar:
257257
}
258258
return out
259259
}
260+
261+
func depInstalled(name string) bool {
262+
if _, err := exec.LookPath(name); err != nil {
263+
return false
264+
}
265+
266+
return true
267+
}

repo_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,15 @@ func TestTypeSwitch(t *testing.T) {
6060
t.Errorf("Not detecting repo switch from SVN to Git")
6161
}
6262
}
63+
64+
func TestDepInstalled(t *testing.T) {
65+
i := depInstalled("git")
66+
if i != true {
67+
t.Error("depInstalled not finding installed dep.")
68+
}
69+
70+
i = depInstalled("thisreallyisntinstalled")
71+
if i != false {
72+
t.Error("depInstalled finding not installed dep.")
73+
}
74+
}

svn.go

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import (
1515
// For example, if the package is https://github.com/Masterminds/cookoo/ the remote
1616
// should be https://github.com/Masterminds/cookoo/trunk for the trunk branch.
1717
func NewSvnRepo(remote, local string) (*SvnRepo, error) {
18+
ins := depInstalled("svn")
19+
if !ins {
20+
return nil, NewLocalError("svn is not installed", nil, "")
21+
}
1822
ltype, err := DetectVcsFromFS(local)
1923

2024
// Found a VCS other than Svn. Need to report an error.

0 commit comments

Comments
 (0)