Skip to content

Commit 3ee5e54

Browse files
boklmgitster
authored andcommitted
rebase: add the --gpg-sign option
Signed-off-by: Nicolas Vigier <[email protected]> Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b6e9e73 commit 3ee5e54

File tree

5 files changed

+47
-17
lines changed

5 files changed

+47
-17
lines changed

Documentation/git-rebase.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ which makes little sense.
281281
specified, `-s recursive`. Note the reversal of 'ours' and
282282
'theirs' as noted above for the `-m` option.
283283

284+
-S[<keyid>]::
285+
--gpg-sign[=<keyid>]::
286+
GPG-sign commits.
287+
284288
-q::
285289
--quiet::
286290
Be quiet. Implies --no-stat.

git-rebase--am.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
case "$action" in
88
continue)
9-
git am --resolved --resolvemsg="$resolvemsg" &&
9+
git am --resolved --resolvemsg="$resolvemsg" \
10+
${gpg_sign_opt:+"$gpg_sign_opt"} &&
1011
move_to_original_branch
1112
return
1213
;;
@@ -26,7 +27,7 @@ then
2627
# empty commits and even if it didn't the format doesn't really lend
2728
# itself well to recording empty patches. fortunately, cherry-pick
2829
# makes this easy
29-
git cherry-pick --allow-empty "$revisions"
30+
git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty "$revisions"
3031
ret=$?
3132
else
3233
rm -f "$GIT_DIR/rebased-patches"
@@ -60,7 +61,8 @@ else
6061
return $?
6162
fi
6263

63-
git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" <"$GIT_DIR/rebased-patches"
64+
git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" \
65+
${gpg_sign_opt:+"$gpg_sign_opt"} <"$GIT_DIR/rebased-patches"
6466
ret=$?
6567

6668
rm -f "$GIT_DIR/rebased-patches"

git-rebase--interactive.sh

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,10 @@ exit_with_patch () {
179179
echo "$1" > "$state_dir"/stopped-sha
180180
make_patch $1
181181
git rev-parse --verify HEAD > "$amend"
182+
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
182183
warn "You can amend the commit now, with"
183184
warn
184-
warn " git commit --amend"
185+
warn " git commit --amend $gpg_sign_opt_quoted"
185186
warn
186187
warn "Once you are satisfied with your changes, run"
187188
warn
@@ -248,7 +249,9 @@ pick_one () {
248249

249250
test -d "$rewritten" &&
250251
pick_one_preserving_merges "$@" && return
251-
output eval git cherry-pick "$strategy_args" $empty_args $ff "$@"
252+
output eval git cherry-pick \
253+
${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
254+
"$strategy_args" $empty_args $ff "$@"
252255
}
253256

254257
pick_one_preserving_merges () {
@@ -351,15 +354,18 @@ pick_one_preserving_merges () {
351354
new_parents=${new_parents# $first_parent}
352355
merge_args="--no-log --no-ff"
353356
if ! do_with_author output eval \
354-
'git merge $merge_args $strategy_args -m "$msg_content" $new_parents'
357+
'git merge ${gpg_sign_opt:+"$gpg_sign_opt"} \
358+
$merge_args $strategy_args -m "$msg_content" $new_parents'
355359
then
356360
printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
357361
die_with_patch $sha1 "Error redoing merge $sha1"
358362
fi
359363
echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
360364
;;
361365
*)
362-
output eval git cherry-pick "$strategy_args" "$@" ||
366+
output eval git cherry-pick \
367+
${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
368+
"$strategy_args" "$@" ||
363369
die_with_patch $sha1 "Could not pick $sha1"
364370
;;
365371
esac
@@ -470,7 +476,8 @@ do_pick () {
470476
--no-post-rewrite -n -q -C $1 &&
471477
pick_one -n $1 &&
472478
git commit --allow-empty --allow-empty-message \
473-
--amend --no-post-rewrite -n -q -C $1 ||
479+
--amend --no-post-rewrite -n -q -C $1 \
480+
${gpg_sign_opt:+"$gpg_sign_opt"} ||
474481
die_with_patch $1 "Could not apply $1... $2"
475482
else
476483
pick_one $1 ||
@@ -497,7 +504,7 @@ do_next () {
497504

498505
mark_action_done
499506
do_pick $sha1 "$rest"
500-
git commit --amend --no-post-rewrite || {
507+
git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || {
501508
warn "Could not amend commit after successfully picking $sha1... $rest"
502509
warn "This is most likely due to an empty commit message, or the pre-commit hook"
503510
warn "failed. If the pre-commit hook failed, you may need to resolve the issue before"
@@ -542,19 +549,22 @@ do_next () {
542549
squash|s|fixup|f)
543550
# This is an intermediate commit; its message will only be
544551
# used in case of trouble. So use the long version:
545-
do_with_author output git commit --amend --no-verify -F "$squash_msg" ||
552+
do_with_author output git commit --amend --no-verify -F "$squash_msg" \
553+
${gpg_sign_opt:+"$gpg_sign_opt"} ||
546554
die_failed_squash $sha1 "$rest"
547555
;;
548556
*)
549557
# This is the final command of this squash/fixup group
550558
if test -f "$fixup_msg"
551559
then
552-
do_with_author git commit --amend --no-verify -F "$fixup_msg" ||
560+
do_with_author git commit --amend --no-verify -F "$fixup_msg" \
561+
${gpg_sign_opt:+"$gpg_sign_opt"} ||
553562
die_failed_squash $sha1 "$rest"
554563
else
555564
cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
556565
rm -f "$GIT_DIR"/MERGE_MSG
557-
do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e ||
566+
do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \
567+
${gpg_sign_opt:+"$gpg_sign_opt"} ||
558568
die_failed_squash $sha1 "$rest"
559569
fi
560570
rm -f "$squash_msg" "$fixup_msg"
@@ -819,14 +829,15 @@ continue)
819829
else
820830
if ! test -f "$author_script"
821831
then
832+
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
822833
die "You have staged changes in your working tree. If these changes are meant to be
823834
squashed into the previous commit, run:
824835
825-
git commit --amend
836+
git commit --amend $gpg_sign_opt_quoted
826837
827838
If they are meant to go into a new commit, run:
828839
829-
git commit
840+
git commit $gpg_sign_opt_quoted
830841
831842
In both case, once you're done, continue with:
832843
@@ -842,10 +853,12 @@ In both case, once you're done, continue with:
842853
die "\
843854
You have uncommitted changes in your working tree. Please, commit them
844855
first and then run 'git rebase --continue' again."
845-
do_with_author git commit --amend --no-verify -F "$msg" -e ||
856+
do_with_author git commit --amend --no-verify -F "$msg" -e \
857+
${gpg_sign_opt:+"$gpg_sign_opt"} ||
846858
die "Could not commit staged changes."
847859
else
848-
do_with_author git commit --no-verify -F "$msg" -e ||
860+
do_with_author git commit --no-verify -F "$msg" -e \
861+
${gpg_sign_opt:+"$gpg_sign_opt"} ||
849862
die "Could not commit staged changes."
850863
fi
851864
fi

git-rebase--merge.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ continue_merge () {
2727
cmt=`cat "$state_dir/current"`
2828
if ! git diff-index --quiet --ignore-submodules HEAD --
2929
then
30-
if ! git commit --no-verify -C "$cmt"
30+
if ! git commit ${gpg_sign_opt:+"$gpg_sign_opt"} --no-verify -C "$cmt"
3131
then
3232
echo "Commit failed, please do not call \"git commit\""
3333
echo "directly, but instead do one of the following: "

git-rebase.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ignore-date! passed to 'git am'
3737
whitespace=! passed to 'git apply'
3838
ignore-whitespace! passed to 'git apply'
3939
C=! passed to 'git apply'
40+
S,gpg-sign? GPG-sign commits
4041
Actions:
4142
continue! continue
4243
abort! abort and check out the original branch
@@ -85,6 +86,7 @@ preserve_merges=
8586
autosquash=
8687
keep_empty=
8788
test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
89+
gpg_sign_opt=
8890

8991
read_basic_state () {
9092
test -f "$state_dir/head-name" &&
@@ -107,6 +109,8 @@ read_basic_state () {
107109
strategy_opts="$(cat "$state_dir"/strategy_opts)"
108110
test -f "$state_dir"/allow_rerere_autoupdate &&
109111
allow_rerere_autoupdate="$(cat "$state_dir"/allow_rerere_autoupdate)"
112+
test -f "$state_dir"/gpg_sign_opt &&
113+
gpg_sign_opt="$(cat "$state_dir"/gpg_sign_opt)"
110114
}
111115

112116
write_basic_state () {
@@ -120,6 +124,7 @@ write_basic_state () {
120124
"$state_dir"/strategy_opts
121125
test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \
122126
"$state_dir"/allow_rerere_autoupdate
127+
test -n "$gpg_sign_opt" && echo "$gpg_sign_opt" > "$state_dir"/gpg_sign_opt
123128
}
124129

125130
output () {
@@ -324,6 +329,12 @@ do
324329
--rerere-autoupdate|--no-rerere-autoupdate)
325330
allow_rerere_autoupdate="$1"
326331
;;
332+
--gpg-sign)
333+
gpg_sign_opt=-S
334+
;;
335+
--gpg-sign=*)
336+
gpg_sign_opt="-S${1#--gpg-sign=}"
337+
;;
327338
--)
328339
shift
329340
break

0 commit comments

Comments
 (0)