diff --git a/CHANGELOG.md b/CHANGELOG.md index ed8f584ccc..f17a14c8aa 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 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 ## 3.21.7 diff --git a/internal/campaigns/run_steps.go b/internal/campaigns/run_steps.go index 6ef650f449..79aa1ac432 100644 --- a/internal/campaigns/run_steps.go +++ b/internal/campaigns/run_steps.go @@ -28,6 +28,20 @@ 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", + "GIT_COMMITTER_NAME=Sourcegraph", + "GIT_COMMITTER_EMAIL=campaigns@sourcegraph.com", + } cmd.Dir = volumeDir out, err := cmd.CombinedOutput() if err != nil { @@ -41,17 +55,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")