From 08003f6440deafc4e193b159c4acece64f7864b1 Mon Sep 17 00:00:00 2001 From: Andrew Donnellan Date: Thu, 12 Dec 2019 17:04:58 +1100 Subject: pkg/vcs: Unset various git environment variables when invoking git If you try to run git-using tests while the GIT_DIR environment variable (and GIT_WORK_TREE, etc) happens to be set, the tests are going to do fun and exciting things on a repository that isn't the test repository it tries to set up. As it turns out, if you try to run "make test" using git rebase -x, you'll end up with GIT_DIR set to the syzkaller tree. Hilarity ensues. Unset GIT_DIR, GIT_WORK_TREE and a few other environment variables when invoking git - that way it'll default to looking at the working directory that we have given it, which is what we expect. Signed-off-by: Andrew Donnellan --- pkg/vcs/git_test_util.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'pkg/vcs/git_test_util.go') diff --git a/pkg/vcs/git_test_util.go b/pkg/vcs/git_test_util.go index 86713bac0..2f050a2b2 100644 --- a/pkg/vcs/git_test_util.go +++ b/pkg/vcs/git_test_util.go @@ -25,7 +25,11 @@ type TestRepo struct { } func (repo *TestRepo) Git(args ...string) { - if _, err := osutil.RunCmd(time.Minute, repo.Dir, "git", args...); err != nil { + cmd := osutil.Command("git", args...) + cmd.Dir = repo.Dir + cmd.Env = filterEnv() + + if _, err := osutil.Run(time.Minute, cmd); err != nil { repo.t.Fatal(err) } } -- cgit mrf-deployment