Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit fbe468c

Browse files
adelowozeripath
authored andcommitted
get branch from commit sha1 (#142)
1 parent d04f81a commit fbe468c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

commit.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
// Commit represents a git commit.
2020
type Commit struct {
21+
Branch string // Branch this commit belongs to
2122
Tree
2223
ID SHA1 // The ID of this commit object
2324
Author *Signature

repo_commit.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strconv"
1111
"strings"
1212

13-
"github.com/mcuadros/go-version"
13+
version "github.com/mcuadros/go-version"
1414
)
1515

1616
// GetRefCommitID returns the last commit ID string of given reference (branch or tag).
@@ -130,6 +130,14 @@ func (repo *Repository) getCommit(id SHA1) (*Commit, error) {
130130
commit.repo = repo
131131
commit.ID = id
132132

133+
data, err = NewCommand("name-rev", id.String()).RunInDirBytes(repo.Path)
134+
if err != nil {
135+
return nil, err
136+
}
137+
138+
// name-rev commitID ouput will be "COMMIT_ID master" or "COMMIT_ID master~12"
139+
commit.Branch = strings.Split(strings.Split(string(data), " ")[1], "~")[0]
140+
133141
repo.commitCache.Set(id.String(), commit)
134142
return commit, nil
135143
}

0 commit comments

Comments
 (0)