This commit is contained in:
Unknown 2014-05-11 14:03:51 -04:00
parent 68fb62347f
commit 98eeec4cbb
2 changed files with 36 additions and 10 deletions

View file

@ -9,8 +9,6 @@ RUN_MODE = dev
[repository]
ROOT =
SCRIPT_TYPE = bash
LANG_IGNS = Google Go|C|C++|Python|Ruby|C Sharp|Java|Objective-C|Android
LICENSES = Apache v2 License|GPL v2|MIT License|Affero GPL|Artistic License 2.0|BSD (3-Clause) License
[server]
PROTOCOL = http

View file

@ -18,6 +18,7 @@ import (
"github.com/Unknwon/cae/zip"
"github.com/Unknwon/com"
qlog "github.com/qiniu/log"
"github.com/gogits/git"
@ -39,8 +40,38 @@ var (
)
func LoadRepoConfig() {
LanguageIgns = strings.Split(base.Cfg.MustValue("repository", "LANG_IGNS"), "|")
Licenses = strings.Split(base.Cfg.MustValue("repository", "LICENSES"), "|")
workDir, err := base.ExecDir()
if err != nil {
qlog.Fatalf("Fail to get work directory: %s\n", err)
}
// Load .gitignore and license files.
types := []string{"gitignore", "license"}
typeFiles := make([][]string, 2)
for i, t := range types {
cfgPath := filepath.Join(workDir, "conf", t)
files, err := com.StatDir(cfgPath)
if err != nil {
qlog.Fatalf("Fail to get default %s files: %v\n", t, err)
}
cfgPath = filepath.Join(workDir, "custom/conf/gitignore")
if com.IsDir(cfgPath) {
customFiles, err := com.StatDir(cfgPath)
if err != nil {
qlog.Fatalf("Fail to get custom %s files: %v\n", t, err)
}
for _, f := range customFiles {
if !com.IsSliceContainsStr(files, f) {
files = append(files, f)
}
}
}
typeFiles[i] = files
}
LanguageIgns = typeFiles[0]
Licenses = typeFiles[1]
}
func NewRepoContext() {
@ -49,15 +80,12 @@ func NewRepoContext() {
// Check if server has basic git setting.
stdout, stderr, err := com.ExecCmd("git", "config", "--get", "user.name")
if strings.Contains(stderr, "fatal:") {
fmt.Printf("repo.NewRepoContext(fail to get git user.name): %s", stderr)
os.Exit(2)
qlog.Fatalf("repo.NewRepoContext(fail to get git user.name): %s", stderr)
} else if err != nil || len(strings.TrimSpace(stdout)) == 0 {
if _, stderr, err = com.ExecCmd("git", "config", "--global", "user.email", "gogitservice@gmail.com"); err != nil {
fmt.Printf("repo.NewRepoContext(fail to set git user.email): %s", stderr)
os.Exit(2)
qlog.Fatalf("repo.NewRepoContext(fail to set git user.email): %s", stderr)
} else if _, stderr, err = com.ExecCmd("git", "config", "--global", "user.name", "Gogs"); err != nil {
fmt.Printf("repo.NewRepoContext(fail to set git user.name): %s", stderr)
os.Exit(2)
qlog.Fatalf("repo.NewRepoContext(fail to set git user.name): %s", stderr)
}
}
}