aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/git
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-05-14 11:17:23 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-05-14 11:17:23 +0200
commit5060be1a90deea0312106fa2bf21ab7357aa86cd (patch)
treecfc0d983068231e395b4e114158163840e12f09d /pkg/git
parentd39e52252cdeaff548aaba08e14d332af02ab13f (diff)
pkg/git: add SwitchCommit and GetCommit
Will be useful for bisection logic. Update #501
Diffstat (limited to 'pkg/git')
-rw-r--r--pkg/git/git.go11
1 files changed, 10 insertions, 1 deletions
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
}