From 2e4fd9a232c3368afeca71043fd7538ed11c681c Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Thu, 15 Jul 2021 10:29:06 +0100 Subject: 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 Run-TryBot: Paul Jolly TryBot-Result: Go Bot Reviewed-by: Russ Cox --- git-codereview/change.go | 5 +++++ git-codereview/change_test.go | 11 +++++++++++ git-codereview/doc.go | 3 +++ 3 files changed, 19 insertions(+) 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 @@ import ( 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 @@ func commitChanges(amend bool) { 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 @@ func TestChangeWithMessage(t *testing.T) { 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 @@ option is only useful when creating commits (e.g. if there are unstaged 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. -- cgit v1.3