summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorTristan Storch <tstorch@math.uni-bielefeld.de>2014-09-04 12:03:29 +0200
committerTristan Storch <tstorch@math.uni-bielefeld.de>2014-09-04 12:07:09 +0200
commit9fc4ded369a90140a63e064371479f2ef4e4bc4f (patch)
treee4c6219b5c28ec1b02f678f2396022879a2f2287 /models/repo.go
parentf36f9e07b78d078c89b57437a12c85ea8218fa1c (diff)
downloadgitea-9fc4ded369a90140a63e064371479f2ef4e4bc4f.tar.gz
gitea-9fc4ded369a90140a63e064371479f2ef4e4bc4f.zip
Standard git user.name and user.email if not set
Git user.name and user.email will now be set to the standard values - Gogs - gogitservice@gmail.com if user.name is not set or empty. If user.name is set and user.email not, it will leave it this way.
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/models/repo.go b/models/repo.go
index 8f62fa17ae..23d44a6b80 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -99,20 +99,26 @@ func NewRepoContext() {
log.Fatal(4, "Gogs requires Git version greater or equal to 1.8.0")
}
- // Check if server has basic git setting.
- stdout, stderr, err := process.Exec("NewRepoContext(get setting)", "git", "config", "--get", "user.name")
- if err != nil {
- log.Fatal(4, "Fail to get git user.name: %s", stderr)
- } else if err != nil || len(strings.TrimSpace(stdout)) == 0 {
- if _, stderr, err = process.Exec("NewRepoContext(set email)", "git", "config", "--global", "user.email", "gogitservice@gmail.com"); err != nil {
- log.Fatal(4, "Fail to set git user.email: %s", stderr)
- } else if _, stderr, err = process.Exec("NewRepoContext(set name)", "git", "config", "--global", "user.name", "Gogs"); err != nil {
- log.Fatal(4, "Fail to set git user.name: %s", stderr)
+ // Check if server has basic git setting and set if not.
+ if stdout, stderr, err := process.Exec("NewRepoContext(get setting)", "git", "config", "--get", "user.name"); err != nil || strings.TrimSpace(stdout) == "" {
+ // ExitError indicates user.name is not set
+ if _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" {
+ stndrdUserName := "Gogs"
+ stndrdUserEmail := "gogitservice@gmail.com"
+ if _, stderr, gerr := process.Exec("NewRepoContext(set name)", "git", "config", "--global", "user.name", stndrdUserName); gerr != nil {
+ log.Fatal(4, "Fail to set git user.name(%s): %s", gerr, stderr)
+ }
+ if _, stderr, gerr := process.Exec("NewRepoContext(set email)", "git", "config", "--global", "user.email", stndrdUserEmail); gerr != nil {
+ log.Fatal(4, "Fail to set git user.email(%s): %s", gerr, stderr)
+ }
+ log.Info("Git user.name and user.email set to %s <%s>", stndrdUserName, stndrdUserEmail)
+ } else {
+ log.Fatal(4, "Fail to get git user.name(%s): %s", err, stderr)
}
}
// Set git some configurations.
- if _, stderr, err = process.Exec("NewRepoContext(git config --global core.quotepath false)",
+ if _, stderr, err := process.Exec("NewRepoContext(git config --global core.quotepath false)",
"git", "config", "--global", "core.quotepath", "false"); err != nil {
log.Fatal(4, "Fail to execute 'git config --global core.quotepath false': %s", stderr)
}