From 8bc502a1ead4d59e1940946c74ff48c8e6457633 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 22 Apr 2014 22:34:49 -0400 Subject: [PATCH] New err check style --- models/repo.go | 24 ++++++++---------------- routers/repo/repo.go | 1 - 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/models/repo.go b/models/repo.go index 19fe6e2887..2011ed7de1 100644 --- a/models/repo.go +++ b/models/repo.go @@ -47,16 +47,16 @@ func NewRepoContext() { zip.Verbose = false // Check if server has basic git setting. - stdout, _, err := com.ExecCmd("git", "config", "--get", "user.name") - if err != nil { - fmt.Printf("repo.init(fail to get git user.name): %v", err) + 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) - } else if len(stdout) == 0 { - if _, _, err = com.ExecCmd("git", "config", "--global", "user.email", "gogitservice@gmail.com"); err != nil { - fmt.Printf("repo.init(fail to set git user.email): %v", err) + } 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) - } else if _, _, err = com.ExecCmd("git", "config", "--global", "user.name", "Gogs"); err != nil { - fmt.Printf("repo.init(fail to set git user.name): %v", err) + } 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) } } @@ -352,7 +352,6 @@ func CreateRepository(user *User, name, desc, lang, license string, private, mir func extractGitBareZip(repoPath string) error { z, err := zip.Open("conf/content/git-bare.zip") if err != nil { - fmt.Println("shi?") return err } defer z.Close() @@ -364,21 +363,14 @@ func extractGitBareZip(repoPath string) error { func initRepoCommit(tmpPath string, sig *git.Signature) (err error) { var stderr string if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "add", "--all"); err != nil { - return err - } else if strings.Contains(stderr, "fatal:") { return errors.New("git add: " + stderr) } - if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email), "-m", "Init commit"); err != nil { - return err - } else if strings.Contains(stderr, "fatal:") { return errors.New("git commit: " + stderr) } if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "push", "origin", "master"); err != nil { - return err - } else if strings.Contains(stderr, "fatal:") { return errors.New("git push: " + stderr) } return nil diff --git a/routers/repo/repo.go b/routers/repo/repo.go index f733378b3f..76964dff13 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -134,7 +134,6 @@ func Single(ctx *middleware.Context, params martini.Params) { } entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treename) - if err != nil && err != git.ErrNotExist { ctx.Handle(404, "repo.Single(GetTreeEntryByPath)", err) return