From: Patrik Weiskircher <patrik@pspdfkit.com>
To: git@vger.kernel.org
Cc: apenwarr@gmail.com, Patrik Weiskircher <patrik@pspdfkit.com>
Subject: [PATCH 1/2] contrib/subtree: Add -S/--gpg-sign option
Date: Wed, 28 May 2025 09:01:15 -0400 [thread overview]
Message-ID: <20250528130116.21534-2-patrik@pspdfkit.com> (raw)
In-Reply-To: <20250528130116.21534-1-patrik@pspdfkit.com>
If set, forwards the options to commit-tree and merge.
Signed-off-by: Patrik Weiskircher <patrik@pspdfkit.com>
---
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
next prev parent reply other threads:[~2025-05-28 13:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-28 13:01 [PATCH 0/2] contrib/subtree: Add -S/--gpg-sign option Patrik Weiskircher
2025-05-28 13:01 ` Patrik Weiskircher [this message]
2025-05-29 23:45 ` [PATCH 1/2] " Junio C Hamano
2025-05-28 13:01 ` [PATCH 2/2] contrib/subtree: Add tests for -S/--gpg-sign Patrik Weiskircher
2025-05-29 23:15 ` [PATCH 0/2] contrib/subtree: Add -S/--gpg-sign option Junio C Hamano
2025-05-30 14:33 ` Patrik Weiskircher
2025-05-30 20:55 ` Junio C Hamano
2025-06-02 13:12 ` Patrik Weiskircher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250528130116.21534-2-patrik@pspdfkit.com \
--to=patrik@pspdfkit.com \
--cc=apenwarr@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).