Skip to content

Commit

Permalink
Git env-var config overrides implemented
Browse files Browse the repository at this point in the history
Signed-off-by: Aino Spring <[email protected]>
  • Loading branch information
theaino committed May 8, 2024
1 parent b58429d commit e6be385
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pkg/settings/exe/cmd_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var gitDenyList = mapset.NewThreadUnsafeSet(
"GIT_WORK_TREE",
"GIT_DIR",
)
var gitConfigOverrides = map[string]string{
"clone.defaultRemoteName": "origin",
}

type GitCmdBuilder interface {
Runner
Expand Down Expand Up @@ -109,7 +112,20 @@ func gitFilteredEnv() []string {
}

env = append(env, "GIT_TERMINAL_PROMPT=0")
env = append(env, "GIT_CONFIG_NOSYSTEM=1")

return env
}

func gitConfigEnv() []string {
var env []string

count := 0
for key, value := range gitConfigOverrides {
env = append(env, fmt.Sprintf("GIT_CONFIG_KEY_%d=%s", count, key))
env = append(env, fmt.Sprintf("GIT_CONFIG_VALUE_%d=%s", count, value))
count++
}
env = append(env, "GIT_CONFIG_COUNT="+strconv.Itoa(count))

return env
}
Expand All @@ -129,6 +145,7 @@ func (c *CmdBuilder) BuildGitCmd(ctx context.Context, dir string, extraArgs ...s
cmd := exec.CommandContext(ctx, c.GitBin, args...)

cmd.Env = gitFilteredEnv()
cmd.Env = append(cmd.Env, gitConfigEnv()...)

cmd = c.deElevateCommand(ctx, cmd)

Expand All @@ -154,7 +171,7 @@ func (c *CmdBuilder) BuildMakepkgCmd(ctx context.Context, dir string, extraArgs
cmd := exec.CommandContext(ctx, c.MakepkgBin, args...)
cmd.Dir = dir

cmd.Env = append(cmd.Env, "GIT_CONFIG_NOSYSTEM=1")
cmd.Env = append(cmd.Env, gitConfigEnv()...)

cmd = c.deElevateCommand(ctx, cmd)

Expand Down

0 comments on commit e6be385

Please sign in to comment.