Skip to content

Commit

Permalink
Merge branch 'bc/gpg-sign-everywhere'
Browse files Browse the repository at this point in the history
Teach "--gpg-sign" option to many commands that create commits.

* bc/gpg-sign-everywhere:
  pull: add the --gpg-sign option.
  rebase: add the --gpg-sign option
  rebase: parse options in stuck-long mode
  rebase: don't try to match -M option
  rebase: remove useless arguments check
  am: add the --gpg-sign option
  am: parse options in stuck-long mode
  git-sh-setup.sh: add variable to use the stuck-long mode
  cherry-pick, revert: add the --gpg-sign option
  • Loading branch information
Junio C Hamano committed Feb 27, 2014
2 parents d8a1bac + ea230d8 commit 62bef66
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 59 deletions.
6 changes: 5 additions & 1 deletion Documentation/git-am.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SYNOPSIS
[--ignore-date] [--ignore-space-change | --ignore-whitespace]
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
[--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet]
[--[no-]scissors]
[--[no-]scissors] [-S[<keyid>]]
[(<mbox> | <Maildir>)...]
'git am' (--continue | --skip | --abort)

Expand Down Expand Up @@ -119,6 +119,10 @@ default. You can use `--no-utf8` to override this.
Skip the current patch. This is only meaningful when
restarting an aborted patch.

-S[<keyid>]::
--gpg-sign[=<keyid>]::
GPG-sign commits.

--continue::
-r::
--resolved::
Expand Down
7 changes: 6 additions & 1 deletion Documentation/git-cherry-pick.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ git-cherry-pick - Apply the changes introduced by some existing commits
SYNOPSIS
--------
[verse]
'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>...
'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff]
[-S[<keyid>]] <commit>...
'git cherry-pick' --continue
'git cherry-pick' --quit
'git cherry-pick' --abort
Expand Down Expand Up @@ -100,6 +101,10 @@ effect to your index in a row.
--signoff::
Add Signed-off-by line at the end of the commit message.

-S[<keyid>]::
--gpg-sign[=<keyid>]::
GPG-sign commits.

--ff::
If the current HEAD is the same as the parent of the
cherry-pick'ed commit, then a fast forward to this commit will
Expand Down
4 changes: 4 additions & 0 deletions Documentation/git-rebase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ which makes little sense.
specified, `-s recursive`. Note the reversal of 'ours' and
'theirs' as noted above for the `-m` option.

-S[<keyid>]::
--gpg-sign[=<keyid>]::
GPG-sign commits.

-q::
--quiet::
Be quiet. Implies --no-stat.
Expand Down
6 changes: 5 additions & 1 deletion Documentation/git-revert.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ git-revert - Revert some existing commits
SYNOPSIS
--------
[verse]
'git revert' [--[no-]edit] [-n] [-m parent-number] [-s] <commit>...
'git revert' [--[no-]edit] [-n] [-m parent-number] [-s] [-S[<keyid>]] <commit>...
'git revert' --continue
'git revert' --quit
'git revert' --abort
Expand Down Expand Up @@ -80,6 +80,10 @@ more details.
This is useful when reverting more than one commits'
effect to your index in a row.

-S[<keyid>]::
--gpg-sign[=<keyid>]::
GPG-sign commits.

-s::
--signoff::
Add Signed-off-by line at the end of the commit message.
Expand Down
2 changes: 2 additions & 0 deletions builtin/revert.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
OPT_STRING(0, "strategy", &opts->strategy, N_("strategy"), N_("merge strategy")),
OPT_CALLBACK('X', "strategy-option", &opts, N_("option"),
N_("option for merge strategy"), option_parse_x),
{ OPTION_STRING, 'S', "gpg-sign", &opts->gpg_sign, N_("key id"),
N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
OPT_END(),
OPT_END(),
OPT_END(),
Expand Down
1 change: 1 addition & 0 deletions contrib/git-resurrect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ is rather slow but allows you to resurrect other people's topic
branches."

OPTIONS_KEEPDASHDASH=
OPTIONS_STUCKLONG=
OPTIONS_SPEC="\
git resurrect $USAGE
--
Expand Down
26 changes: 17 additions & 9 deletions git-am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

SUBDIRECTORY_OK=Yes
OPTIONS_KEEPDASHDASH=
OPTIONS_STUCKLONG=t
OPTIONS_SPEC="\
git am [options] [(<mbox>|<Maildir>)...]
git am [options] (--continue | --skip | --abort)
Expand Down Expand Up @@ -37,6 +38,7 @@ abort restore the original branch and abort the patching operation.
committer-date-is-author-date lie about committer date
ignore-date use current timestamp for author date
rerere-autoupdate update the index with reused conflict resolution if possible
S,gpg-sign? GPG-sign commits
rebasing* (internal use for git-rebase)"

. git-sh-setup
Expand Down Expand Up @@ -374,6 +376,7 @@ git_apply_opt=
committer_date_is_author_date=
ignore_date=
allow_rerere_autoupdate=
gpg_sign_opt=

if test "$(git config --bool --get am.keepcr)" = true
then
Expand Down Expand Up @@ -413,14 +416,14 @@ it will be removed. Please do not use it anymore."
abort=t ;;
--rebasing)
rebasing=t threeway=t ;;
--resolvemsg)
shift; resolvemsg=$1 ;;
--whitespace|--directory|--exclude|--include)
git_apply_opt="$git_apply_opt $(sq "$1=$2")"; shift ;;
-C|-p)
git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;;
--patch-format)
shift ; patch_format="$1" ;;
--resolvemsg=*)
resolvemsg="${1#--resolvemsg=}" ;;
--whitespace=*|--directory=*|--exclude=*|--include=*)
git_apply_opt="$git_apply_opt $(sq "$1")" ;;
-C*|-p*)
git_apply_opt="$git_apply_opt $(sq "$1")" ;;
--patch-format=*)
patch_format="${1#--patch-format=}" ;;
--reject|--ignore-whitespace|--ignore-space-change)
git_apply_opt="$git_apply_opt $1" ;;
--committer-date-is-author-date)
Expand All @@ -435,6 +438,10 @@ it will be removed. Please do not use it anymore."
keepcr=t ;;
--no-keep-cr)
keepcr=f ;;
--gpg-sign)
gpg_sign_opt=-S ;;
--gpg-sign=*)
gpg_sign_opt="-S${1#--gpg-sign=}" ;;
--)
shift; break ;;
*)
Expand Down Expand Up @@ -899,7 +906,8 @@ did you forget to use 'git add'?"
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
export GIT_COMMITTER_DATE
fi &&
git commit-tree $tree ${parent:+-p} $parent <"$dotest/final-commit"
git commit-tree ${parent:+-p} $parent ${gpg_sign_opt:+"$gpg_sign_opt"} $tree \
<"$dotest/final-commit"
) &&
git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
stop_here $this
Expand Down
1 change: 1 addition & 0 deletions git-instaweb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

PERL='@@PERL@@'
OPTIONS_KEEPDASHDASH=
OPTIONS_STUCKLONG=
OPTIONS_SPEC="\
git instaweb [options] (--start | --stop | --restart)
--
Expand Down
13 changes: 12 additions & 1 deletion git-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ do
--no-verify-signatures)
verify_signatures=--no-verify-signatures
;;
--gpg-sign|-S)
gpg_sign_args=-S
;;
--gpg-sign=*)
gpg_sign_args=$(git rev-parse --sq-quote "-S${1#--gpg-sign=}")
;;
-S*)
gpg_sign_args=$(git rev-parse --sq-quote "$1")
;;
--d|--dr|--dry|--dry-|--dry-r|--dry-ru|--dry-run)
dry_run=--dry-run
;;
Expand Down Expand Up @@ -320,11 +329,13 @@ merge_name=$(git fmt-merge-msg $log_arg <"$GIT_DIR/FETCH_HEAD") || exit
case "$rebase" in
true)
eval="git-rebase $diffstat $strategy_args $merge_args $rebase_args $verbosity"
eval="$eval $gpg_sign_args"
eval="$eval --onto $merge_head ${oldremoteref:-$merge_head}"
;;
*)
eval="git-merge $diffstat $no_commit $verify_signatures $edit $squash $no_ff $ff_only"
eval="$eval $log_arg $strategy_args $merge_args $verbosity $progress"
eval="$eval $log_arg $strategy_args $merge_args $verbosity $progress"
eval="$eval $gpg_sign_args"
eval="$eval \"\$merge_name\" HEAD $merge_head"
;;
esac
Expand Down
1 change: 1 addition & 0 deletions git-quiltimport.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
OPTIONS_KEEPDASHDASH=
OPTIONS_STUCKLONG=
OPTIONS_SPEC="\
git quiltimport [options]
--
Expand Down
8 changes: 5 additions & 3 deletions git-rebase--am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

case "$action" in
continue)
git am --resolved --resolvemsg="$resolvemsg" &&
git am --resolved --resolvemsg="$resolvemsg" \
${gpg_sign_opt:+"$gpg_sign_opt"} &&
move_to_original_branch
return
;;
Expand All @@ -26,7 +27,7 @@ then
# empty commits and even if it didn't the format doesn't really lend
# itself well to recording empty patches. fortunately, cherry-pick
# makes this easy
git cherry-pick --allow-empty "$revisions"
git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty "$revisions"
ret=$?
else
rm -f "$GIT_DIR/rebased-patches"
Expand Down Expand Up @@ -60,7 +61,8 @@ else
return $?
fi

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

rm -f "$GIT_DIR/rebased-patches"
Expand Down
39 changes: 26 additions & 13 deletions git-rebase--interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ exit_with_patch () {
echo "$1" > "$state_dir"/stopped-sha
make_patch $1
git rev-parse --verify HEAD > "$amend"
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
warn "You can amend the commit now, with"
warn
warn " git commit --amend"
warn " git commit --amend $gpg_sign_opt_quoted"
warn
warn "Once you are satisfied with your changes, run"
warn
Expand Down Expand Up @@ -248,7 +249,9 @@ pick_one () {

test -d "$rewritten" &&
pick_one_preserving_merges "$@" && return
output eval git cherry-pick "$strategy_args" $empty_args $ff "$@"
output eval git cherry-pick \
${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
"$strategy_args" $empty_args $ff "$@"
}

pick_one_preserving_merges () {
Expand Down Expand Up @@ -351,15 +354,18 @@ pick_one_preserving_merges () {
new_parents=${new_parents# $first_parent}
merge_args="--no-log --no-ff"
if ! do_with_author output eval \
'git merge $merge_args $strategy_args -m "$msg_content" $new_parents'
'git merge ${gpg_sign_opt:+"$gpg_sign_opt"} \
$merge_args $strategy_args -m "$msg_content" $new_parents'
then
printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
die_with_patch $sha1 "Error redoing merge $sha1"
fi
echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
;;
*)
output eval git cherry-pick "$strategy_args" "$@" ||
output eval git cherry-pick \
${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
"$strategy_args" "$@" ||
die_with_patch $sha1 "Could not pick $sha1"
;;
esac
Expand Down Expand Up @@ -470,7 +476,8 @@ do_pick () {
--no-post-rewrite -n -q -C $1 &&
pick_one -n $1 &&
git commit --allow-empty --allow-empty-message \
--amend --no-post-rewrite -n -q -C $1 ||
--amend --no-post-rewrite -n -q -C $1 \
${gpg_sign_opt:+"$gpg_sign_opt"} ||
die_with_patch $1 "Could not apply $1... $2"
else
pick_one $1 ||
Expand All @@ -497,7 +504,7 @@ do_next () {

mark_action_done
do_pick $sha1 "$rest"
git commit --amend --no-post-rewrite || {
git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || {
warn "Could not amend commit after successfully picking $sha1... $rest"
warn "This is most likely due to an empty commit message, or the pre-commit hook"
warn "failed. If the pre-commit hook failed, you may need to resolve the issue before"
Expand Down Expand Up @@ -542,19 +549,22 @@ do_next () {
squash|s|fixup|f)
# This is an intermediate commit; its message will only be
# used in case of trouble. So use the long version:
do_with_author output git commit --amend --no-verify -F "$squash_msg" ||
do_with_author output git commit --amend --no-verify -F "$squash_msg" \
${gpg_sign_opt:+"$gpg_sign_opt"} ||
die_failed_squash $sha1 "$rest"
;;
*)
# This is the final command of this squash/fixup group
if test -f "$fixup_msg"
then
do_with_author git commit --amend --no-verify -F "$fixup_msg" ||
do_with_author git commit --amend --no-verify -F "$fixup_msg" \
${gpg_sign_opt:+"$gpg_sign_opt"} ||
die_failed_squash $sha1 "$rest"
else
cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
rm -f "$GIT_DIR"/MERGE_MSG
do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e ||
do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \
${gpg_sign_opt:+"$gpg_sign_opt"} ||
die_failed_squash $sha1 "$rest"
fi
rm -f "$squash_msg" "$fixup_msg"
Expand Down Expand Up @@ -819,14 +829,15 @@ continue)
else
if ! test -f "$author_script"
then
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
die "You have staged changes in your working tree. If these changes are meant to be
squashed into the previous commit, run:
git commit --amend
git commit --amend $gpg_sign_opt_quoted
If they are meant to go into a new commit, run:
git commit
git commit $gpg_sign_opt_quoted
In both case, once you're done, continue with:
Expand All @@ -842,10 +853,12 @@ In both case, once you're done, continue with:
die "\
You have uncommitted changes in your working tree. Please, commit them
first and then run 'git rebase --continue' again."
do_with_author git commit --amend --no-verify -F "$msg" -e ||
do_with_author git commit --amend --no-verify -F "$msg" -e \
${gpg_sign_opt:+"$gpg_sign_opt"} ||
die "Could not commit staged changes."
else
do_with_author git commit --no-verify -F "$msg" -e ||
do_with_author git commit --no-verify -F "$msg" -e \
${gpg_sign_opt:+"$gpg_sign_opt"} ||
die "Could not commit staged changes."
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion git-rebase--merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ continue_merge () {
cmt=`cat "$state_dir/current"`
if ! git diff-index --quiet --ignore-submodules HEAD --
then
if ! git commit --no-verify -C "$cmt"
if ! git commit ${gpg_sign_opt:+"$gpg_sign_opt"} --no-verify -C "$cmt"
then
echo "Commit failed, please do not call \"git commit\""
echo "directly, but instead do one of the following: "
Expand Down
Loading

0 comments on commit 62bef66

Please sign in to comment.