Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

knotserver: set default git committer user via config

Introducing `KNOT_GIT_USER_NAME` and `KNOT_GIT_USER_EMAIL` environment
variables.

This will prevent silently inheritting global gitconfig's user

Signed-off-by: Seongmin Lee <boltlessengineer@proton.me>

authored by

Seongmin Lee and committed by
Tangled
0749c39a 033886cc

+21 -14
+7
knotserver/config/config.go
··· 27 27 Dev bool `env:"DEV, default=false"` 28 28 } 29 29 30 + type Git struct { 31 + // user name & email used as committer 32 + UserName string `env:"USER_NAME, default=Tangled"` 33 + UserEmail string `env:"USER_EMAIL, default=noreply@tangled.sh"` 34 + } 35 + 30 36 func (s Server) Did() syntax.DID { 31 37 return syntax.DID(fmt.Sprintf("did:web:%s", s.Hostname)) 32 38 } ··· 40 34 type Config struct { 41 35 Repo Repo `env:",prefix=KNOT_REPO_"` 42 36 Server Server `env:",prefix=KNOT_SERVER_"` 37 + Git Git `env:",prefix=KNOT_GIT_"` 43 38 AppViewEndpoint string `env:"APPVIEW_ENDPOINT, default=https://tangled.sh"` 44 39 } 45 40
+12 -14
knotserver/git/merge.go
··· 85 85 86 86 // MergeOptions specifies the configuration for a merge operation 87 87 type MergeOptions struct { 88 - CommitMessage string 89 - CommitBody string 90 - AuthorName string 91 - AuthorEmail string 92 - FormatPatch bool 88 + CommitMessage string 89 + CommitBody string 90 + AuthorName string 91 + AuthorEmail string 92 + CommitterName string 93 + CommitterEmail string 94 + FormatPatch bool 93 95 } 94 96 95 97 func (e ErrMerge) Error() string { ··· 166 164 var stderr bytes.Buffer 167 165 var cmd *exec.Cmd 168 166 167 + // configure default git user before merge 168 + exec.Command("git", "-C", tmpDir, "config", "user.name", opts.CommitterName).Run() 169 + exec.Command("git", "-C", tmpDir, "config", "user.email", opts.CommitterEmail).Run() 169 170 exec.Command("git", "-C", tmpDir, "config", "advice.mergeConflict", "false").Run() 170 171 171 172 // if patch is a format-patch, apply using 'git am' ··· 193 188 authorName := opts.AuthorName 194 189 authorEmail := opts.AuthorEmail 195 190 196 - if authorEmail == "" { 197 - authorEmail = "noreply@tangled.sh" 198 - } 199 - 200 - if authorName == "" { 201 - authorName = "Tangled" 202 - } 203 - 204 - if authorName != "" { 191 + if authorName != "" && authorEmail != "" { 205 192 commitArgs = append(commitArgs, "--author", fmt.Sprintf("%s <%s>", authorName, authorEmail)) 206 193 } 194 + // else, will default to knot's global user.name & user.email configured via `KNOT_GIT_USER_*` env variables 207 195 208 196 commitArgs = append(commitArgs, "-m", opts.CommitMessage) 209 197
+2
knotserver/xrpc/merge.go
··· 81 81 mo.CommitMessage = *data.CommitMessage 82 82 } 83 83 84 + mo.CommitterName = x.Config.Git.UserName 85 + mo.CommitterEmail = x.Config.Git.UserEmail 84 86 mo.FormatPatch = patchutil.IsFormatPatch(data.Patch) 85 87 86 88 err = gr.MergeWithOptions([]byte(data.Patch), data.Branch, mo)