Skip to content

Commit 19510da

Browse files
committed
more helpers
1 parent d86a90f commit 19510da

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

commit.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ type Commit struct {
2424
// submodules map[string]*SubModule
2525
}
2626

27+
func (c *Commit) GetCommitOfRelPath(relpath string) (*Commit, error) {
28+
return c.repo.getCommitOfRelPath(c.ID, relpath)
29+
}
30+
2731
// AddAllChanges marks local changes to be ready for commit.
2832
func AddChanges(repoPath string, all bool, files ...string) error {
2933
cmd := NewCommand("add")

repo_commit.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ func (repo *Repository) GetCommitOfBranch(branch string) (*Commit, error) {
122122
return repo.GetCommit(commitID)
123123
}
124124

125+
func (repo *Repository) getCommitOfRelPath(id sha1, relpath string) (*Commit, error) {
126+
stdout, err := NewCommand("log", "-1", _PRETTY_LOG_FORMAT, id.String(), "--", relpath).RunInDir(repo.Path)
127+
if err != nil {
128+
return nil, err
129+
}
130+
131+
id, err = NewIDFromString(stdout)
132+
if err != nil {
133+
return nil, err
134+
}
135+
136+
return repo.getCommit(id)
137+
}
138+
125139
// GetCommitByPath returns the last commit of relative path.
126140
func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
127141
stdout, err := NewCommand("log", "-1", _PRETTY_LOG_FORMAT, "--", relpath).RunInDirBytes(repo.Path)

0 commit comments

Comments
 (0)