rebase: pass --[no-]signoff option to git am
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 18 Apr 2017 09:29:05 +0000 (11:29 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 19 Apr 2017 03:37:07 +0000 (20:37 -0700)
This makes it easy to sign off a whole patchset before submission.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-rebase.txt
git-rebase.sh
t/t3428-rebase-signoff.sh [new file with mode: 0755]
index de222c81af98c96678841f258342fe2cc3c426a8..76ee47218f2e365a1b0001a64c23d16a2c31ae04 100644 (file)
@@ -365,6 +365,11 @@ default is `--no-fork-point`, otherwise the default is `--fork-point`.
        of the rebased commits (see linkgit:git-am[1]).
        Incompatible with the --interactive option.
 
+--signoff::
+       This flag is passed to 'git am' to sign off all the rebased
+       commits (see linkgit:git-am[1]). Incompatible with the
+       --interactive option.
+
 -i::
 --interactive::
        Make a list of the commits which are about to be rebased.  Let the
index 04f6e44bc8c779d7f4c60c19066820533279324a..0bced9b0959f51f448bd7dd1947b5b658499951b 100755 (executable)
@@ -34,6 +34,7 @@ root!              rebase all reachable commits up to the root(s)
 autosquash         move commits that begin with squash!/fixup! under -i
 committer-date-is-author-date! passed to 'git am'
 ignore-date!       passed to 'git am'
+signoff            passed to 'git am'
 whitespace=!       passed to 'git apply'
 ignore-whitespace! passed to 'git apply'
 C=!                passed to 'git apply'
@@ -320,7 +321,7 @@ do
        --ignore-whitespace)
                git_am_opt="$git_am_opt $1"
                ;;
-       --committer-date-is-author-date|--ignore-date)
+       --committer-date-is-author-date|--ignore-date|--signoff|--no-signoff)
                git_am_opt="$git_am_opt $1"
                force_rebase=t
                ;;
diff --git a/t/t3428-rebase-signoff.sh b/t/t3428-rebase-signoff.sh
new file mode 100755 (executable)
index 0000000..2afb564
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+test_description='git rebase --signoff
+
+This test runs git rebase --signoff and make sure that it works.
+'
+
+. ./test-lib.sh
+
+# A simple file to commit
+cat >file <<EOF
+a
+EOF
+
+# Expected commit message after rebase --signoff
+cat >expected-signed <<EOF
+first
+
+Signed-off-by: $(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/")
+EOF
+
+# Expected commit message after rebase without --signoff (or with --no-signoff)
+cat >expected-unsigned <<EOF
+first
+EOF
+
+
+# We configure an alias to do the rebase --signoff so that
+# on the next subtest we can show that --no-signoff overrides the alias
+test_expect_success 'rebase --signoff adds a sign-off line' '
+       git commit --allow-empty -m "Initial empty commit" &&
+       git add file && git commit -m first &&
+       git config alias.rbs "rebase --signoff" &&
+       git rbs HEAD^ &&
+       git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+       test_cmp expected-signed actual
+'
+
+test_expect_success 'rebase --no-signoff does not add a sign-off line' '
+       git commit --amend -m "first" &&
+       git rbs --no-signoff HEAD^ &&
+       git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+       test_cmp expected-unsigned actual
+'
+
+test_done