summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/repo.go5
-rw-r--r--models/repo_test.go22
2 files changed, 26 insertions, 1 deletions
diff --git a/models/repo.go b/models/repo.go
index 7aaeb6e0e7..f92f753b92 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -676,7 +676,10 @@ func (repo *Repository) DescriptionHTML() template.HTML {
// LocalCopyPath returns the local repository copy path
func (repo *Repository) LocalCopyPath() string {
- return path.Join(setting.AppDataPath, "tmp/local-repo", com.ToStr(repo.ID))
+ if filepath.IsAbs(setting.Repository.Local.LocalCopyPath) {
+ return path.Join(setting.Repository.Local.LocalCopyPath, com.ToStr(repo.ID))
+ }
+ return path.Join(setting.AppDataPath, setting.Repository.Local.LocalCopyPath, com.ToStr(repo.ID))
}
// UpdateLocalCopyBranch pulls latest changes of given branch from repoPath to localPath.
diff --git a/models/repo_test.go b/models/repo_test.go
index a538d44c0e..13ac272b6d 100644
--- a/models/repo_test.go
+++ b/models/repo_test.go
@@ -5,11 +5,14 @@
package models
import (
+ "path"
"testing"
"code.gitea.io/gitea/modules/markdown"
+ "code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
+ "github.com/Unknwon/com"
)
func TestRepo(t *testing.T) {
@@ -132,3 +135,22 @@ func TestRepoAPIURL(t *testing.T) {
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user12/repo10", repo.APIURL())
}
+
+func TestRepoLocalCopyPath(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+
+ repo, err := GetRepositoryByID(10)
+ assert.NoError(t, err)
+ assert.NotNil(t, repo)
+
+ // test default
+ repoID := com.ToStr(repo.ID)
+ expected := path.Join(setting.AppDataPath, setting.Repository.Local.LocalCopyPath, repoID)
+ assert.Equal(t, expected, repo.LocalCopyPath())
+
+ // test absolute setting
+ tempPath := "/tmp/gitea/local-copy-path"
+ expected = path.Join(tempPath, repoID)
+ setting.Repository.Local.LocalCopyPath = tempPath
+ assert.Equal(t, expected, repo.LocalCopyPath())
+}