git-codereview: add -s option for change

Some projects (CUE, https://cuelang.org, is one such example) use the
Developer Certificate of Origin (https://developercertificate.org) as an
alternative to a CLA. For such projects, all commit messages must
contain the Signed-off-by trailer, with an email address that matches
the commit author. This requires the -s flag to be passed to git commit.

This change adds a -s flag to git-codereview's change command, which is
then simply passed through to git commit.

Change-Id: I6aeac37a1bcdc6e260ae822d3a03117fb87f846f
Reviewed-on: https://go-review.googlesource.com/c/review/+/334750
Trust: Paul Jolly <paul@myitcv.org.uk>
Run-TryBot: Paul Jolly <paul@myitcv.org.uk>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
diff --git a/git-codereview/change.go b/git-codereview/change.go
index 045fe9c..3bdcd75 100644
--- a/git-codereview/change.go
+++ b/git-codereview/change.go
@@ -16,12 +16,14 @@
 var commitMsg string
 var changeAuto bool
 var changeQuick bool
+var changeSignoff bool
 
 func cmdChange(args []string) {
 	// NOTE: New flags should be added to the usage message below as well as doc.go.
 	flags.StringVar(&commitMsg, "m", "", "specify a commit message")
 	flags.BoolVar(&changeAuto, "a", false, "add changes to any tracked files")
 	flags.BoolVar(&changeQuick, "q", false, "do not edit pending commit msg")
+	flags.BoolVar(&changeSignoff, "s", false, "add a Signed-off-by trailer at the end of the commit message")
 	flags.Parse(args)
 	if len(flags.Args()) > 1 {
 		fmt.Fprintf(stderr(), "Usage: %s change %s [-a] [-m msg] [-q] [branch]\n", progName, globalFlags)
@@ -100,6 +102,9 @@
 		if changeAuto {
 			args = append(args, "-a")
 		}
+		if changeSignoff {
+			args = append(args, "-s")
+		}
 		run("git", args...)
 	}
 	commit(amend)
diff --git a/git-codereview/change_test.go b/git-codereview/change_test.go
index 3e3ea30..cd0cbcc 100644
--- a/git-codereview/change_test.go
+++ b/git-codereview/change_test.go
@@ -185,3 +185,14 @@
 	testMain(t, "change", "-m", "foo: some commit message")
 	testRan(t, "git commit -q --allow-empty -m foo: some commit message")
 }
+
+func TestChangeWithSignoff(t *testing.T) {
+	gt := newGitTest(t)
+	defer gt.done()
+
+	testMain(t, "change", "new_branch")
+	// There are no staged changes, hence an empty commit will be created.
+	// Hence we also need a commit message.
+	testMain(t, "change", "-s", "-m", "foo: bar")
+	testRan(t, "git commit -q --allow-empty -m foo: bar -s")
+}
diff --git a/git-codereview/doc.go b/git-codereview/doc.go
index 2b1af88..a74d7d4 100644
--- a/git-codereview/doc.go
+++ b/git-codereview/doc.go
@@ -157,6 +157,9 @@
 changes). If a commit already exists, it is overwritten. If -q is also
 present, -q will be ignored.
 
+The -s option adds a Signed-off-by trailer at the end of the commit message;
+it is equivalent to the 'git commit' -s option.
+
 As a special case, if branchname is a decimal CL number, such as 987, the change
 command downloads the latest patch set of that CL from the server and switches to it.
 A specific patch set P can be requested by adding /P: 987.2 for patch set 2 of CL 987.