From 5060be1a90deea0312106fa2bf21ab7357aa86cd Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 14 May 2018 11:17:23 +0200 Subject: pkg/git: add SwitchCommit and GetCommit Will be useful for bisection logic. Update #501 --- pkg/git/git.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'pkg/git') diff --git a/pkg/git/git.go b/pkg/git/git.go index ed7bc3a77..6464dc5eb 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -85,6 +85,11 @@ func CheckoutCommit(dir, repo, commit string) (*Commit, error) { if err != nil { return nil, err } + return SwitchCommit(dir, commit) +} + +// SwitchCommit checkouts the specified commit without fetching. +func SwitchCommit(dir, commit string) (*Commit, error) { if _, err := runSandboxed(dir, "git", "checkout", commit); err != nil { return nil, err } @@ -128,7 +133,11 @@ type Commit struct { // HeadCommit returns info about the HEAD commit of the current branch of git repository in dir. func HeadCommit(dir string) (*Commit, error) { - output, err := runSandboxed(dir, "git", "log", "--pretty=format:%H%n%s%n%ad", "-n", "1") + return GetCommit(dir, "HEAD") +} + +func GetCommit(dir, commit string) (*Commit, error) { + output, err := runSandboxed(dir, "git", "log", "--pretty=format:%H%n%s%n%ad", "-n", "1", commit) if err != nil { return nil, err } -- cgit mrf-deployment