Hello,
Here is a series of patches to add the --gpg-sign option to be able to gpg sign commits, to the cherry-pick, revert, am and rebase commands.
Nicolas
threads / discuss / 35267
Subject: Adding --gpg-sign to cherry-pick, revert, am, rebase
Hello,
Here is a series of patches to add the --gpg-sign option to be able to gpg sign commits, to the cherry-pick, revert, am and rebase commands.
Nicolas
[PATCH 1/8] cherry-pick, revert: add the --gpg-sign option
Signed-off-by: Nicolas Vigier <boklm@mars-attacks.org> --- Documentation/git-cherry-pick.txt | 7 ++++++- Documentation/git-revert.txt | 6 +++++- builtin/revert.c | 2 ++ sequencer.c | 7 +++++++ sequencer.h | 2 ++ 5 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt index c205d2363e42..f1e6b2fd6d15 100644 --- a/Documentation/git-cherry-pick.txt +++ b/Documentation/git-cherry-pick.txt @@ -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 @@ -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 diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt index 2de67a54962b..9eb83f01a451 100644 --- a/Documentation/git-revert.txt +++ b/Documentation/git-revert.txt @@ -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 @@ -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. diff --git a/builtin/revert.c b/builtin/revert.c index 87659c9fdb74..065d88dd05ea 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -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(), diff --git a/sequencer.c b/sequencer.c index 06e52b4c83ff..b10a90fe70f6 100644 --- a/sequencer.c +++ b/sequencer.c @@ -392,11 +392,18 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts, { struct argv_array array; int rc; + char *gpg_sign; argv_array_init(&array); argv_array_push(&array, "commit"); argv_array_push(&array, "-n"); + if (opts->gpg_sign) { + gpg_sign = xmalloc(3 + strlen(opts->gpg_sign)); + sprintf(gpg_sign, "-S%s", opts->gpg_sign); + argv_array_push(&array, gpg_sign); + free(gpg_sign); + } if (opts->signoff) argv_array_push(&array, "-s"); if (!opts->edit) { diff --git a/sequencer.h b/sequencer.h index 1fc22dcabe13..db43e9cf86dc 100644 --- a/sequencer.h +++ b/sequencer.h @@ -37,6 +37,8 @@ struct replay_opts { int mainline; + const char *gpg_sign; + /* Merge strategy */ const char *strategy; const char **xopts;
-- 1.8.4.2
Re: [PATCH 1/8] cherry-pick, revert: add the --gpg-sign option
On Sun, Nov 03, 2013 at 04:54:17PM +0100, Nicolas Vigier wrote:
> diff --git a/sequencer.h b/sequencer.h
> index 1fc22dcabe13..db43e9cf86dc 100644
> --- a/sequencer.h
> +++ b/sequencer.h
> @@ -37,6 +37,8 @@ struct replay_opts {
>
> int mainline;
>
> + const char *gpg_sign;
> +
> /* Merge strategy */
> const char *strategy;
> const char **xopts;One thing you're missing here is the ability to save and retrieve the options. You might be cherry-picking or reverting multiple commits and get interrupted (maybe one is already applied) and need to use --continue.
So populate_options_cb and save_opts need to learn about this sequencer option so that after --continue, commits continue to get signed.
-- brian m. carlson / brian with sandals: Houston, Texas, US +1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
Re: [PATCH 1/8] cherry-pick, revert: add the --gpg-sign option
On Sun, 03 Nov 2013, brian m. carlson wrote:
> On Sun, Nov 03, 2013 at 04:54:17PM +0100, Nicolas Vigier wrote:
> > diff --git a/sequencer.h b/sequencer.h
> > index 1fc22dcabe13..db43e9cf86dc 100644
> > --- a/sequencer.h
> > +++ b/sequencer.h
> > @@ -37,6 +37,8 @@ struct replay_opts {
> >
> > int mainline;
> >
> > + const char *gpg_sign;
> > +
> > /* Merge strategy */
> > const char *strategy;
> > const char **xopts;
>
> One thing you're missing here is the ability to save and retrieve the
> options. You might be cherry-picking or reverting multiple commits and
> get interrupted (maybe one is already applied) and need to use
> --continue.
>
> So populate_options_cb and save_opts need to learn about this sequencer
> option so that after --continue, commits continue to get signed.Ah indeed, I didn't think about that. I will look at it. Thanks.
[PATCH] cherry-pick, revert: add the --gpg-sign option
Signed-off-by: Nicolas Vigier <boklm@mars-attacks.org> Helped-by: Brian M. Carlson <sandals@crustytoothpaste.net> --- Documentation/git-cherry-pick.txt | 7 ++++++- Documentation/git-revert.txt | 6 +++++- builtin/revert.c | 2 ++ sequencer.c | 11 +++++++++++ sequencer.h | 2 ++ 5 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt index c205d2363e42..f1e6b2fd6d15 100644 --- a/Documentation/git-cherry-pick.txt +++ b/Documentation/git-cherry-pick.txt @@ -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 @@ -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 diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt index 2de67a54962b..9eb83f01a451 100644 --- a/Documentation/git-revert.txt +++ b/Documentation/git-revert.txt @@ -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 @@ -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. diff --git a/builtin/revert.c b/builtin/revert.c index 87659c9fdb74..065d88dd05ea 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -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(), diff --git a/sequencer.c b/sequencer.c index 06e52b4c83ff..2048cd81b3b2 100644 --- a/sequencer.c +++ b/sequencer.c @@ -392,11 +392,18 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts, { struct argv_array array; int rc; + char *gpg_sign; argv_array_init(&array); argv_array_push(&array, "commit"); argv_array_push(&array, "-n"); + if (opts->gpg_sign) { + gpg_sign = xmalloc(3 + strlen(opts->gpg_sign)); + sprintf(gpg_sign, "-S%s", opts->gpg_sign); + argv_array_push(&array, gpg_sign); + free(gpg_sign); + } if (opts->signoff) argv_array_push(&array, "-s"); if (!opts->edit) { @@ -808,6 +815,8 @@ static int populate_opts_cb(const char *key, const char *value, void *data) opts->mainline = git_config_int(key, value); else if (!strcmp(key, "options.strategy")) git_config_string(&opts->strategy, key, value); + else if (!strcmp(key, "options.gpg-sign")) + git_config_string(&opts->gpg_sign, key, value); else if (!strcmp(key, "options.strategy-option")) { ALLOC_GROW(opts->xopts, opts->xopts_nr + 1, opts->xopts_alloc); opts->xopts[opts->xopts_nr++] = xstrdup(value); @@ -981,6 +990,8 @@ static void save_opts(struct replay_opts *opts) } if (opts->strategy) git_config_set_in_file(opts_file, "options.strategy", opts->strategy); + if (opts->gpg_sign) + git_config_set_in_file(opts_file, "options.gpg-sign", opts->gpg_sign); if (opts->xopts) { int i; for (i = 0; i < opts->xopts_nr; i++) diff --git a/sequencer.h b/sequencer.h index 1fc22dcabe13..db43e9cf86dc 100644 --- a/sequencer.h +++ b/sequencer.h @@ -37,6 +37,8 @@ struct replay_opts { int mainline; + const char *gpg_sign; + /* Merge strategy */ const char *strategy; const char **xopts;
-- 1.8.4.2
Re: [PATCH] cherry-pick, revert: add the --gpg-sign option
On Sun, Nov 03, 2013 at 07:46:15PM +0100, Nicolas Vigier wrote:
> diff --git a/sequencer.c b/sequencer.c
> index 06e52b4c83ff..2048cd81b3b2 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -392,11 +392,18 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
> {
> struct argv_array array;
> int rc;
> + char *gpg_sign;
>
> argv_array_init(&array);
> argv_array_push(&array, "commit");
> argv_array_push(&array, "-n");
>
> + if (opts->gpg_sign) {
> + gpg_sign = xmalloc(3 + strlen(opts->gpg_sign));
> + sprintf(gpg_sign, "-S%s", opts->gpg_sign);
> + argv_array_push(&array, gpg_sign);
> + free(gpg_sign);
> + }
> if (opts->signoff)
> argv_array_push(&array, "-s");
> if (!opts->edit) {
> @@ -808,6 +815,8 @@ static int populate_opts_cb(const char *key, const char *value, void *data)
> opts->mainline = git_config_int(key, value);
> else if (!strcmp(key, "options.strategy"))
> git_config_string(&opts->strategy, key, value);
> + else if (!strcmp(key, "options.gpg-sign"))
> + git_config_string(&opts->gpg_sign, key, value);
> else if (!strcmp(key, "options.strategy-option")) {
> ALLOC_GROW(opts->xopts, opts->xopts_nr + 1, opts->xopts_alloc);
> opts->xopts[opts->xopts_nr++] = xstrdup(value);
> @@ -981,6 +990,8 @@ static void save_opts(struct replay_opts *opts)
> }
> if (opts->strategy)
> git_config_set_in_file(opts_file, "options.strategy", opts->strategy);
> + if (opts->gpg_sign)
> + git_config_set_in_file(opts_file, "options.gpg-sign", opts->gpg_sign);
> if (opts->xopts) {
> int i;
> for (i = 0; i < opts->xopts_nr; i++)Looks much better. That's essentially what I did when I was patching that particular area. Thanks for posting this patch set; it's something I've wanted for a while, but never got around to actually doing myself.
-- brian m. carlson / brian with sandals: Houston, Texas, US +1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
[PATCH 2/8] git-sh-setup.sh: add variable to use the stuck-long mode
If the variable $OPTIONS_STUCKLONG is not empty, then rev-parse option parsing is done in --stuck-long mode.
Signed-off-by: Nicolas Vigier <boklm@mars-attacks.org> --- contrib/examples/git-checkout.sh | 1 + contrib/examples/git-clean.sh | 1 + contrib/examples/git-clone.sh | 1 + contrib/examples/git-merge.sh | 1 + contrib/examples/git-repack.sh | 1 + contrib/git-resurrect.sh | 1 + git-am.sh | 1 + git-instaweb.sh | 1 + git-quiltimport.sh | 1 + git-rebase.sh | 1 + git-request-pull.sh | 1 + git-sh-setup.sh | 2 ++ 12 files changed, 13 insertions(+)
diff --git a/contrib/examples/git-checkout.sh b/contrib/examples/git-checkout.sh index 1a7689a48f07..d7507edaf564 100755 --- a/contrib/examples/git-checkout.sh +++ b/contrib/examples/git-checkout.sh @@ -1,6 +1,7 @@ #!/bin/sh OPTIONS_KEEPDASHDASH=t +OPTIONS_STUCKLONG= OPTIONS_SPEC="\ git-checkout [options] [<branch>] [<paths>...] -- diff --git a/contrib/examples/git-clean.sh b/contrib/examples/git-clean.sh index 01c95e9fe8a1..9d881cd90dfb 100755 --- a/contrib/examples/git-clean.sh +++ b/contrib/examples/git-clean.sh @@ -4,6 +4,7 @@ # OPTIONS_KEEPDASHDASH= +OPTIONS_STUCKLONG= OPTIONS_SPEC="\ git-clean [options] <paths>... diff --git a/contrib/examples/git-clone.sh b/contrib/examples/git-clone.sh index 547228e13ce6..ea4757db33ab 100755 --- a/contrib/examples/git-clone.sh +++ b/contrib/examples/git-clone.sh @@ -8,6 +8,7 @@ # See git-sh-setup why. unset CDPATH +OPTIONS_STUCKLONG= OPTIONS_SPEC="\ git-clone [options] [--] <repo> [<dir>] -- diff --git a/contrib/examples/git-merge.sh b/contrib/examples/git-merge.sh index a5e42a9f0124..f0243d560121 100755 --- a/contrib/examples/git-merge.sh +++ b/contrib/examples/git-merge.sh @@ -4,6 +4,7 @@ # OPTIONS_KEEPDASHDASH= +OPTIONS_STUCKLONG= OPTIONS_SPEC="\ git merge [options] <remote>... git merge [options] <msg> HEAD <remote> diff --git a/contrib/examples/git-repack.sh b/contrib/examples/git-repack.sh index 757933174e4c..fd5ced527da5 100755 --- a/contrib/examples/git-repack.sh +++ b/contrib/examples/git-repack.sh @@ -4,6 +4,7 @@ # OPTIONS_KEEPDASHDASH= +OPTIONS_STUCKLONG= OPTIONS_SPEC="\ git repack [options] -- diff --git a/contrib/git-resurrect.sh b/contrib/git-resurrect.sh index a4ed4c3c62f0..d7e97bbc76c2 100755 --- a/contrib/git-resurrect.sh +++ b/contrib/git-resurrect.sh @@ -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 -- diff --git a/git-am.sh b/git-am.sh index bbea43075be0..a3b6f988229c 100755 --- a/git-am.sh +++ b/git-am.sh @@ -4,6 +4,7 @@ SUBDIRECTORY_OK=Yes OPTIONS_KEEPDASHDASH= +OPTIONS_STUCKLONG= OPTIONS_SPEC="\ git am [options] [(<mbox>|<Maildir>)...] git am [options] (--continue | --skip | --abort) diff --git a/git-instaweb.sh b/git-instaweb.sh index e93a23867543..4aa3eb80fd25 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -5,6 +5,7 @@ PERL='@@PERL@@' OPTIONS_KEEPDASHDASH= +OPTIONS_STUCKLONG= OPTIONS_SPEC="\ git instaweb [options] (--start | --stop | --restart) -- diff --git a/git-quiltimport.sh b/git-quiltimport.sh index 8e17525dd86a..167d79fea809 100755 --- a/git-quiltimport.sh +++ b/git-quiltimport.sh @@ -1,5 +1,6 @@ #!/bin/sh OPTIONS_KEEPDASHDASH= +OPTIONS_STUCKLONG= OPTIONS_SPEC="\ git quiltimport [options] -- diff --git a/git-rebase.sh b/git-rebase.sh index 226752fbff62..6ebef7e8b86e 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -5,6 +5,7 @@ SUBDIRECTORY_OK=Yes OPTIONS_KEEPDASHDASH= +OPTIONS_STUCKLONG= OPTIONS_SPEC="\ git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] [<upstream>] [<branch>] git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] --root [<branch>] diff --git a/git-request-pull.sh b/git-request-pull.sh index fe21d5db631c..cf4f1505a54b 100755 --- a/git-request-pull.sh +++ b/git-request-pull.sh @@ -9,6 +9,7 @@ LONG_USAGE='Summarizes the changes between two commits to the standard output, and includes the given URL in the generated summary.' SUBDIRECTORY_OK='Yes' OPTIONS_KEEPDASHDASH= +OPTIONS_STUCKLONG= OPTIONS_SPEC='git request-pull [options] start url [end] -- p show patch text as well diff --git a/git-sh-setup.sh b/git-sh-setup.sh index ebfe8f7a4d06..e1d66799693d 100644 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -75,6 +75,8 @@ if test -n "$OPTIONS_SPEC"; then parseopt_extra= [ -n "$OPTIONS_KEEPDASHDASH" ] && parseopt_extra="--keep-dashdash" + [ -n "$OPTIONS_STUCKLONG" ] && + parseopt_extra="$parseopt_extra --stuck-long" eval "$( echo "$OPTIONS_SPEC" |
-- 1.8.4.2
[PATCH 3/8] am: parse options in stuck-long mode
There is no functionnal change. The reason for this change is to be able to add a new option taking an optional argument.
Signed-off-by: Nicolas Vigier <boklm@mars-attacks.org> --- git-am.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/git-am.sh b/git-am.sh index a3b6f988229c..020abf6940bd 100755 --- a/git-am.sh +++ b/git-am.sh @@ -4,7 +4,7 @@ SUBDIRECTORY_OK=Yes OPTIONS_KEEPDASHDASH= -OPTIONS_STUCKLONG= +OPTIONS_STUCKLONG=t OPTIONS_SPEC="\ git am [options] [(<mbox>|<Maildir>)...] git am [options] (--continue | --skip | --abort) @@ -414,14 +414,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)
-- 1.8.4.2
[PATCH 4/8] am: add the --gpg-sign option
Signed-off-by: Nicolas Vigier <boklm@mars-attacks.org> --- Documentation/git-am.txt | 6 +++++- git-am.sh | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt index 54d8461d61b2..17924d0f3ff3 100644 --- a/Documentation/git-am.txt +++ b/Documentation/git-am.txt @@ -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) @@ -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:: diff --git a/git-am.sh b/git-am.sh index 020abf6940bd..dccbae2af0de 100755 --- a/git-am.sh +++ b/git-am.sh @@ -38,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 @@ -375,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 @@ -436,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 ;; *) @@ -900,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 ${gpg_sign_opt:+"$gpg_sign_opt"} $tree ${parent:+-p} $parent \ + <"$dotest/final-commit" ) && git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent || stop_here $this
-- 1.8.4.2
[PATCH] am: add the --gpg-sign option
Signed-off-by: Nicolas Vigier <boklm@mars-attacks.org> --- Second version of this patch. In the first version I forgot to save the status of the gpg-sign option so that it is also used with --continue.
Documentation/git-am.txt | 6 +++++- git-am.sh | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt index 54d8461d61b2..17924d0f3ff3 100644 --- a/Documentation/git-am.txt +++ b/Documentation/git-am.txt @@ -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) @@ -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:: diff --git a/git-am.sh b/git-am.sh index 020abf6940bd..dd2f4611f246 100755 --- a/git-am.sh +++ b/git-am.sh @@ -38,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 @@ -375,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 @@ -436,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 ;; *) @@ -564,6 +570,7 @@ Use \"git am --abort\" to remove it.")" echo "$scissors" >"$dotest/scissors" echo "$no_inbody_headers" >"$dotest/no_inbody_headers" echo "$GIT_QUIET" >"$dotest/quiet" + echo "$gpg_sign_opt" >"$dotest/gpg-sign-opt" echo 1 >"$dotest/next" if test -n "$rebasing" then @@ -645,6 +652,7 @@ then else SIGNOFF= fi +gpg_sign_opt=$(cat "$dotest/gpg-sign-opt") last=`cat "$dotest/last"` this=`cat "$dotest/next"` @@ -900,7 +908,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 ${gpg_sign_opt:+"$gpg_sign_opt"} $tree ${parent:+-p} $parent \ + <"$dotest/final-commit" ) && git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent || stop_here $this
-- 1.8.4.2
[PATCH 5/8] rebase: remove useless arguments check
Remove a check on the number of arguments for --onto and -x options. It is not possible for $# to be <= 2 at this point :
- if --onto or -x has an argument, git rev-parse --parseopt will
provide something like this :
set -- --onto 'x' --
when parsing the "--onto" option, $# will be 3 or more if there are
other options.- if --onto or -x doesn't have an argument, git rev-parse --parseopt will exit with an error and display usage information.
Signed-off-by: Nicolas Vigier <boklm@mars-attacks.org> --- git-rebase.sh | 2 -- 1 file changed, 2 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh index 6ebef7e8b86e..6b9279a69028 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -236,12 +236,10 @@ do action=${1##--} ;; --onto) - test 2 -le "$#" || usage onto="$2" shift ;; -x) - test 2 -le "$#" || usage cmd="${cmd}exec $2${LF}" shift ;;
-- 1.8.4.2
[PATCH 6/8] rebase: don't try to match -M option
The -M option does not exist in OPTIONS_SPEC, so there is no use to try to find it.
Signed-off-by: Nicolas Vigier <boklm@mars-attacks.org> --- git-rebase.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/git-rebase.sh b/git-rebase.sh index 6b9279a69028..2f2f8ded5c3f 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -259,7 +259,7 @@ do --no-autosquash) autosquash= ;; - -M|-m) + -m) do_merge=t ;; -X)
-- 1.8.4.2
[PATCH 7/8] rebase: parse options in stuck-long mode
There is no functionnal change. The reason for this change is to be able to add a new option taking an optional argument.
Signed-off-by: Nicolas Vigier <boklm@mars-attacks.org> --- git-rebase.sh | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh index 2f2f8ded5c3f..a6c294b2289b 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -5,7 +5,7 @@ SUBDIRECTORY_OK=Yes OPTIONS_KEEPDASHDASH= -OPTIONS_STUCKLONG= +OPTIONS_STUCKLONG=t OPTIONS_SPEC="\ git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] [<upstream>] [<branch>] git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] --root [<branch>] @@ -235,21 +235,19 @@ do test $total_argc -eq 2 || usage action=${1##--} ;; - --onto) - onto="$2" - shift + --onto=*) + onto="${1#--onto=}" ;; - -x) - cmd="${cmd}exec $2${LF}" - shift + --exec=*) + cmd="${cmd}exec ${1#--exec=}${LF}" ;; - -i) + --interactive) interactive_rebase=explicit ;; - -k) + --keep-empty) keep_empty=yes ;; - -p) + --preserve-merges) preserve_merges=t test -z "$interactive_rebase" && interactive_rebase=implied ;; @@ -259,21 +257,19 @@ do --no-autosquash) autosquash= ;; - -m) + --merge) do_merge=t ;; - -X) - shift - strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$1")" + --strategy-option=*) + strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--${1#--strategy-option=}")" do_merge=t test -z "$strategy" && strategy=recursive ;; - -s) - shift - strategy="$1" + --strategy=*) + strategy="${1#--strategy=}" do_merge=t ;; - -n) + --no-stat) diffstat= ;; --stat) @@ -282,21 +278,20 @@ do --autostash) autostash=true ;; - -v) + --verbose) verbose=t diffstat=t GIT_QUIET= ;; - -q) + --quiet) GIT_QUIET=t git_am_opt="$git_am_opt -q" verbose= diffstat= ;; - --whitespace) - shift - git_am_opt="$git_am_opt --whitespace=$1" - case "$1" in + --whitespace=*) + git_am_opt="$git_am_opt --whitespace=${1#--whitespace=}" + case "${1#--whitespace=}" in fix|strip) force_rebase=t ;; @@ -309,14 +304,13 @@ do git_am_opt="$git_am_opt $1" force_rebase=t ;; - -C) - shift - git_am_opt="$git_am_opt -C$1" + -C*) + git_am_opt="$git_am_opt $1" ;; --root) rebase_root=t ;; - -f|--no-ff) + --force-rebase|--no-ff) force_rebase=t ;; --rerere-autoupdate|--no-rerere-autoupdate)
-- 1.8.4.2
[PATCH 8/8] rebase: add the --gpg-sign option
Signed-off-by: Nicolas Vigier <boklm@mars-attacks.org> --- Documentation/git-rebase.txt | 4 ++++ git-rebase--am.sh | 8 +++++--- git-rebase--interactive.sh | 32 ++++++++++++++++++++------------ git-rebase--merge.sh | 2 +- git-rebase.sh | 11 +++++++++++ 5 files changed, 41 insertions(+), 16 deletions(-)
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index 94e07fdab550..ed25bc3e41d1 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -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. diff --git a/git-rebase--am.sh b/git-rebase--am.sh index 34e3102fcbfa..82ed63dd7874 100644 --- a/git-rebase--am.sh +++ b/git-rebase--am.sh @@ -5,7 +5,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 ;; @@ -25,7 +26,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" @@ -59,7 +60,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" diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 3c6bed9a28f7..8aac6a85b192 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -184,7 +184,7 @@ exit_with_patch () { git rev-parse --verify HEAD > "$amend" warn "You can amend the commit now, with" warn - warn " git commit --amend" + warn " git commit --amend $gpg_sign_opt" warn warn "Once you are satisfied with your changes, run" warn @@ -251,7 +251,8 @@ 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:+"$gpg_sign_opt"} \ + "$strategy_args" $empty_args $ff "$@" } pick_one_preserving_merges () { @@ -362,7 +363,8 @@ pick_one_preserving_merges () { echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list" ;; *) - output eval git cherry-pick "$strategy_args" "$@" || + output eval git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} \ + "$strategy_args" "$@" || die_with_patch $sha1 "Could not pick $sha1" ;; esac @@ -473,7 +475,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 || @@ -500,7 +503,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" @@ -545,19 +548,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" @@ -825,11 +831,11 @@ continue) 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 If they are meant to go into a new commit, run: - git commit + git commit $gpg_sign_opt In both case, once you're done, continue with: @@ -845,10 +851,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 diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh index 16d18176ece5..1e747424c22e 100644 --- a/git-rebase--merge.sh +++ b/git-rebase--merge.sh @@ -25,7 +25,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: " diff --git a/git-rebase.sh b/git-rebase.sh index a6c294b2289b..a2c0ea3cf4ba 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -36,6 +36,7 @@ ignore-date! passed to 'git am' whitespace=! passed to 'git apply' ignore-whitespace! passed to 'git apply' C=! passed to 'git apply' +S,gpg-sign? GPG-sign commits Actions: continue! continue abort! abort and check out the original branch @@ -83,6 +84,7 @@ preserve_merges= autosquash= keep_empty= test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t +gpg_sign_opt= read_basic_state () { test -f "$state_dir/head-name" && @@ -105,6 +107,8 @@ read_basic_state () { strategy_opts="$(cat "$state_dir"/strategy_opts)" test -f "$state_dir"/allow_rerere_autoupdate && allow_rerere_autoupdate="$(cat "$state_dir"/allow_rerere_autoupdate)" + test -f "$state_dir"/gpg_sign_opt && + gpg_sign_opt="$(cat "$state_dir"/gpg_sign_opt)" } write_basic_state () { @@ -118,6 +122,7 @@ write_basic_state () { "$state_dir"/strategy_opts test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \ "$state_dir"/allow_rerere_autoupdate + test -n "$gpg_sign_opt" && echo "$gpg_sign_opt" > "$state_dir"/gpg_sign_opt } output () { @@ -316,6 +321,12 @@ do --rerere-autoupdate|--no-rerere-autoupdate) allow_rerere_autoupdate="$1" ;; + --gpg-sign) + gpg_sign_opt=-S + ;; + --gpg-sign=*) + gpg_sign_opt="-S${1#--gpg-sign=}" + ;; --) shift break
-- 1.8.4.2
Re: Adding --gpg-sign to cherry-pick, revert, am, rebase
On Sun, Nov 03, 2013 at 04:54:16PM +0100, Nicolas Vigier wrote:
> Hello, > > Here is a series of patches to add the --gpg-sign option to be able to > gpg sign commits, to the cherry-pick, revert, am and rebase commands.
Whatever happened to this series? It looks like it never made it into next, master, or pu, and Junio's immediately-following "What's cooking" email didn't mention it.
I'm really very interested in seeing it merged, so if there's something I can do to help it along, please let me know.
-- brian m. carlson / brian with sandals: Houston, Texas, US +1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187