Skip to content

avoid os.Setenv calls in runServ, add env vars to gitcmd.Env instead #3772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,18 @@ func runServ(c *cli.Context) error {
reponame = reponame[:len(reponame)-5]
}

os.Setenv(models.EnvRepoUsername, username)
env := []string{}
addEnv := func(key string, value string) {
env = append(env, key+"="+value)
}

addEnv(models.EnvRepoUsername, username)
if isUncyclo {
os.Setenv(models.EnvRepoIsUncyclo, "true")
addEnv(models.EnvRepoIsUncyclo, "true")
} else {
os.Setenv(models.EnvRepoIsUncyclo, "false")
addEnv(models.EnvRepoIsUncyclo, "false")
}
os.Setenv(models.EnvRepoName, reponame)
addEnv(models.EnvRepoName, reponame)

repo, err := private.GetRepositoryByOwnerAndName(username, reponame)
if err != nil {
Expand Down Expand Up @@ -259,8 +264,8 @@ func runServ(c *cli.Context) error {
user.Name, repoPath)
}

os.Setenv(models.EnvPusherName, user.Name)
os.Setenv(models.EnvPusherID, fmt.Sprintf("%d", user.ID))
addEnv(models.EnvPusherName, user.Name)
addEnv(models.EnvPusherID, fmt.Sprintf("%d", user.ID))
}
}

Expand Down Expand Up @@ -319,8 +324,9 @@ func runServ(c *cli.Context) error {
}
}

os.Setenv(models.ProtectedBranchRepoID, fmt.Sprintf("%d", repo.ID))
addEnv(models.ProtectedBranchRepoID, fmt.Sprintf("%d", repo.ID))

gitcmd.Env = env
gitcmd.Dir = setting.RepoRootPath
gitcmd.Stdout = os.Stdout
gitcmd.Stdin = os.Stdin
Expand Down