From: Patrik Weiskircher Date: Wed, 28 May 2025 13:01:15 GMT Subject: [PATCH 1/2] contrib/subtree: Add -S/--gpg-sign option Message-ID: <20250528130116.21534-2-patrik@pspdfkit.com> In-Reply-To: <20250528130116.21534-1-patrik@pspdfkit.com> If set, forwards the options to commit-tree and merge. Signed-off-by: Patrik Weiskircher --- 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' [] -P add -'git subtree' [] -P add -'git subtree' [] -P merge [] -'git subtree' [] -P split [] +'git subtree' [] -P [-S[]] add +'git subtree' [] -P [-S[]] add +'git subtree' [] -P [-S[]] merge [] +'git subtree' [] -P [-S[]] split [] [verse] -'git subtree' [] -P pull -'git subtree' [] -P push +'git subtree' [] -P [-S[]] pull +'git subtree' [] -P [-S[]] push DESCRIPTION ----------- @@ -149,6 +149,14 @@ OPTIONS FOR ALL COMMANDS want to manipulate. This option is mandatory for all commands. +-S[]:: +--gpg-sign[=]:: +--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= -git subtree add --prefix= -git subtree merge --prefix= -git subtree split --prefix= [] -git subtree pull --prefix= -git subtree push --prefix= +git subtree add --prefix= [-S[]] +git subtree add --prefix= [-S[]] +git subtree merge --prefix= [-S[]] +git subtree split --prefix= [-S[]] [] +git subtree pull --prefix= [-S[]] +git subtree push --prefix= [-S[]] -- 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