Skip to contentSkip to conversation

rebase: add --signoff option

PATCH In review Steffen Prohaska 3 participants 6 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rebase: add --signoff option

When preparing a series of commits for upstream you may need to signoff commits if you forgot to do so earlier. This patch teaches git-rebase to signoff during rebase if you pass the option --signoff.

Notes
1) --signoff cannot be used simultaneously with --interactive.
2) --signoff forces a rebase even if current path is a descendant of <upstream>.

---
 Documentation/git-rebase.txt |    9 +++++++--
 git-rebase--interactive.sh   |    3 +++
 git-rebase.sh                |   10 ++++++++--
 3 files changed, 18 insertions(+), 4 deletions(-)
Documentation/git-rebase.txt +7 -2
index e8e7579..befe337 100644
@@ -8,8 +8,8 @@ git-rebase - Forward-port local commits to the updated upstream head
 SYNOPSIS
 --------
 [verse]
-'git-rebase' [-i | --interactive] [-v | --verbose] [-m | --merge]
-	[-C<n>] [ --whitespace=<option>] [-p | --preserve-merges]
+'git-rebase' [-i | --interactive] [-v | --verbose] [-m | --merge] [-C<n>]
+    [--signoff] [ --whitespace=<option>] [-p | --preserve-merges]
 	[--onto <newbase>] <upstream> [<branch>]
 'git-rebase' --continue | --skip | --abort
 
@@ -201,6 +201,11 @@ OPTIONS
 	is used instead (`git-merge-recursive` when merging a single
 	head, `git-merge-octopus` otherwise).  This implies --merge.
 
+--signoff::
+	Add `Signed-off-by:` line to each commit message, using
+	the committer identity of yourself.
+
+
 -v, \--verbose::
 	Display a diffstat of what changed upstream since the last rebase.
 
git-rebase--interactive.sh +3 -0
index 8568a4f..29cef17 100755
@@ -395,6 +395,9 @@ do
 	-C*)
 		die "Interactive rebase uses merge, so $1 does not make sense"
 		;;
+	--si|--sig|--sign|--signo|--signof|--signoff)
+		die "Interactive rebase doesn't support simultaneous signoff."
+		;;
 	-v|--verbose)
 		VERBOSE=t
 		;;
git-rebase.sh +8 -2
index 1583402..3b06bf4 100755
@@ -46,6 +46,7 @@ dotest=$GIT_DIR/.dotest-merge
 prec=4
 verbose=
 git_am_opt=
+opt_signoff=
 
 continue_merge () {
 	test -n "$prev_head" || die "prev_head must be defined"
@@ -200,7 +201,7 @@ do
 		;;
 	-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
 		--strateg=*|--strategy=*|\
-	-s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
+	-s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
 		case "$#,$1" in
 		*,*=*)
 			strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
@@ -221,6 +222,10 @@ do
 	-C*)
 		git_am_opt="$git_am_opt $1"
 		;;
+	--si|--sig|--sign|--signo|--signof|--signoff)
+		git_am_opt="$git_am_opt --signoff"
+		opt_signoff=t
+		;;
 	-*)
 		usage
 		;;
@@ -302,8 +307,9 @@ branch=$(git rev-parse --verify "${branch_name}^0") || exit
 
 # Check if we are already based on $onto with linear history,
 # but this should be done only when upstream and onto are the same.
+# The check must also be skipped if signoff is requested.
 mb=$(git merge-base "$onto" "$branch")
-if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
+if test "$upstream" = "$onto" && test "$mb" = "$onto" && test -z "$opt_signoff" &&
 	# linear history?
 	! git rev-list --parents "$onto".."$branch" | grep " .* " > /dev/null
 then
Signature · 1 line
1.5.3.3.127.g40d17
#1 lore raw
Quoted 11 lines · Steffen Prohaska

When preparing a series of commits for upstream you may need to signoff commits if you forgot to do so earlier. This patch teaches git-rebase to signoff during rebase if you pass the option --signoff.

Notes
1) --signoff cannot be used simultaneously with --interactive.
2) --signoff forces a rebase even if current path is a descendant of <upstream>.

I do not think it is fatal for --signoff to be incompatible with the "interactive" mode is fatal, but lack of mention in the documentation is. Also this would need test scripts to prevent it from getting broken by future changes by others. I'd like to see ones that test at least the cases where (1) nobody has sign-off, (2) you do not have sign-off but others do, and (3) you already have sign-off at the end.

But I do like the general concept.

#2 lore raw
In reply to Steffen Prohaska

Hi,

Quoted 2 lines · Steffen Prohaska

When preparing a series of commits for upstream you may need to signoff commits if you forgot to do so earlier.

Why not use format-patch's --signoff option for that?

Ciao,
Dscho

#3 lore raw
Quoted 6 lines · Johannes Schindelin
Quoted 2 lines · Steffen Prohaska

When preparing a series of commits for upstream you may need to signoff commits if you forgot to do so earlier.

Why not use format-patch's --signoff option for that?

format-patch is fine for mail. But if I either push the commits to a shared repo (like msysgit's mob) or ask upstream to pull from my public repo format-patch doesn't help directly.

Steffen

#4 lore raw

Hi,

Quoted 4 lines · Steffen Prohaska
Quoted 2 lines · Johannes Schindelin

On Sun, 30 Sep 2007, Steffen Prohaska wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

When preparing a series of commits for upstream you may need to signoff commits if you forgot to do so earlier.

Why not use format-patch's --signoff option for that?

format-patch is fine for mail. But if I either push the commits to a shared repo (like msysgit's mob) or ask upstream to pull from my public repo format-patch doesn't help directly.

Fair enough. But maybe "rebase --interactive" is not too difficult, either?

Ciao,
Dscho

#5 lore raw
Quoted 9 lines · Johannes Schindelin
Quoted 7 lines · Steffen Prohaska
Quoted 5 lines · Johannes Schindelin
Quoted 2 lines · Steffen Prohaska

When preparing a series of commits for upstream you may need to signoff commits if you forgot to do so earlier.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Why not use format-patch's --signoff option for that?

format-patch is fine for mail. But if I either push the commits to a shared repo (like msysgit's mob) or ask upstream to pull from my public repo format-patch doesn't help directly.

Fair enough. But maybe "rebase --interactive" is not too difficult, either?

But not too easy either because "rebase --interactive" is based on "git merge" and not "git am". You can just use a two step process instead and first "rebase --interactive" followed by "rebase --signoff".

Steffen