diff --git a/repository/factory.go b/repository/factory.go index ea03043..2cb40ea 100644 --- a/repository/factory.go +++ b/repository/factory.go @@ -57,6 +57,7 @@ type SCM interface { Fetch() (err error) Branch(name string) (err error) Commit(files []string, msg string) (err error) + Head() (commit string, err error) } // Remote repository. diff --git a/repository/git.go b/repository/git.go index d9703af..1c33098 100644 --- a/repository/git.go +++ b/repository/git.go @@ -118,6 +118,21 @@ func (r *Git) Commit(files []string, msg string) (err error) { return r.push() } +// Head returns HEAD commit. +func (r *Git) Head() (commit string, err error) { + cmd := command.New("/usr/bin/git") + cmd.Dir = r.Path + cmd.Options.Add("rev-parse") + cmd.Options.Add("HEAD") + err = cmd.Run() + if err != nil { + return + } + commit = string(cmd.Output()) + commit = strings.TrimSpace(commit) + return +} + // push changes to remote. func (r *Git) push() (err error) { cmd := command.New("/usr/bin/git") diff --git a/repository/subversion.go b/repository/subversion.go index 92ae4e5..5344dcc 100644 --- a/repository/subversion.go +++ b/repository/subversion.go @@ -143,6 +143,12 @@ func (r *Subversion) Commit(files []string, msg string) (err error) { return } +// Head returns latest commit. +func (r *Subversion) Head() (commit string, err error) { + // TODO: needs implementation. + return +} + // URL returns the parsed URL. func (r *Subversion) URL() (u *urllib.URL) { u, _ = urllib.Parse(r.Remote.URL)