1
0
mirror of https://github.com/go-gitea/git.git synced 2026-02-05 06:45:03 +01:00

more helpers

This commit is contained in:
Unknwon
2015-11-27 02:15:42 -05:00
parent d86a90f801
commit 19510da781
2 changed files with 18 additions and 0 deletions

View File

@@ -24,6 +24,10 @@ type Commit struct {
// submodules map[string]*SubModule
}
func (c *Commit) GetCommitOfRelPath(relpath string) (*Commit, error) {
return c.repo.getCommitOfRelPath(c.ID, relpath)
}
// AddAllChanges marks local changes to be ready for commit.
func AddChanges(repoPath string, all bool, files ...string) error {
cmd := NewCommand("add")

View File

@@ -122,6 +122,20 @@ func (repo *Repository) GetCommitOfBranch(branch string) (*Commit, error) {
return repo.GetCommit(commitID)
}
func (repo *Repository) getCommitOfRelPath(id sha1, relpath string) (*Commit, error) {
stdout, err := NewCommand("log", "-1", _PRETTY_LOG_FORMAT, id.String(), "--", relpath).RunInDir(repo.Path)
if err != nil {
return nil, err
}
id, err = NewIDFromString(stdout)
if err != nil {
return nil, err
}
return repo.getCommit(id)
}
// GetCommitByPath returns the last commit of relative path.
func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
stdout, err := NewCommand("log", "-1", _PRETTY_LOG_FORMAT, "--", relpath).RunInDirBytes(repo.Path)