From 3f702c6f95921a3238e8910a1bc9145f03ec6e2d Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Fri, 22 Nov 2024 07:46:04 -0800 Subject: [PATCH] :sparkes: implement Subversion.Head(). Signed-off-by: Jeff Ortel --- repository/subversion.go | 21 +++++++++++++++++++-- repository/svn_test.go | 15 --------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/repository/subversion.go b/repository/subversion.go index 8773ece..ba73633 100644 --- a/repository/subversion.go +++ b/repository/subversion.go @@ -7,6 +7,7 @@ import ( urllib "net/url" "os" pathlib "path" + "regexp" "strings" liberr "github.com/jortel/go-utils/error" @@ -16,6 +17,9 @@ import ( "github.com/konveyor/tackle2-hub/nas" ) +// RevisionRegex match revision embedded in `svn info`. +var RevisionRegex = regexp.MustCompile(`(Revision\:\s+)([\d]+)`) + // Subversion repository. type Subversion struct { Authenticated @@ -115,9 +119,22 @@ func (r *Subversion) Commit(files []string, msg string) (err error) { return } -// Head returns latest commit. +// Head returns the current revision. func (r *Subversion) Head() (commit string, err error) { - // TODO: needs implementation. + cmd := r.svn() + cmd.Dir = r.root() + cmd.Options.Add("info", "-r", "HEAD") + err = cmd.Run() + if err != nil { + return + } + output := cmd.Output() + m := RevisionRegex.FindStringSubmatch(string(output)) + if len(m) == 3 { + commit = m[2] + } else { + err = liberr.New("[SVN] info parser failed.") + } return } diff --git a/repository/svn_test.go b/repository/svn_test.go index 8df29e3..19d4878 100644 --- a/repository/svn_test.go +++ b/repository/svn_test.go @@ -22,18 +22,3 @@ func TestSvnURL(t *testing.T) { expectStr := "http://svn.corp/project/trunk/eng/product/thing/app_1" g.Expect(expectStr).To(gomega.Equal(s)) } - -func TestSvnFetch(t *testing.T) { - //g := gomega.NewGomegaWithT(t) - remote := Remote{ - URL: "http://svn.corp/project", - Branch: "trunk", - Path: "eng/product/thing/app_1", - } - // Load. - r := Subversion{ - Remote: remote, - Path: "/tmp/svn/test", - } - r.checkout() -}