Skip to content

Commit 2cae477

Browse files
eseligermrnugget
andauthored
Don't use git config that might be present on the host (#373)
* 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. * Try setting committer name as well * Add changelog entry * Update changelog Co-authored-by: Thorsten Ball <[email protected]>
1 parent 850eabe commit 2cae477

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ All notable changes to `src-cli` are documented in this file.
1717

1818
### Fixed
1919

20+
- `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)
21+
2022
### Removed
2123

2224
## 3.21.7

internal/campaigns/run_steps.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ func runSteps(ctx context.Context, wc *WorkspaceCreator, repo *graphql.Repositor
2828

2929
runGitCmd := func(args ...string) ([]byte, error) {
3030
cmd := exec.CommandContext(ctx, "git", args...)
31+
cmd.Env = []string{
32+
// Don't use the system wide git config.
33+
"GIT_CONFIG_NOSYSTEM=1",
34+
// And also not any other, because they can mess up output, change defaults, .. which can do unexpected things.
35+
"GIT_CONFIG=/dev/null",
36+
// Set user.name and user.email in the local repository. The user name and
37+
// e-mail will eventually be ignored anyway, since we're just using the Git
38+
// repository to generate diffs, but we don't want git to generate alarming
39+
// looking warnings.
40+
"GIT_AUTHOR_NAME=Sourcegraph",
41+
42+
"GIT_COMMITTER_NAME=Sourcegraph",
43+
44+
}
3145
cmd.Dir = volumeDir
3246
out, err := cmd.CombinedOutput()
3347
if err != nil {
@@ -41,17 +55,6 @@ func runSteps(ctx context.Context, wc *WorkspaceCreator, repo *graphql.Repositor
4155
return nil, errors.Wrap(err, "git init failed")
4256
}
4357

44-
// Set user.name and user.email in the local repository. The user name and
45-
// e-mail will eventually be ignored anyway, since we're just using the Git
46-
// repository to generate diffs, but we don't want git to generate alarming
47-
// looking warnings.
48-
if _, err := runGitCmd("config", "--local", "user.name", "Sourcegraph"); err != nil {
49-
return nil, errors.Wrap(err, "git config user.name failed")
50-
}
51-
if _, err := runGitCmd("config", "--local", "user.email", "[email protected]"); err != nil {
52-
return nil, errors.Wrap(err, "git config user.email failed")
53-
}
54-
5558
// --force because we want previously "gitignored" files in the repository
5659
if _, err := runGitCmd("add", "--force", "--all"); err != nil {
5760
return nil, errors.Wrap(err, "git add failed")

0 commit comments

Comments
 (0)