From b9ec98287f2876e4ab0de126dc5b07b9173c95f0 Mon Sep 17 00:00:00 2001 From: Erik Seliger Date: Wed, 11 Nov 2020 03:06:50 +0100 Subject: [PATCH 1/4] Don't use git config that might be present on the host This can cause unexpected git behavior, like a different diff tool, ANSI coloring in the diff and probably other bad magic. --- internal/campaigns/run_steps.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/internal/campaigns/run_steps.go b/internal/campaigns/run_steps.go index 6ef650f449..b11d1bdd12 100644 --- a/internal/campaigns/run_steps.go +++ b/internal/campaigns/run_steps.go @@ -28,6 +28,18 @@ func runSteps(ctx context.Context, wc *WorkspaceCreator, repo *graphql.Repositor runGitCmd := func(args ...string) ([]byte, error) { cmd := exec.CommandContext(ctx, "git", args...) + cmd.Env = []string{ + // Don't use the system wide git config. + "GIT_CONFIG_NOSYSTEM=1", + // And also not any other, because they can mess up output, change defaults, .. which can do unexpected things. + "GIT_CONFIG=/dev/null", + // Set user.name and user.email in the local repository. The user name and + // e-mail will eventually be ignored anyway, since we're just using the Git + // repository to generate diffs, but we don't want git to generate alarming + // looking warnings. + "GIT_AUTHOR_NAME=Sourcegraph", + "GIT_AUTHOR_EMAIL=campaigns@sourcegraph.com", + } cmd.Dir = volumeDir out, err := cmd.CombinedOutput() if err != nil { @@ -41,17 +53,6 @@ func runSteps(ctx context.Context, wc *WorkspaceCreator, repo *graphql.Repositor return nil, errors.Wrap(err, "git init failed") } - // Set user.name and user.email in the local repository. The user name and - // e-mail will eventually be ignored anyway, since we're just using the Git - // repository to generate diffs, but we don't want git to generate alarming - // looking warnings. - if _, err := runGitCmd("config", "--local", "user.name", "Sourcegraph"); err != nil { - return nil, errors.Wrap(err, "git config user.name failed") - } - if _, err := runGitCmd("config", "--local", "user.email", "campaigns@sourcegraph.com"); err != nil { - return nil, errors.Wrap(err, "git config user.email failed") - } - // --force because we want previously "gitignored" files in the repository if _, err := runGitCmd("add", "--force", "--all"); err != nil { return nil, errors.Wrap(err, "git add failed") From 35d1706584fd351e8d6fd188d2475ee8d8a7661d Mon Sep 17 00:00:00 2001 From: Erik Seliger Date: Wed, 11 Nov 2020 03:34:33 +0100 Subject: [PATCH 2/4] Try setting committer name as well --- internal/campaigns/run_steps.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/campaigns/run_steps.go b/internal/campaigns/run_steps.go index b11d1bdd12..79aa1ac432 100644 --- a/internal/campaigns/run_steps.go +++ b/internal/campaigns/run_steps.go @@ -39,6 +39,8 @@ func runSteps(ctx context.Context, wc *WorkspaceCreator, repo *graphql.Repositor // looking warnings. "GIT_AUTHOR_NAME=Sourcegraph", "GIT_AUTHOR_EMAIL=campaigns@sourcegraph.com", + "GIT_COMMITTER_NAME=Sourcegraph", + "GIT_COMMITTER_EMAIL=campaigns@sourcegraph.com", } cmd.Dir = volumeDir out, err := cmd.CombinedOutput() From 334849e8d5acf6ebfbe8ad55376cc86018fb03ec Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 11 Nov 2020 09:37:04 +0100 Subject: [PATCH 3/4] Add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed8f584ccc..459831da62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ All notable changes to `src-cli` are documented in this file. ### Fixed +- `src campaign [apply|preview]` could sometimes fail to parse the produced diffs in a repository in case `git` was configured to use a custom `diff` program. The fix is to ignore any `git` configuration. [#373](https://github.com/sourcegraph/src-cli/pull/373) + ### Removed ## 3.21.7 From e352412bc51155d3d5f3cddb12e93b1388bb39c8 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 11 Nov 2020 09:37:50 +0100 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 459831da62..f17a14c8aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ All notable changes to `src-cli` are documented in this file. ### Fixed -- `src campaign [apply|preview]` could sometimes fail to parse the produced diffs in a repository in case `git` was configured to use a custom `diff` program. The fix is to ignore any `git` configuration. [#373](https://github.com/sourcegraph/src-cli/pull/373) +- `src campaign [apply|preview]` could fail to parse the produced diff in a repository when `git` was configured to use a custom `diff` program. The fix is to ignore any local `git` configuration when running `git` commands. [#373](https://github.com/sourcegraph/src-cli/pull/373) ### Removed