diff options
author | Richard Mahn <richmahn@users.noreply.github.com> | 2019-04-17 10:06:35 -0600 |
---|---|---|
committer | techknowlogick <matti@mdranta.net> | 2019-04-17 12:06:35 -0400 |
commit | 2262811e407facea09047e94aa1850c192511587 (patch) | |
tree | a478624613dc6cf095784d629f9627b197de15e8 /modules/git/repo_commit.go | |
parent | 059195b127848d96a4690257af19d8c97c6d2363 (diff) | |
download | gitea-2262811e407facea09047e94aa1850c192511587.tar.gz gitea-2262811e407facea09047e94aa1850c192511587.zip |
Fixes 4762 - Content API for Creating, Updating, Deleting Files (#6314)
Diffstat (limited to 'modules/git/repo_commit.go')
-rw-r--r-- | modules/git/repo_commit.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index 1ecd1f8891..7c65d6e921 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -10,7 +10,7 @@ import ( "strconv" "strings" - version "github.com/mcuadros/go-version" + "github.com/mcuadros/go-version" ) // GetRefCommitID returns the last commit ID string of given reference (branch or tag). @@ -270,7 +270,7 @@ func (repo *Repository) searchCommits(id SHA1, opts SearchCommitsOptions) (*list return repo.parsePrettyFormatLogToList(stdout) } -func (repo *Repository) getFilesChanged(id1 string, id2 string) ([]string, error) { +func (repo *Repository) getFilesChanged(id1, id2 string) ([]string, error) { stdout, err := NewCommand("diff", "--name-only", id1, id2).RunInDirBytes(repo.Path) if err != nil { return nil, err @@ -278,6 +278,15 @@ func (repo *Repository) getFilesChanged(id1 string, id2 string) ([]string, error return strings.Split(string(stdout), "\n"), nil } +// FileChangedBetweenCommits Returns true if the file changed between commit IDs id1 and id2 +func (repo *Repository) FileChangedBetweenCommits(filename, id1, id2 string) (bool, error) { + stdout, err := NewCommand("diff", "--name-only", "-z", id1, id2, "--", filename).RunInDirBytes(repo.Path) + if err != nil { + return false, err + } + return len(strings.TrimSpace(string(stdout))) > 0, nil +} + // FileCommitsCount return the number of files at a revison func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) { return commitsCount(repo.Path, revision, file) |