mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-04 08:17:24 -05:00
Make LocalCopyPath
a setting instead of a hard-coded path (#1881)
This commit is contained in:
parent
cbdd5f787c
commit
6ec07a6bd7
4
conf/app.ini
vendored
4
conf/app.ini
vendored
@ -32,6 +32,10 @@ LINE_WRAP_EXTENSIONS = .txt,.md,.markdown,.mdown,.mkd,
|
|||||||
; Separate values by commas. Preview tab in edit mode won't show if the file extension doesn't match
|
; Separate values by commas. Preview tab in edit mode won't show if the file extension doesn't match
|
||||||
PREVIEWABLE_FILE_MODES = markdown
|
PREVIEWABLE_FILE_MODES = markdown
|
||||||
|
|
||||||
|
[repository.local]
|
||||||
|
; Path for uploads. Defaults to `tmp/local-repo`
|
||||||
|
LOCAL_COPY_PATH = tmp/local-repo
|
||||||
|
|
||||||
[repository.upload]
|
[repository.upload]
|
||||||
; Whether repository file uploads are enabled. Defaults to `true`
|
; Whether repository file uploads are enabled. Defaults to `true`
|
||||||
ENABLED = true
|
ENABLED = true
|
||||||
|
@ -676,7 +676,10 @@ func (repo *Repository) DescriptionHTML() template.HTML {
|
|||||||
|
|
||||||
// LocalCopyPath returns the local repository copy path
|
// LocalCopyPath returns the local repository copy path
|
||||||
func (repo *Repository) LocalCopyPath() string {
|
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.
|
// UpdateLocalCopyBranch pulls latest changes of given branch from repoPath to localPath.
|
||||||
|
@ -5,11 +5,14 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/markdown"
|
"code.gitea.io/gitea/modules/markdown"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/Unknwon/com"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRepo(t *testing.T) {
|
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())
|
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())
|
||||||
|
}
|
||||||
|
@ -174,6 +174,11 @@ var (
|
|||||||
FileMaxSize int64
|
FileMaxSize int64
|
||||||
MaxFiles int
|
MaxFiles int
|
||||||
} `ini:"-"`
|
} `ini:"-"`
|
||||||
|
|
||||||
|
// Repository local settings
|
||||||
|
Local struct {
|
||||||
|
LocalCopyPath string
|
||||||
|
} `ini:"-"`
|
||||||
}{
|
}{
|
||||||
AnsiCharset: "",
|
AnsiCharset: "",
|
||||||
ForcePrivate: false,
|
ForcePrivate: false,
|
||||||
@ -206,6 +211,13 @@ var (
|
|||||||
FileMaxSize: 3,
|
FileMaxSize: 3,
|
||||||
MaxFiles: 5,
|
MaxFiles: 5,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Repository local settings
|
||||||
|
Local: struct {
|
||||||
|
LocalCopyPath string
|
||||||
|
}{
|
||||||
|
LocalCopyPath: "tmp/local-repo",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
RepoRootPath string
|
RepoRootPath string
|
||||||
ScriptType = "bash"
|
ScriptType = "bash"
|
||||||
@ -887,6 +899,8 @@ please consider changing to GITEA_CUSTOM`)
|
|||||||
log.Fatal(4, "Failed to map Repository.Editor settings: %v", err)
|
log.Fatal(4, "Failed to map Repository.Editor settings: %v", err)
|
||||||
} else if err = Cfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
|
} else if err = Cfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
|
||||||
log.Fatal(4, "Failed to map Repository.Upload settings: %v", err)
|
log.Fatal(4, "Failed to map Repository.Upload settings: %v", err)
|
||||||
|
} else if err = Cfg.Section("repository.local").MapTo(&Repository.Local); err != nil {
|
||||||
|
log.Fatal(4, "Failed to map Repository.Local settings: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !filepath.IsAbs(Repository.Upload.TempPath) {
|
if !filepath.IsAbs(Repository.Upload.TempPath) {
|
||||||
|
Loading…
Reference in New Issue
Block a user