summaryrefslogtreecommitdiffstats
path: root/modules/repofiles
diff options
context:
space:
mode:
Diffstat (limited to 'modules/repofiles')
-rw-r--r--modules/repofiles/action.go2
-rw-r--r--modules/repofiles/blob.go1
-rw-r--r--modules/repofiles/blob_test.go2
-rw-r--r--modules/repofiles/commit_status.go2
-rw-r--r--modules/repofiles/content.go2
-rw-r--r--modules/repofiles/content_test.go12
-rw-r--r--modules/repofiles/diff_test.go4
-rw-r--r--modules/repofiles/file_test.go3
-rw-r--r--modules/repofiles/temp_repo.go1
-rw-r--r--modules/repofiles/tree.go1
-rw-r--r--modules/repofiles/tree_test.go2
-rw-r--r--modules/repofiles/update.go1
12 files changed, 33 insertions, 0 deletions
diff --git a/modules/repofiles/action.go b/modules/repofiles/action.go
index 996363863d..8b35cba726 100644
--- a/modules/repofiles/action.go
+++ b/modules/repofiles/action.go
@@ -53,9 +53,11 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
}
if err := gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
if !git.IsErrUnsupportedVersion(err) {
+ gitRepo.Close()
return err
}
}
+ gitRepo.Close()
}
}
diff --git a/modules/repofiles/blob.go b/modules/repofiles/blob.go
index e9d85a0dcf..60a05e280e 100644
--- a/modules/repofiles/blob.go
+++ b/modules/repofiles/blob.go
@@ -17,6 +17,7 @@ func GetBlobBySHA(repo *models.Repository, sha string) (*api.GitBlobResponse, er
if err != nil {
return nil, err
}
+ defer gitRepo.Close()
gitBlob, err := gitRepo.GetBlob(sha)
if err != nil {
return nil, err
diff --git a/modules/repofiles/blob_test.go b/modules/repofiles/blob_test.go
index 1dc183a8af..ddc23aeac3 100644
--- a/modules/repofiles/blob_test.go
+++ b/modules/repofiles/blob_test.go
@@ -21,6 +21,8 @@ func TestGetBlobBySHA(t *testing.T) {
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
ctx.SetParams(":id", "1")
ctx.SetParams(":sha", sha)
diff --git a/modules/repofiles/commit_status.go b/modules/repofiles/commit_status.go
index f3dfbf209f..3d93c58d85 100644
--- a/modules/repofiles/commit_status.go
+++ b/modules/repofiles/commit_status.go
@@ -23,8 +23,10 @@ func CreateCommitStatus(repo *models.Repository, creator *models.User, sha strin
return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
}
if _, err := gitRepo.GetCommit(sha); err != nil {
+ gitRepo.Close()
return fmt.Errorf("GetCommit[%s]: %v", sha, err)
}
+ gitRepo.Close()
if err := models.NewCommitStatus(models.NewCommitStatusOptions{
Repo: repo,
diff --git a/modules/repofiles/content.go b/modules/repofiles/content.go
index d7d43ef9d1..aed98c33a8 100644
--- a/modules/repofiles/content.go
+++ b/modules/repofiles/content.go
@@ -59,6 +59,7 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface
if err != nil {
return nil, err
}
+ defer gitRepo.Close()
// Get the commit object for the ref
commit, err := gitRepo.GetCommit(ref)
@@ -117,6 +118,7 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
if err != nil {
return nil, err
}
+ defer gitRepo.Close()
// Get the commit object for the ref
commit, err := gitRepo.GetCommit(ref)
diff --git a/modules/repofiles/content_test.go b/modules/repofiles/content_test.go
index cd98c54ea6..d024cfd549 100644
--- a/modules/repofiles/content_test.go
+++ b/modules/repofiles/content_test.go
@@ -56,6 +56,8 @@ func TestGetContents(t *testing.T) {
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
treePath := "README.md"
ref := ctx.Repo.Repository.DefaultBranch
@@ -82,6 +84,8 @@ func TestGetContentsOrListForDir(t *testing.T) {
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
treePath := "" // root dir
ref := ctx.Repo.Repository.DefaultBranch
@@ -115,6 +119,8 @@ func TestGetContentsOrListForFile(t *testing.T) {
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
treePath := "README.md"
ref := ctx.Repo.Repository.DefaultBranch
@@ -141,6 +147,8 @@ func TestGetContentsErrors(t *testing.T) {
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
treePath := "README.md"
ref := repo.DefaultBranch
@@ -170,6 +178,8 @@ func TestGetContentsOrListErrors(t *testing.T) {
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
treePath := "README.md"
ref := repo.DefaultBranch
@@ -198,6 +208,8 @@ func TestGetContentsOrListOfEmptyRepos(t *testing.T) {
test.LoadRepo(t, ctx, 15)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
t.Run("empty repo", func(t *testing.T) {
diff --git a/modules/repofiles/diff_test.go b/modules/repofiles/diff_test.go
index de5ed1d754..db2c7552c4 100644
--- a/modules/repofiles/diff_test.go
+++ b/modules/repofiles/diff_test.go
@@ -22,6 +22,8 @@ func TestGetDiffPreview(t *testing.T) {
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
branch := ctx.Repo.Repository.DefaultBranch
treePath := "README.md"
content := "# repo1\n\nDescription for repo1\nthis is a new line"
@@ -119,6 +121,8 @@ func TestGetDiffPreviewErrors(t *testing.T) {
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
branch := ctx.Repo.Repository.DefaultBranch
treePath := "README.md"
content := "# repo1\n\nDescription for repo1\nthis is a new line"
diff --git a/modules/repofiles/file_test.go b/modules/repofiles/file_test.go
index 95ec175ed4..3cb4eb472b 100644
--- a/modules/repofiles/file_test.go
+++ b/modules/repofiles/file_test.go
@@ -88,10 +88,13 @@ func TestGetFileResponseFromCommit(t *testing.T) {
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
repo := ctx.Repo.Repository
branch := repo.DefaultBranch
treePath := "README.md"
gitRepo, _ := git.OpenRepository(repo.RepoPath())
+ defer gitRepo.Close()
commit, _ := gitRepo.GetBranchCommit(branch)
expectedFileResponse := getExpectedFileResponse()
diff --git a/modules/repofiles/temp_repo.go b/modules/repofiles/temp_repo.go
index abc224c2c2..6bd775d9d2 100644
--- a/modules/repofiles/temp_repo.go
+++ b/modules/repofiles/temp_repo.go
@@ -42,6 +42,7 @@ func NewTemporaryUploadRepository(repo *models.Repository) (*TemporaryUploadRepo
// Close the repository cleaning up all files
func (t *TemporaryUploadRepository) Close() {
+ defer t.gitRepo.Close()
if err := models.RemoveTemporaryPath(t.basePath); err != nil {
log.Error("Failed to remove temporary path %s: %v", t.basePath, err)
}
diff --git a/modules/repofiles/tree.go b/modules/repofiles/tree.go
index 318a5d152d..cf0534563f 100644
--- a/modules/repofiles/tree.go
+++ b/modules/repofiles/tree.go
@@ -19,6 +19,7 @@ func GetTreeBySHA(repo *models.Repository, sha string, page, perPage int, recurs
if err != nil {
return nil, err
}
+ defer gitRepo.Close()
gitTree, err := gitRepo.GetTree(sha)
if err != nil || gitTree == nil {
return nil, models.ErrSHANotFound{
diff --git a/modules/repofiles/tree_test.go b/modules/repofiles/tree_test.go
index ecff8b9071..e1bb812ec1 100644
--- a/modules/repofiles/tree_test.go
+++ b/modules/repofiles/tree_test.go
@@ -21,6 +21,8 @@ func TestGetTreeBySHA(t *testing.T) {
test.LoadRepoCommit(t, ctx)
test.LoadUser(t, ctx, 2)
test.LoadGitRepo(t, ctx)
+ defer ctx.Repo.GitRepo.Close()
+
sha := ctx.Repo.Repository.DefaultBranch
page := 1
perPage := 10
diff --git a/modules/repofiles/update.go b/modules/repofiles/update.go
index 5479616c4b..ef56609f4d 100644
--- a/modules/repofiles/update.go
+++ b/modules/repofiles/update.go
@@ -430,6 +430,7 @@ func PushUpdate(repo *models.Repository, branch string, opts models.PushUpdateOp
if err != nil {
return fmt.Errorf("OpenRepository: %v", err)
}
+ defer gitRepo.Close()
if err = repo.UpdateSize(); err != nil {
log.Error("Failed to update size for repository: %v", err)