mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 00:03:35 +01:00
Merge pull request #790 from euank/master
Initialize unset git user.email / user.name correctly; fix Dockerfile
This commit is contained in:
commit
afdb0c7f9d
3 changed files with 13 additions and 16 deletions
|
@ -46,7 +46,7 @@ ENV HOME /home/git
|
||||||
ENV USER git
|
ENV USER git
|
||||||
ENV PATH $GOGS_PATH:$PATH
|
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"]
|
ENTRYPOINT ["/tmp/init_gogs.sh"]
|
||||||
CMD ["gogs", "web"]
|
CMD ["gogs", "web"]
|
||||||
|
|
|
@ -47,7 +47,7 @@ ENV HOME /home/git
|
||||||
ENV USER git
|
ENV USER git
|
||||||
ENV PATH $GOGS_PATH:$PATH
|
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"]
|
ENTRYPOINT ["/tmp/init_gogs.sh"]
|
||||||
CMD ["gogs", "web"]
|
CMD ["gogs", "web"]
|
||||||
|
|
|
@ -105,21 +105,18 @@ func NewRepoContext() {
|
||||||
log.Fatal(4, "Gogs requires Git version greater or equal to 1.7.1")
|
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.
|
// Check if server has user.email and user.name set correctly and set if they're not.
|
||||||
if stdout, stderr, err := process.Exec("NewRepoContext(get setting)", "git", "config", "--get", "user.name"); err != nil || strings.TrimSpace(stdout) == "" {
|
for configKey, defaultValue := range map[string]string{"user.name": "Gogs", "user.email": "gogitservice@gmail.com"} {
|
||||||
// ExitError indicates user.name is not set
|
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 _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" {
|
||||||
stndrdUserName := "Gogs"
|
if _, stderr, gerr := process.Exec("NewRepoContext(set "+configKey+")", "git", "config", "--global", configKey, defaultValue); gerr != nil {
|
||||||
stndrdUserEmail := "gogitservice@gmail.com"
|
log.Fatal(4, "Fail to set git %s(%s): %s", configKey, gerr, stderr)
|
||||||
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.Info("Git config %s set to %s", configKey, defaultValue)
|
||||||
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 {
|
} else {
|
||||||
log.Fatal(4, "Fail to get git user.name(%s): %s", err, stderr)
|
log.Fatal(4, "Fail to get git %s(%s): %s", configKey, err, stderr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue