git-codereview: rename from 'git-review' to 'git-codereview'

Mostly trivial search and replace, except for hooks.go which
includes a special case to remove the old git-review hooks.

Change-Id: Ic0792bb3e26607e5e0ead88958e46c3ac08288cd
Reviewed-on: https://go-review.googlesource.com/1741
Reviewed-by: Russ Cox <rsc@golang.org>
diff --git a/README b/README
index c79702c..ee35cda 100644
--- a/README
+++ b/README
@@ -1,3 +1,3 @@
-The review tool is a command-line tool for working with Gerrit.
-It wraps git and handles a lot of the mess.
-See "git-review help" for instruction.
+The git-codereview tool is a command-line tool for working with Gerrit.
+
+See https://godoc.org/golang.org/x/review/git-codereview
diff --git a/git-review/api.go b/git-codereview/api.go
similarity index 100%
rename from git-review/api.go
rename to git-codereview/api.go
diff --git a/git-review/branch.go b/git-codereview/branch.go
similarity index 100%
rename from git-review/branch.go
rename to git-codereview/branch.go
diff --git a/git-review/branch_test.go b/git-codereview/branch_test.go
similarity index 100%
rename from git-review/branch_test.go
rename to git-codereview/branch_test.go
diff --git a/git-review/change.go b/git-codereview/change.go
similarity index 99%
rename from git-review/change.go
rename to git-codereview/change.go
index d8dedef..ec6e1b6 100644
--- a/git-review/change.go
+++ b/git-codereview/change.go
@@ -123,7 +123,7 @@
 	// Otherwise, this is a request to create a local work branch.
 	// Check for reserved names. We take everything with a dot.
 	if strings.Contains(target, ".") {
-		dief("invalid branch name %v: branch names with dots are reserved for git-review.", target)
+		dief("invalid branch name %v: branch names with dots are reserved for git-codereview.", target)
 	}
 
 	// If the current branch has a pending commit, building
diff --git a/git-review/change_test.go b/git-codereview/change_test.go
similarity index 100%
rename from git-review/change_test.go
rename to git-codereview/change_test.go
diff --git a/git-review/doc.go b/git-codereview/doc.go
similarity index 86%
rename from git-review/doc.go
rename to git-codereview/doc.go
index c3a37bb..ea9fe12 100644
--- a/git-review/doc.go
+++ b/git-codereview/doc.go
@@ -3,19 +3,19 @@
 // license that can be found in the LICENSE file.
 
 /*
-Git-review manages the code review process for Git changes using a Gerrit
+Git-codereview manages the code review process for Git changes using a Gerrit
 server.
 
-The git-review tool manages "change branches" in the local git repository.
+The git-codereview tool manages "change branches" in the local git repository.
 Each such branch tracks a single commit, or "pending change",
 that is reviewed using a Gerrit server.
 Modifications to the pending change are applied by amending the commit.
 This process implements the "single-commit feature branch" model.
 
-Once installed as git-review, the tool's commands are available through git
+Once installed as git-codereview, the tool's commands are available through git
 either by running
 
-	git review <command>
+	git codereview <command>
 
 or, if aliases are installed, as
 
@@ -26,12 +26,12 @@
 aliases in their .gitconfig file:
 
 	[alias]
-		change = review change
-		gofmt = review gofmt
-		mail = review mail
-		pending = review pending
-		submit = review submit
-		sync = review sync
+		change = codereview change
+		gofmt = codereview gofmt
+		mail = codereview mail
+		pending = codereview pending
+		submit = codereview submit
+		sync = codereview sync
 
 All commands accept these global flags:
 
@@ -46,7 +46,7 @@
 The change command creates and moves between Git branches and maintains the
 pending commits on work branches.
 
-	git review change [-a] [-q] [branchname]
+	git codereview change [-a] [-q] [branchname]
 
 Given a branch name as an argument, the change command switches to the named
 branch, creating it if necessary. If the branch is created and there are staged
@@ -68,7 +68,7 @@
 current work branch, both in the staging area (index) and the working tree
 (local directory).
 
-	git review gofmt [-l]
+	git codereview gofmt [-l]
 
 The -l option causes the command to list the files that need reformatting but
 not reformat them. Otherwise, the gofmt command reformats modified files in
@@ -79,13 +79,13 @@
 
 The help command displays basic usage instructions.
 
-	git review help
+	git codereview help
 
 Hooks
 
 The hooks command installs the Git hooks to enforce code review conventions.
 
-	git review hooks
+	git codereview hooks
 
 The pre-commit hook checks that all Go code is formatted with gofmt and that
 the commit is not being made directly to the master branch.
@@ -103,7 +103,7 @@
 
 The hook-invoke command is an internal command that invokes the named Git hook.
 
-	git review hook-invoke <hook> [args]
+	git codereview hook-invoke <hook> [args]
 
 It is run by the shell scripts installed by the "git review hooks" command.
 
@@ -111,7 +111,7 @@
 
 The mail command starts the code review process for the pending change.
 
-	git review mail [-f] [-r email] [-cc email]
+	git codereview mail [-f] [-r email] [-cc email]
 
 It pushes the pending change commit in the current branch to the Gerrit code
 review server and prints the URL for the change on the server.
@@ -132,7 +132,7 @@
 The pending command prints to standard output the status of all pending changes
 and staged, unstaged, and untracked files in the local repository.
 
-	git review pending [-l]
+	git codereview pending [-l]
 
 The -l flag causes the command to use only locally available information.
 By default, it fetches recent commits and code review information from the
@@ -143,7 +143,7 @@
 The submit command pushes the pending change to the Gerrit server and tells
 Gerrit to submit it to the master branch.
 
-	git review submit
+	git codereview submit
 
 The command fails if there are modified files (staged or unstaged) that are not
 part of the pending change.
@@ -158,7 +158,7 @@
 
 The sync command updates the local repository.
 
-	git review sync
+	git codereview sync
 
 It fetches changes from the remote repository and merges changes from the
 upstream branch to the current branch, rebasing the pending change, if any,
diff --git a/git-review/gofmt.go b/git-codereview/gofmt.go
similarity index 100%
rename from git-review/gofmt.go
rename to git-codereview/gofmt.go
diff --git a/git-review/gofmt_test.go b/git-codereview/gofmt_test.go
similarity index 100%
rename from git-review/gofmt_test.go
rename to git-codereview/gofmt_test.go
diff --git a/git-review/hook.go b/git-codereview/hook.go
similarity index 89%
rename from git-review/hook.go
rename to git-codereview/hook.go
index fd8a9ef..165e6e8 100644
--- a/git-review/hook.go
+++ b/git-codereview/hook.go
@@ -26,20 +26,25 @@
 func installHook() {
 	for _, hookFile := range hookFiles {
 		filename := filepath.Join(repoRoot(), hookPath+hookFile)
+		hookContent := fmt.Sprintf(hookScript, hookFile)
 
-		// Special case: remove old commit-msg shell script
-		// in favor of invoking the git-review hook implementation,
-		// which will be easier to change in the future.
-		if hookFile == "commit-msg" {
-			data, err := ioutil.ReadFile(filename)
-			if err == nil && string(data) == oldCommitMsgHook {
+		if data, err := ioutil.ReadFile(filename); err == nil {
+			// Special case: remove old hooks that use 'git-review'
+			oldHookContent := fmt.Sprintf(oldHookScript, hookFile)
+			if string(data) == oldHookContent {
+				verbosef("removing old %v hook", hookFile)
+				os.Remove(filename)
+			}
+			// Special case: remove old commit-msg shell script
+			// in favor of invoking the git-codereview hook
+			// implementation, which will be easier to change in
+			// the future.
+			if hookFile == "commit-msg" && string(data) == oldCommitMsgHook {
 				verbosef("removing old commit-msg hook")
 				os.Remove(filename)
 			}
 		}
 
-		hookContent := fmt.Sprintf(hookScript, hookFile)
-
 		// If hook file exists, assume it is okay.
 		_, err := os.Stat(filename)
 		if err == nil {
@@ -85,12 +90,16 @@
 }
 
 var hookScript = `#!/bin/sh
+exec git-codereview hook-invoke %s "$@"
+`
+
+var oldHookScript = `#!/bin/sh
 exec git-review hook-invoke %s "$@"
 `
 
 func hookInvoke(args []string) {
 	if len(args) == 0 {
-		dief("usage: git-review hook-invoke <hook-name> [args...]")
+		dief("usage: git-codereview hook-invoke <hook-name> [args...]")
 	}
 	switch args[0] {
 	case "commit-msg":
@@ -106,7 +115,7 @@
 func hookCommitMsg(args []string) {
 	// Add Change-Id to commit message if needed.
 	if len(args) != 1 {
-		dief("usage: git-review hook-invoke commit-msg message.txt\n")
+		dief("usage: git-codereview hook-invoke commit-msg message.txt\n")
 	}
 	file := args[0]
 	data, err := ioutil.ReadFile(file)
diff --git a/git-review/hook_test.go b/git-codereview/hook_test.go
similarity index 95%
rename from git-review/hook_test.go
rename to git-codereview/hook_test.go
index 20b4b68..6cd822f 100644
--- a/git-review/hook_test.go
+++ b/git-codereview/hook_test.go
@@ -42,7 +42,7 @@
 	// Check that hook fails when message is empty.
 	write(t, gt.client+"/empty.txt", "\n\n# just a file with\n# comments\n")
 	testMainDied(t, "hook-invoke", "commit-msg", gt.client+"/empty.txt")
-	const want = "git-review: empty commit message\n"
+	const want = "git-codereview: empty commit message\n"
 	if got := stderr.String(); got != want {
 		t.Fatalf("unexpected output:\ngot: %q\nwant: %q", got, want)
 	}
@@ -158,7 +158,7 @@
 	if err != nil {
 		t.Fatalf("hooks did not write commit-msg hook: %v", err)
 	}
-	if string(data) != "#!/bin/sh\nexec git-review hook-invoke commit-msg \"$@\"\n" {
+	if string(data) != "#!/bin/sh\nexec git-codereview hook-invoke commit-msg \"$@\"\n" {
 		t.Fatalf("invalid commit-msg hook:\n%s", string(data))
 	}
 }
@@ -176,7 +176,7 @@
 	if string(data) == oldCommitMsgHook {
 		t.Fatalf("hooks left old commit-msg hook in place")
 	}
-	if string(data) != "#!/bin/sh\nexec git-review hook-invoke commit-msg \"$@\"\n" {
+	if string(data) != "#!/bin/sh\nexec git-codereview hook-invoke commit-msg \"$@\"\n" {
 		t.Fatalf("invalid commit-msg hook:\n%s", string(data))
 	}
 }
@@ -185,7 +185,7 @@
 	gt := newGitTest(t)
 	defer gt.done()
 
-	trun(t, gt.pwd, "go", "build", "-o", gt.client+"/git-review")
+	trun(t, gt.pwd, "go", "build", "-o", gt.client+"/git-codereview")
 	path := os.Getenv("PATH")
 	defer os.Setenv("PATH", path)
 	os.Setenv("PATH", gt.client+string(filepath.ListSeparator)+path)
diff --git a/git-review/mail.go b/git-codereview/mail.go
similarity index 100%
rename from git-review/mail.go
rename to git-codereview/mail.go
diff --git a/git-review/mail_test.go b/git-codereview/mail_test.go
similarity index 100%
rename from git-review/mail_test.go
rename to git-codereview/mail_test.go
diff --git a/git-review/pending.go b/git-codereview/pending.go
similarity index 95%
rename from git-review/pending.go
rename to git-codereview/pending.go
index 267e2de..63a2cdb 100644
--- a/git-review/pending.go
+++ b/git-codereview/pending.go
@@ -104,7 +104,7 @@
 
 	// Print output, like:
 	//	pending d8fcb99 https://go-review.googlesource.com/1620 (current branch, 1 behind)
-	//		git-review: expand pending output
+	//		git-codereview: expand pending output
 	//
 	//		for pending:
 	//		- show full commit message
@@ -122,16 +122,16 @@
 	//		Code-Review:
 	//			+2 Andrew Gerrand, Rob Pike
 	//		Files in this change:
-	//			git-review/api.go
-	//			git-review/branch.go
-	//			git-review/change.go
-	//			git-review/pending.go
-	//			git-review/review.go
-	//			git-review/submit.go
-	//			git-review/sync.go
+	//			git-codereview/api.go
+	//			git-codereview/branch.go
+	//			git-codereview/change.go
+	//			git-codereview/pending.go
+	//			git-codereview/review.go
+	//			git-codereview/submit.go
+	//			git-codereview/sync.go
 	//		Files untracked:
-	//			git-review/doc.go
-	//			git-review/savedmail.go.txt
+	//			git-codereview/doc.go
+	//			git-codereview/savedmail.go.txt
 	//
 	var buf bytes.Buffer
 	for _, b := range branches {
diff --git a/git-review/review.go b/git-codereview/review.go
similarity index 93%
rename from git-review/review.go
rename to git-codereview/review.go
index fa789ae..0b0ee8e 100644
--- a/git-review/review.go
+++ b/git-codereview/review.go
@@ -2,13 +2,12 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// TODO(adg): print changed files on review sync
 // TODO(adg): translate email addresses without @ by looking up somewhere
 
-// Command git-review provides a simple command-line user interface for
+// Command git-codereview provides a simple command-line user interface for
 // working with git repositories and the Gerrit code review system.
-// See "git-review help" for details.
-package main // import "golang.org/x/review/git-review"
+// See "git-codereview help" for details.
+package main // import "golang.org/x/review/git-codereview"
 
 import (
 	"bytes"
@@ -44,10 +43,10 @@
 
 const help = `Usage: %s <command> ` + globalFlags + `
 
-The review command is a wrapper for the git command that provides a simple
-interface to the "single-commit feature branch" development model.
+The git-codereview command is a wrapper for the git command that provides a
+simple interface to the "single-commit feature branch" development model.
 
-See the full docs for details: https://godoc.org/golang.org/x/review/git-review
+See the docs for details: https://godoc.org/golang.org/x/review/git-codereview
 
 The -v flag prints all Git commands that make changes.
 The -n flag prints all commands that would be run, but does not run them.
diff --git a/git-review/submit.go b/git-codereview/submit.go
similarity index 100%
rename from git-review/submit.go
rename to git-codereview/submit.go
diff --git a/git-review/submit_test.go b/git-codereview/submit_test.go
similarity index 97%
rename from git-review/submit_test.go
rename to git-codereview/submit_test.go
index 66514bd..2f87bbf 100644
--- a/git-review/submit_test.go
+++ b/git-codereview/submit_test.go
@@ -28,14 +28,14 @@
 	trun(t, gt.client, "git", "add", "file1")
 	testMainDied(t, "submit")
 	testPrintedStderr(t, "cannot submit: staged changes exist",
-		"git status", "!git stash", "!git add", "git-review change")
+		"git status", "!git stash", "!git add", "git-codereview change")
 	testNoStdout(t)
 
 	t.Logf("> unstaged changes")
 	write(t, gt.client+"/file1", "actual content")
 	testMainDied(t, "submit")
 	testPrintedStderr(t, "cannot submit: unstaged changes exist",
-		"git status", "git stash", "git add", "git-review change")
+		"git status", "git stash", "git add", "git-codereview change")
 	testNoStdout(t)
 	testRan(t)
 	trun(t, gt.client, "git", "add", "file1")
diff --git a/git-review/sync.go b/git-codereview/sync.go
similarity index 91%
rename from git-review/sync.go
rename to git-codereview/sync.go
index 8df3427..f11e26c 100644
--- a/git-review/sync.go
+++ b/git-codereview/sync.go
@@ -39,7 +39,7 @@
 	if HasStagedChanges() {
 		dief("cannot %s: staged changes exist\n"+
 			"\trun 'git status' to see changes\n"+
-			"\trun 'git-review change' to commit staged changes", cmd)
+			"\trun 'git-codereview change' to commit staged changes", cmd)
 	}
 }
 
@@ -48,6 +48,6 @@
 		dief("cannot %s: unstaged changes exist\n"+
 			"\trun 'git status' to see changes\n"+
 			"\trun 'git stash' to save unstaged changes\n"+
-			"\trun 'git add' and 'git-review change' to commit staged changes", cmd)
+			"\trun 'git add' and 'git-codereview change' to commit staged changes", cmd)
 	}
 }
diff --git a/git-review/sync_test.go b/git-codereview/sync_test.go
similarity index 89%
rename from git-review/sync_test.go
rename to git-codereview/sync_test.go
index 64ad7c6..0fdcbf8 100644
--- a/git-review/sync_test.go
+++ b/git-codereview/sync_test.go
@@ -18,14 +18,14 @@
 	write(t, gt.client+"/file1", "actual content")
 	testMainDied(t, "sync")
 	testPrintedStderr(t, "cannot sync: unstaged changes exist",
-		"git status", "git stash", "git add", "git-review change")
+		"git status", "git stash", "git add", "git-codereview change")
 	testNoStdout(t)
 
 	// check for error with staged changes
 	trun(t, gt.client, "git", "add", "file1")
 	testMainDied(t, "sync")
 	testPrintedStderr(t, "cannot sync: staged changes exist",
-		"git status", "!git stash", "!git add", "git-review change")
+		"git status", "!git stash", "!git add", "git-codereview change")
 	testNoStdout(t)
 
 	// check for success after stash
diff --git a/git-review/util_test.go b/git-codereview/util_test.go
similarity index 94%
rename from git-review/util_test.go
rename to git-codereview/util_test.go
index b095a5f..27ed6c9 100644
--- a/git-review/util_test.go
+++ b/git-codereview/util_test.go
@@ -42,7 +42,7 @@
 }
 
 func newGitTest(t *testing.T) *gitTest {
-	tmpdir, err := ioutil.TempDir("", "git-review-test")
+	tmpdir, err := ioutil.TempDir("", "git-codereview-test")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -67,10 +67,10 @@
 	trun(t, client, "git", "clone", server, ".")
 
 	// write stub hooks to keep installHook from installing its own.
-	// If it installs its own, git will look for git-review on the current path
-	// and may find an old git-review that does just about anything.
+	// If it installs its own, git will look for git-codereview on the current path
+	// and may find an old git-codereview that does just about anything.
 	// In any event, we wouldn't be testing what we want to test.
-	// Tests that want to exercise hooks need to arrange for a git-review
+	// Tests that want to exercise hooks need to arrange for a git-codereview
 	// in the path and replace these with the real ones.
 	for _, h := range hookFiles {
 		write(t, client+"/.git/hooks/"+h, "#!/bin/bash\nexit 0\n")
@@ -150,7 +150,7 @@
 	*noRun = false
 	*verbose = 0
 
-	t.Logf("git-review %s", strings.Join(args, " "))
+	t.Logf("git-codereview %s", strings.Join(args, " "))
 
 	canDie := mainCanDie
 	mainCanDie = false // reset for next invocation
@@ -187,7 +187,7 @@
 	stdoutTrap = new(bytes.Buffer)
 	stderrTrap = new(bytes.Buffer)
 
-	os.Args = append([]string{"git-review"}, args...)
+	os.Args = append([]string{"git-codereview"}, args...)
 	main()
 }