If set, forwards the options to commit-tree and merge. Signed-off-by: Patrik Weiskircher <patrik@xxxxxxxxxxxx> --- contrib/subtree/git-subtree.adoc | 20 +++++++++---- contrib/subtree/git-subtree.sh | 50 +++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 19 deletions(-) diff --git a/contrib/subtree/git-subtree.adoc b/contrib/subtree/git-subtree.adoc index 004abf415b..f550be1a86 100644 --- a/contrib/subtree/git-subtree.adoc +++ b/contrib/subtree/git-subtree.adoc @@ -9,14 +9,14 @@ git-subtree - Merge subtrees together and split repository into subtrees SYNOPSIS -------- [verse] -'git subtree' [<options>] -P <prefix> add <local-commit> -'git subtree' [<options>] -P <prefix> add <repository> <remote-ref> -'git subtree' [<options>] -P <prefix> merge <local-commit> [<repository>] -'git subtree' [<options>] -P <prefix> split [<local-commit>] +'git subtree' [<options>] -P <prefix> [-S[<keyid>]] add <local-commit> +'git subtree' [<options>] -P <prefix> [-S[<keyid>]] add <repository> <remote-ref> +'git subtree' [<options>] -P <prefix> [-S[<keyid>]] merge <local-commit> [<repository>] +'git subtree' [<options>] -P <prefix> [-S[<keyid>]] split [<local-commit>] [verse] -'git subtree' [<options>] -P <prefix> pull <repository> <remote-ref> -'git subtree' [<options>] -P <prefix> push <repository> <refspec> +'git subtree' [<options>] -P <prefix> [-S[<keyid>]] pull <repository> <remote-ref> +'git subtree' [<options>] -P <prefix> [-S[<keyid>]] push <repository> <refspec> DESCRIPTION ----------- @@ -149,6 +149,14 @@ OPTIONS FOR ALL COMMANDS want to manipulate. This option is mandatory for all commands. +-S[<keyid>]:: +--gpg-sign[=<keyid>]:: +--no-gpg-sign:: + GPG-sign commits. The `keyid` argument is optional and + defaults to the committer identity; if specified, it must be + stuck to the option without a space. `--no-gpg-sign` is useful to + countermand a `--gpg-sign` option given earlier on the command line. + OPTIONS FOR 'add' AND 'merge' (ALSO: 'pull', 'split --rejoin', AND 'push --rejoin') ----------------------------------------------------------------------------------- These options for 'add' and 'merge' may also be given to 'pull' (which diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 15ae86db1b..b98a708c10 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -26,12 +26,12 @@ then fi OPTS_SPEC="\ -git subtree add --prefix=<prefix> <commit> -git subtree add --prefix=<prefix> <repository> <ref> -git subtree merge --prefix=<prefix> <commit> -git subtree split --prefix=<prefix> [<commit>] -git subtree pull --prefix=<prefix> <repository> <ref> -git subtree push --prefix=<prefix> <repository> <refspec> +git subtree add --prefix=<prefix> [-S[<keyid>]] <commit> +git subtree add --prefix=<prefix> [-S[<keyid>]] <repository> <ref> +git subtree merge --prefix=<prefix> [-S[<keyid>]] <commit> +git subtree split --prefix=<prefix> [-S[<keyid>]] [<commit>] +git subtree pull --prefix=<prefix> [-S[<keyid>]] <repository> <ref> +git subtree push --prefix=<prefix> [-S[<keyid>]] <repository> <refspec> -- h,help! show the help q,quiet! quiet @@ -46,6 +46,7 @@ rejoin merge the new branch back into HEAD options for 'add' and 'merge' (also: 'pull', 'split --rejoin', and 'push --rejoin') squash merge subtree changes as a single commit m,message!= use the given message as the commit message for the merge commit +S,gpg-sign?key-id GPG-sign commits. The keyid argument is optional and defaults to the committer identity; if specified, it must be stuck to the option without a space. " indent=0 @@ -102,6 +103,20 @@ assert () { fi } +# Usage: gpg_sign_opt +# Returns the GPG signing option for git commit-tree +gpg_sign_opt () { + if test "${arg_gpg_sign+set}" = "set" + then + if test -n "$arg_gpg_sign" + then + printf " -S%s" "$arg_gpg_sign" + else + printf " -S" + fi + fi +} + # Usage: die_incompatible_opt OPTION COMMAND die_incompatible_opt () { assert test "$#" = 2 @@ -240,6 +255,15 @@ main () { test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command" arg_addmerge_squash= ;; + -S) + if test $# -gt 0 && test "${1#-}" = "$1" + then + arg_gpg_sign="$1" + shift + else + arg_gpg_sign="" + fi + ;; --) break ;; @@ -537,7 +561,7 @@ copy_commit () { printf "%s" "$arg_split_annotate" cat ) | - git commit-tree "$2" $3 # reads the rest of stdin + git commit-tree "$2" $(gpg_sign_opt) $3 # reads the rest of stdin ) || die "fatal: can't copy commit $1" } @@ -683,10 +707,10 @@ new_squash_commit () { if test -n "$old" then squash_msg "$dir" "$oldsub" "$newsub" | - git commit-tree "$tree" -p "$old" || exit $? + git commit-tree "$tree" $(gpg_sign_opt) -p "$old" || exit $? else squash_msg "$dir" "" "$newsub" | - git commit-tree "$tree" || exit $? + git commit-tree "$tree" $(gpg_sign_opt) || exit $? fi } @@ -925,11 +949,11 @@ cmd_add_commit () { then rev=$(new_squash_commit "" "" "$rev") || exit $? commit=$(add_squashed_msg "$rev" "$dir" | - git commit-tree "$tree" $headp -p "$rev") || exit $? + git commit-tree "$tree" $(gpg_sign_opt) $headp -p "$rev") || exit $? else revp=$(peel_committish "$rev") || exit $? commit=$(add_msg "$dir" $headrev "$rev" | - git commit-tree "$tree" $headp -p "$revp") || exit $? + git commit-tree "$tree" $(gpg_sign_opt) $headp -p "$revp") || exit $? fi git reset "$commit" || exit $? @@ -1080,9 +1104,9 @@ cmd_merge () { if test -n "$arg_addmerge_message" then git merge --no-ff -Xsubtree="$arg_prefix" \ - --message="$arg_addmerge_message" "$rev" + --message="$arg_addmerge_message" $(gpg_sign_opt) "$rev" else - git merge --no-ff -Xsubtree="$arg_prefix" $rev + git merge --no-ff -Xsubtree="$arg_prefix" $(gpg_sign_opt) "$rev" fi } -- 2.49.0