From 234a7c19a4a59632dadaf430ab2431dccc0d74a9 Mon Sep 17 00:00:00 2001 From: euank Date: Sat, 27 Dec 2014 19:07:54 -0800 Subject: [PATCH 1/2] Default values for both user.name and user.email The previous behavior was to set default values only if user.name was not set, but to always set it for both. This only sets a value if there wasn't one; this fixes cases where someone has a user.name but no user.email (see included Dockerfile) or someone has a user.email but no user.name (before the email would have been over-written). --- models/repo.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/models/repo.go b/models/repo.go index 3ea4efc7f..50b2b3fc2 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) + // 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) } - 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) } } From f059866a2171c26c90447bf43ee6e4e03f58ecec Mon Sep 17 00:00:00 2001 From: euank Date: Sat, 27 Dec 2014 19:10:33 -0800 Subject: [PATCH 2/2] Set user.name & user.email in Dockerfile The previous setting would cause all repo creations to fail, as described in issue #328. The previous commit also resolves this issue, but it seems saner to create the user in the Dockerfile than at runtime. --- docker/blocks/docker_gogs/Dockerfile | 2 +- docker/blocks/docker_gogs_dev/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/blocks/docker_gogs/Dockerfile b/docker/blocks/docker_gogs/Dockerfile index e2e056ae0..2c98cc501 100644 --- a/docker/blocks/docker_gogs/Dockerfile +++ b/docker/blocks/docker_gogs/Dockerfile @@ -46,7 +46,7 @@ ENV HOME /home/git ENV USER git ENV PATH $GOGS_PATH:$PATH -RUN git config --global user.name "GoGS" +RUN git config --global user.name "GoGS" && git config --global user.email "gogitservice@gmail.com" ENTRYPOINT ["/tmp/init_gogs.sh"] CMD ["gogs", "web"] diff --git a/docker/blocks/docker_gogs_dev/Dockerfile b/docker/blocks/docker_gogs_dev/Dockerfile index d1b96bf4a..2a628c2d5 100644 --- a/docker/blocks/docker_gogs_dev/Dockerfile +++ b/docker/blocks/docker_gogs_dev/Dockerfile @@ -47,7 +47,7 @@ ENV HOME /home/git ENV USER git ENV PATH $GOGS_PATH:$PATH -RUN git config --global user.name "GoGS" +RUN git config --global user.name "GoGS" && git config --global user.email "gogitservice@gmail.com" ENTRYPOINT ["/tmp/init_gogs.sh"] CMD ["gogs", "web"]