summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/repo.go25
-rw-r--r--models/user.go2
2 files changed, 12 insertions, 15 deletions
diff --git a/models/repo.go b/models/repo.go
index 3ea4efc7f0..50b2b3fc25 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -105,21 +105,18 @@ func NewRepoContext() {
log.Fatal(4, "Gogs requires Git version greater or equal to 1.7.1")
}
- // 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)
+ // Check if server has user.email and user.name set correctly and set if they're not.
+ for configKey, defaultValue := range map[string]string{"user.name": "Gogs", "user.email": "gogitservice@gmail.com"} {
+ if stdout, stderr, err := process.Exec("NewRepoContext(get setting)", "git", "config", "--get", configKey); err != nil || strings.TrimSpace(stdout) == "" {
+ // ExitError indicates this config is not set
+ if _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" {
+ if _, stderr, gerr := process.Exec("NewRepoContext(set "+configKey+")", "git", "config", "--global", configKey, defaultValue); gerr != nil {
+ log.Fatal(4, "Fail to set git %s(%s): %s", configKey, gerr, stderr)
+ }
+ log.Info("Git config %s set to %s", configKey, defaultValue)
+ } else {
+ log.Fatal(4, "Fail to get git %s(%s): %s", configKey, err, 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)
}
}
diff --git a/models/user.go b/models/user.go
index 651168eba2..f16fbca344 100644
--- a/models/user.go
+++ b/models/user.go
@@ -453,7 +453,7 @@ func ChangeUserName(u *User, newUserName string) (err error) {
// UpdateUser updates user's information.
func UpdateUser(u *User) error {
- has, err := x.Where("id!=?", u.Id).And("email=?", u.Email).Get(new(User))
+ has, err := x.Where("id!=?", u.Id).And("type=?", INDIVIDUAL).And("email=?", u.Email).Get(new(User))
if err != nil {
return err
} else if has {