diff --git a/pkg/common/git_test.go b/pkg/common/git_test.go index 3c72b8e..bd70d87 100644 --- a/pkg/common/git_test.go +++ b/pkg/common/git_test.go @@ -49,6 +49,27 @@ func testDir(t *testing.T) string { return basedir } +func cleanGitHooks(dir string) error { + hooksDir := filepath.Join(dir, ".git", "hooks") + files, err := ioutil.ReadDir(hooksDir) + if err != nil { + if os.IsNotExist(err) { + return nil + } + return err + } + for _, f := range files { + if f.IsDir() { + continue + } + relName := filepath.Join(hooksDir, f.Name()) + if err := os.Remove(relName); err != nil { + return err + } + } + return nil +} + func TestFindGitRemoteURL(t *testing.T) { assert := assert.New(t) @@ -56,6 +77,8 @@ func TestFindGitRemoteURL(t *testing.T) { gitConfig() err := gitCmd("init", basedir) assert.NoError(err) + err = cleanGitHooks(basedir) + assert.NoError(err) remoteURL := "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo-name" err = gitCmd("config", "-f", fmt.Sprintf("%s/.git/config", basedir), "--add", "remote.origin.url", remoteURL) @@ -138,6 +161,7 @@ func TestGitFindRef(t *testing.T) { dir := filepath.Join(basedir, name) require.NoError(t, os.MkdirAll(dir, 0755)) require.NoError(t, gitCmd("-C", dir, "init")) + require.NoError(t, cleanGitHooks(dir)) tt.Prepare(t, dir) ref, err := FindGitRef(dir) tt.Assert(t, ref, err)