--- a/govcs.go Tue Dec 05 21:19:23 2017 -0600
+++ b/govcs.go Tue Dec 05 21:55:16 2017 -0600
@@ -18,6 +18,8 @@
"bitbucket.org/rw_grim/govcs/git"
"bitbucket.org/rw_grim/govcs/hg"
"bitbucket.org/rw_grim/govcs/vcs"
@@ -30,17 +32,19 @@
+ ErrNoRepositoryFound = errors.New("no repository found") // Detect will try to determine what version control system is in use in the
// given working directory and return a vcs.VCS instance for it.
-func Detect(wd string) vcs.VCS {
+func Detect(wd string) (vcs.VCS, error) { for _, detector := range detectors {
+ return nil, ErrNoRepositoryFound --- a/govcs_test.go Tue Dec 05 21:19:23 2017 -0600
+++ b/govcs_test.go Tue Dec 05 21:55:16 2017 -0600
@@ -62,8 +62,9 @@
backend := s.setup("git", exec.NewMockCommand("found", nil))
defer exec.SetBackend(backend)
- vcs := Detect("working-directory")
+ vcs, err := Detect("working-directory") Expect(vcs).ToNot(BeNil())
+ Expect(err).To(BeNil()) @@ -74,10 +75,20 @@
backend := s.setup("hg", exec.NewMockCommand("found", nil))
defer exec.SetBackend(backend)
- vcs := Detect("working-directory")
+ vcs, err := Detect("working-directory") Expect(vcs).ToNot(BeNil())
+ Expect(err).To(BeNil()) m, ok := vcs.(*hg.Mercurial)
Expect(m).To(BeAssignableToTypeOf(&hg.Mercurial{}))
+func (s *vcsSuite) TestFindNoRepository(t sweet.T) { + backend := s.setup("", exec.NewMockCommand("", errors.New("not a repo"))) + defer exec.SetBackend(backend) + vcs, err := Detect("working-directory") + Expect(vcs).To(BeNil()) + Expect(err).To(MatchError(ErrNoRepositoryFound))