1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-04 08:17:24 -05:00

New err check style

This commit is contained in:
Unknown 2014-04-22 22:34:49 -04:00
parent 88072a1e9b
commit 8bc502a1ea
2 changed files with 8 additions and 17 deletions

View File

@ -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

View File

@ -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