grim/govcs

77caf60cb0bf
Parents 11a3dcfb973b
Children 164e2634eddc
Add support for getting the root of the repository
--- a/git/git.go Tue Dec 05 21:55:16 2017 -0600
+++ b/git/git.go Tue Dec 05 22:15:21 2017 -0600
@@ -55,6 +55,11 @@
return g.runCmd([]string{"config", "--local", "remote." + name + ".url"})
}
+// Root will return the root of the repository.
+func (g *Git) Root() string {
+ return g.runCmd([]string{"rev-parse", "--show-toplevel"})
+}
+
// Commit will return the commit id of the repository.
func (g *Git) Commit() string {
return g.runCmd([]string{"rev-parse", "HEAD"})
--- a/git/git_test.go Tue Dec 05 21:55:16 2017 -0600
+++ b/git/git_test.go Tue Dec 05 22:15:21 2017 -0600
@@ -86,6 +86,15 @@
Expect(git.Remote("upstream")).To(Equal("https://bitbucket.org/rw_grim/covcs2"))
}
+func (s *gitSuite) TestRoot(t sweet.T) {
+ path := "/home/foo/go/src/github.com/bar/baz"
+ backend := s.setup(exec.NewMockCommand(path+"\n", nil))
+ defer exec.SetBackend(backend)
+
+ git := Git{}
+ Expect(git.Root()).To(Equal(path))
+}
+
func (s *gitSuite) TestCommit(t sweet.T) {
backend := s.setup(exec.NewMockCommand("deadbeef", nil))
defer exec.SetBackend(backend)
--- a/hg/hg.go Tue Dec 05 21:55:16 2017 -0600
+++ b/hg/hg.go Tue Dec 05 22:15:21 2017 -0600
@@ -64,6 +64,11 @@
return ""
}
+// Root will return the root of the repository.
+func (m *Mercurial) Root() string {
+ return m.runCmd([]string{"root"})
+}
+
// Commit will return the commit id of the repository.
func (m *Mercurial) Commit() string {
return m.runLog("{node}")
--- a/hg/hg_test.go Tue Dec 05 21:55:16 2017 -0600
+++ b/hg/hg_test.go Tue Dec 05 22:15:21 2017 -0600
@@ -86,6 +86,15 @@
Expect(hg.Remote("upstream")).To(Equal("myupstream"))
}
+func (s *hgSuite) TestRoot(t sweet.T) {
+ path := "/home/foo/go/src/bitbucket.org/bar/baz"
+ backend := s.setup(exec.NewMockCommand(path+"\n", nil))
+ defer exec.SetBackend(backend)
+
+ hg := Mercurial{}
+ Expect(hg.Root()).To(Equal(path))
+}
+
func (s *hgSuite) TestCommit(t sweet.T) {
backend := s.setup(exec.NewMockCommand("deadbeef", nil))
defer exec.SetBackend(backend)
--- a/vcs/vcs.go Tue Dec 05 21:55:16 2017 -0600
+++ b/vcs/vcs.go Tue Dec 05 22:15:21 2017 -0600
@@ -23,6 +23,9 @@
// the default for the version control system will be used.
Remote(name string) string
+ // Root will return the root of the repository.
+ Root() string
+
// Commit returns the current commit id of repository.
Commit() string