Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 14 additions & 11 deletions internal/campaigns/run_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down