diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/action.go | 1 | ||||
-rw-r--r-- | models/issue.go | 4 | ||||
-rw-r--r-- | models/models.go | 15 | ||||
-rw-r--r-- | models/repo.go | 53 | ||||
-rw-r--r-- | models/user.go | 2 |
5 files changed, 44 insertions, 31 deletions
diff --git a/models/action.go b/models/action.go index 98a4f5a0..de2cdd12 100644 --- a/models/action.go +++ b/models/action.go @@ -332,7 +332,6 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, } } - go DeliverHooks() return nil } diff --git a/models/issue.go b/models/issue.go index 8004647c..c756e497 100644 --- a/models/issue.go +++ b/models/issue.go @@ -472,8 +472,8 @@ func UpdateIssueUserPairByAssignee(aid, iid int64) error { if aid == 0 { return nil } - rawSql = "UPDATE `issue_user` SET is_assigned = true WHERE uid = ? AND issue_id = ?" - _, err := x.Exec(rawSql, aid, iid) + rawSql = "UPDATE `issue_user` SET is_assigned = ? WHERE uid = ? AND issue_id = ?" + _, err := x.Exec(rawSql, true, aid, iid) return err } diff --git a/models/models.go b/models/models.go index 677f9ba9..cf212441 100644 --- a/models/models.go +++ b/models/models.go @@ -49,18 +49,19 @@ func init() { } func LoadModelsConfig() { - DbCfg.Type = setting.Cfg.MustValue("database", "DB_TYPE") + sec := setting.Cfg.Section("database") + DbCfg.Type = sec.Key("DB_TYPE").String() if DbCfg.Type == "sqlite3" { UseSQLite3 = true } - DbCfg.Host = setting.Cfg.MustValue("database", "HOST") - DbCfg.Name = setting.Cfg.MustValue("database", "NAME") - DbCfg.User = setting.Cfg.MustValue("database", "USER") + DbCfg.Host = sec.Key("HOST").String() + DbCfg.Name = sec.Key("NAME").String() + DbCfg.User = sec.Key("USER").String() if len(DbCfg.Pwd) == 0 { - DbCfg.Pwd = setting.Cfg.MustValue("database", "PASSWD") + DbCfg.Pwd = sec.Key("PASSWD").String() } - DbCfg.SslMode = setting.Cfg.MustValue("database", "SSL_MODE") - DbCfg.Path = setting.Cfg.MustValue("database", "PATH", "data/gogs.db") + DbCfg.SslMode = sec.Key("SSL_MODE").String() + DbCfg.Path = sec.Key("PATH").MustString("data/gogs.db") } func getEngine() (*xorm.Engine, error) { diff --git a/models/repo.go b/models/repo.go index 3ea4efc7..65689b6a 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) } } @@ -832,6 +829,8 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { // ChangeRepositoryName changes all corresponding setting from old repository name to new one. func ChangeRepositoryName(userName, oldRepoName, newRepoName string) (err error) { + userName = strings.ToLower(userName) + oldRepoName = strings.ToLower(oldRepoName) newRepoName = strings.ToLower(newRepoName) if !IsLegalName(newRepoName) { return ErrRepoNameIllegal @@ -839,7 +838,7 @@ func ChangeRepositoryName(userName, oldRepoName, newRepoName string) (err error) // Update accesses. accesses := make([]Access, 0, 10) - if err = x.Find(&accesses, &Access{RepoName: strings.ToLower(userName + "/" + oldRepoName)}); err != nil { + if err = x.Find(&accesses, &Access{RepoName: userName + "/" + oldRepoName}); err != nil { return err } @@ -1187,6 +1186,8 @@ func MirrorUpdate() { isMirrorUpdating = true defer func() { isMirrorUpdating = false }() + mirrors := make([]*Mirror, 0, 10) + if err := x.Iterate(new(Mirror), func(idx int, bean interface{}) error { m := bean.(*Mirror) if m.NextUpdate.After(time.Now()) { @@ -1197,13 +1198,25 @@ func MirrorUpdate() { if _, stderr, err := process.ExecDir(10*time.Minute, repoPath, fmt.Sprintf("MirrorUpdate: %s", repoPath), "git", "remote", "update"); err != nil { - return errors.New("git remote update: " + stderr) + desc := fmt.Sprintf("Fail to update mirror repository(%s): %s", repoPath, stderr) + log.Error(4, desc) + if err = CreateRepositoryNotice(desc); err != nil { + log.Error(4, "Fail to add notice: %v", err) + } + return nil } m.NextUpdate = time.Now().Add(time.Duration(m.Interval) * time.Hour) - return UpdateMirror(m) + mirrors = append(mirrors, m) + return nil }); err != nil { - log.Error(4, "repo.MirrorUpdate: %v", err) + log.Error(4, "MirrorUpdate: %v", err) + } + + for i := range mirrors { + if err := UpdateMirror(mirrors[i]); err != nil { + log.Error(4, "UpdateMirror", fmt.Sprintf("%s: %v", mirrors[i].RepoName, err)) + } } } @@ -1215,7 +1228,7 @@ func GitFsck() { isGitFscking = true defer func() { isGitFscking = false }() - args := append([]string{"fsck"}, setting.GitFsckArgs...) + args := append([]string{"fsck"}, setting.Git.Fsck.Args...) if err := x.Where("id > 0").Iterate(new(Repository), func(idx int, bean interface{}) error { repo := bean.(*Repository) @@ -1239,7 +1252,7 @@ func GitFsck() { } func GitGcRepos() error { - args := append([]string{"gc"}, setting.GitGcArgs...) + args := append([]string{"gc"}, setting.Git.GcArgs...) return x.Where("id > 0").Iterate(new(Repository), func(idx int, bean interface{}) error { repo := bean.(*Repository) diff --git a/models/user.go b/models/user.go index 651168eb..f16fbca3 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 { |