summaryrefslogtreecommitdiffstats
path: root/modules/context
diff options
context:
space:
mode:
authorRichard Mahn <richmahn@users.noreply.github.com>2019-04-17 10:06:35 -0600
committertechknowlogick <matti@mdranta.net>2019-04-17 12:06:35 -0400
commit2262811e407facea09047e94aa1850c192511587 (patch)
treea478624613dc6cf095784d629f9627b197de15e8 /modules/context
parent059195b127848d96a4690257af19d8c97c6d2363 (diff)
downloadgitea-2262811e407facea09047e94aa1850c192511587.tar.gz
gitea-2262811e407facea09047e94aa1850c192511587.zip
Fixes 4762 - Content API for Creating, Updating, Deleting Files (#6314)
Diffstat (limited to 'modules/context')
-rw-r--r--modules/context/repo.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 2c6a4f5360..9d3fb7cfec 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -128,6 +128,21 @@ func (r *Repository) BranchNameSubURL() string {
return ""
}
+// FileExists returns true if a file exists in the given repo branch
+func (r *Repository) FileExists(path string, branch string) (bool, error) {
+ if branch == "" {
+ branch = r.Repository.DefaultBranch
+ }
+ commit, err := r.GitRepo.GetBranchCommit(branch)
+ if err != nil {
+ return false, err
+ }
+ if _, err := commit.GetTreeEntryByPath(path); err != nil {
+ return false, err
+ }
+ return true, nil
+}
+
// GetEditorconfig returns the .editorconfig definition if found in the
// HEAD of the default repo branch.
func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error) {