rebase: add the --gpg-sign option

Signed-off-by: Nicolas Vigier <boklm@mars-attacks.org> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Vigier committed Feb 10, 2014 at 01:03 UTC 3ee5e54038fd32ee60b24ebd385981aeb14b80a5
5 files changed +47 -17
Documentation/git-rebase.txt
+4
@@ -281,6 +281,10 @@ which makes little sense.
281 specified, `-s recursive`. Note the reversal of 'ours' and
282 'theirs' as noted above for the `-m` option.
283
284 +-S[<keyid>]::
285 +--gpg-sign[=<keyid>]::
286 + GPG-sign commits.
287 +
288 -q::
289 --quiet::
290 Be quiet. Implies --no-stat.
git-rebase--am.sh
+5 -3
@@ -6,7 +6,8 @@
6
7 case "$action" in
8 continue)
9 - git am --resolved --resolvemsg="$resolvemsg" &&
9 + git am --resolved --resolvemsg="$resolvemsg" \
10 + ${gpg_sign_opt:+"$gpg_sign_opt"} &&
11 move_to_original_branch
12 return
13 ;;
@@ -26,7 +27,7 @@ then
27 # empty commits and even if it didn't the format doesn't really lend
28 # itself well to recording empty patches. fortunately, cherry-pick
29 # makes this easy
29 - git cherry-pick --allow-empty "$revisions"
30 + git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty "$revisions"
31 ret=$?
32 else
33 rm -f "$GIT_DIR/rebased-patches"
@@ -60,7 +61,8 @@ else
61 return $?
62 fi
63
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"
66 ret=$?
67
68 rm -f "$GIT_DIR/rebased-patches"
git-rebase--interactive.sh
+26 -13
@@ -179,9 +179,10 @@ exit_with_patch () {
179 echo "$1" > "$state_dir"/stopped-sha
180 make_patch $1
181 git rev-parse --verify HEAD > "$amend"
182 + gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
183 warn "You can amend the commit now, with"
184 warn
184 - warn " git commit --amend"
185 + warn " git commit --amend $gpg_sign_opt_quoted"
186 warn
187 warn "Once you are satisfied with your changes, run"
188 warn
@@ -248,7 +249,9 @@ pick_one () {
249
250 test -d "$rewritten" &&
251 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 "$@"
255 }
256
257 pick_one_preserving_merges () {
@@ -351,7 +354,8 @@ pick_one_preserving_merges () {
354 new_parents=${new_parents# $first_parent}
355 merge_args="--no-log --no-ff"
356 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'
359 then
360 printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
361 die_with_patch $sha1 "Error redoing merge $sha1"
@@ -359,7 +363,9 @@ pick_one_preserving_merges () {
363 echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
364 ;;
365 *)
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" "$@" ||
369 die_with_patch $sha1 "Could not pick $sha1"
370 ;;
371 esac
@@ -470,7 +476,8 @@ do_pick () {
476 --no-post-rewrite -n -q -C $1 &&
477 pick_one -n $1 &&
478 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"} ||
481 die_with_patch $1 "Could not apply $1... $2"
482 else
483 pick_one $1 ||
@@ -497,7 +504,7 @@ do_next () {
504
505 mark_action_done
506 do_pick $sha1 "$rest"
500 - git commit --amend --no-post-rewrite || {
507 + git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || {
508 warn "Could not amend commit after successfully picking $sha1... $rest"
509 warn "This is most likely due to an empty commit message, or the pre-commit hook"
510 warn "failed. If the pre-commit hook failed, you may need to resolve the issue before"
@@ -542,19 +549,22 @@ do_next () {
549 squash|s|fixup|f)
550 # This is an intermediate commit; its message will only be
551 # 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"} ||
554 die_failed_squash $sha1 "$rest"
555 ;;
556 *)
557 # This is the final command of this squash/fixup group
558 if test -f "$fixup_msg"
559 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"} ||
562 die_failed_squash $sha1 "$rest"
563 else
564 cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
565 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"} ||
568 die_failed_squash $sha1 "$rest"
569 fi
570 rm -f "$squash_msg" "$fixup_msg"
@@ -819,14 +829,15 @@ continue)
829 else
830 if ! test -f "$author_script"
831 then
832 + gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
833 die "You have staged changes in your working tree. If these changes are meant to be
834 squashed into the previous commit, run:
835
825 - git commit --amend
836 + git commit --amend $gpg_sign_opt_quoted
837
838 If they are meant to go into a new commit, run:
839
829 - git commit
840 + git commit $gpg_sign_opt_quoted
841
842 In both case, once you're done, continue with:
843
@@ -842,10 +853,12 @@ In both case, once you're done, continue with:
853 die "\
854 You have uncommitted changes in your working tree. Please, commit them
855 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"} ||
858 die "Could not commit staged changes."
859 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"} ||
862 die "Could not commit staged changes."
863 fi
864 fi
git-rebase--merge.sh
+1 -1
@@ -27,7 +27,7 @@ continue_merge () {
27 cmt=`cat "$state_dir/current"`
28 if ! git diff-index --quiet --ignore-submodules HEAD --
29 then
30 - if ! git commit --no-verify -C "$cmt"
30 + if ! git commit ${gpg_sign_opt:+"$gpg_sign_opt"} --no-verify -C "$cmt"
31 then
32 echo "Commit failed, please do not call \"git commit\""
33 echo "directly, but instead do one of the following: "
git-rebase.sh
+11
@@ -37,6 +37,7 @@ ignore-date! passed to 'git am'
37 whitespace=! passed to 'git apply'
38 ignore-whitespace! passed to 'git apply'
39 C=! passed to 'git apply'
40 +S,gpg-sign? GPG-sign commits
41 Actions:
42 continue! continue
43 abort! abort and check out the original branch
@@ -85,6 +86,7 @@ preserve_merges=
86 autosquash=
87 keep_empty=
88 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
89 +gpg_sign_opt=
90
91 read_basic_state () {
92 test -f "$state_dir/head-name" &&
@@ -107,6 +109,8 @@ read_basic_state () {
109 strategy_opts="$(cat "$state_dir"/strategy_opts)"
110 test -f "$state_dir"/allow_rerere_autoupdate &&
111 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)"
114 }
115
116 write_basic_state () {
@@ -120,6 +124,7 @@ write_basic_state () {
124 "$state_dir"/strategy_opts
125 test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \
126 "$state_dir"/allow_rerere_autoupdate
127 + test -n "$gpg_sign_opt" && echo "$gpg_sign_opt" > "$state_dir"/gpg_sign_opt
128 }
129
130 output () {
@@ -324,6 +329,12 @@ do
329 --rerere-autoupdate|--no-rerere-autoupdate)
330 allow_rerere_autoupdate="$1"
331 ;;
332 + --gpg-sign)
333 + gpg_sign_opt=-S
334 + ;;
335 + --gpg-sign=*)
336 + gpg_sign_opt="-S${1#--gpg-sign=}"
337 + ;;
338 --)
339 shift
340 break