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:
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user