diff options
| author | siddharth ravikumar <s@ricketyspace.net> | 2023-09-11 22:34:15 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-10-18 12:53:42 +0000 |
| commit | 8be3abfe097ddf04b28eec2783249d29b3a48dae (patch) | |
| tree | 7839249866fdd7da93221eaf0ef9ee2b82e44ba4 /git-codereview/hook_test.go | |
| parent | 406355a4df8af4b140e43c56c0c4c9869471edca (diff) | |
| download | go-x-review-8be3abfe097ddf04b28eec2783249d29b3a48dae.tar.xz | |
git-codereview: make hooks command report conflicting hooksv1.8.0
Display warning message when a hook is already installed and is
different from the one installed by git-codereview.
Improves upon CL 184417.
Fixes golang/go#16777
Change-Id: I7579a3e86572e8b74f92317973e7cc7094b3942d
Reviewed-on: https://go-review.googlesource.com/c/review/+/377034
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Diffstat (limited to 'git-codereview/hook_test.go')
| -rw-r--r-- | git-codereview/hook_test.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/git-codereview/hook_test.go b/git-codereview/hook_test.go index d4ffbc4..8ffe234 100644 --- a/git-codereview/hook_test.go +++ b/git-codereview/hook_test.go @@ -475,6 +475,8 @@ func TestHooksOverwriteOldCommitMsg(t *testing.T) { gt := newGitTest(t) defer gt.done() + gt.removeStubHooks() + mkdir(t, gt.client+"/.git/hooks") write(t, gt.client+"/.git/hooks/commit-msg", oldCommitMsgHook, 0755) testMain(t, "hooks") // install hooks data, err := ioutil.ReadFile(gt.client + "/.git/hooks/commit-msg") @@ -489,6 +491,26 @@ func TestHooksOverwriteOldCommitMsg(t *testing.T) { } } +// Test that 'git-codereview hooks' reports when it fails to write hooks. +// See go.dev/issue/16777. +func TestHooksReportConflictingContent(t *testing.T) { + gt := newGitTest(t) + defer gt.done() + + const pretendUserHook = "#!/bin/sh\necho 'pretend to be a custom hook'\nexit 1\n" + for _, h := range hookFiles { + write(t, gt.client+"/.git/hooks/"+h, pretendUserHook, 0755) + } + testMainDied(t, "hooks") // install hooks + testPrintedStderr(t, "Hooks files", "already exist.", "To install git-codereview hooks, delete these files and re-run 'git-codereview hooks'.") + for _, h := range hookFiles { + data := read(t, gt.client+"/.git/hooks/"+h) + if string(data) != pretendUserHook { + t.Errorf("existing hook file %s was unexpectedly modified", h) + } + } +} + func testInstallHook(t *testing.T, gt *gitTest) (restore func()) { trun(t, gt.pwd, "go", "build", "-o", gt.client+"/git-codereview") path := os.Getenv("PATH") |
