Skip to content

contrib/subtree: Add -S/-gpg-sign #1928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pweiskircher
Copy link

@pweiskircher pweiskircher commented Jun 2, 2025

This patch adds support for the -S/--gpg-sign option to the git subtree command.

Currently, git subtree creates squash and merge commits without applying GPG signatures, even when commit signing is configured via commit.gpgSign. This causes issues in repositories that require signed commits for policy reasons.

The implementation ensures that -S/--gpg-sign behaves consistently with other Git commands, passing the flag through to git commit-tree and git merge where appropriate.

This change improves compatibility with workflows and repositories that enforce signed commits.

Changes have been made to this patch according to a discussion with Junio C Hamano [email protected] on my previous patch attempt.

Changes since v1:

  • Adjusted commit message to not mention the not implemented flag yet.

CC: [email protected], Junio C Hamano [email protected]
cc: "D. Ben Knoble" [email protected]
cc: Patrik Weiskircher [email protected]
cc: "Kristoffer Haugsbakk" [email protected]

@pweiskircher pweiskircher changed the title Use --stuck-long when parsing arguments contrib/subtree: Add -S/-gpg-sign Jun 2, 2025
Copy link

gitgitgadget bot commented Jun 2, 2025

Welcome to GitGitGadget

Hi @pweiskircher, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests.

Please make sure that either:

  • Your Pull Request has a good description, if it consists of multiple commits, as it will be used as cover letter.
  • Your Pull Request description is empty, if it consists of a single commit, as the commit message should be descriptive enough by itself.

You can CC potential reviewers by adding a footer to the PR description with the following syntax:

CC: Revi Ewer <[email protected]>, Ill Takalook <[email protected]>

NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description,
because it will result in a malformed CC list on the mailing list. See
example.

Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:

  • the lines should not exceed 76 columns,
  • the first line should be like a header and typically start with a prefix like "tests:" or "revisions:" to state which subsystem the change is about, and
  • the commit messages' body should be describing the "why?" of the change.
  • Finally, the commit messages should end in a Signed-off-by: line matching the commits' author.

It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code.

Contributing the patches

Before you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form /allow. A good way to find other contributors is to locate recent pull requests where someone has been /allowed:

Both the person who commented /allow and the PR author are able to /allow you.

An alternative is the channel #git-devel on the Libera Chat IRC network:

<newcontributor> I've just created my first PR, could someone please /allow me? https://github.com/gitgitgadget/git/pull/12345
<veteran> newcontributor: it is done
<newcontributor> thanks!

Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment /submit.

If you want to see what email(s) would be sent for a /submit request, add a PR comment /preview to have the email(s) sent to you. You must have a public GitHub email address for this. Note that any reviewers CC'd via the list in the PR description will not actually be sent emails.

After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail).

If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the (raw) link), then import it into your mail program. If you use GMail, you can do this via:

curl -g --user "<EMailAddress>:<Password>" \
    --url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt

To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):

Changes since v1:
- Fixed a typo in the commit message (found by ...)
- Added a code comment to ... as suggested by ...
...

To send a new iteration, just add another PR comment with the contents: /submit.

Need help?

New contributors who want advice are encouraged to join [email protected], where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join.

You may also be able to find help in real time in the developer IRC channel, #git-devel on Libera Chat. Remember that IRC does not support offline messaging, so if you send someone a private message and log out, they cannot respond to you. The scrollback of #git-devel is archived, though.

@gitgitgadget gitgitgadget bot added the new user label Jun 2, 2025
Copy link

gitgitgadget bot commented Jun 2, 2025

There are issues in commit 1f46176:
Use --stuck-long when parsing arguments
Commit not signed off

Copy link

gitgitgadget bot commented Jun 2, 2025

There are issues in commit c8f4a6d:
contrib/subtree: Add -S/--gpg-sign
Prefixed commit message must be in lower case
Commit not signed off

@pweiskircher pweiskircher force-pushed the subtree-sign-the-second branch from c8f4a6d to c12243d Compare June 2, 2025 13:48
Copy link

gitgitgadget bot commented Jun 2, 2025

There are issues in commit c12243d:
contrib/subtree: Add -S/--gpg-sign
Prefixed commit message must be in lower case

@pweiskircher pweiskircher force-pushed the subtree-sign-the-second branch from c12243d to 118ab05 Compare June 2, 2025 13:57
Copy link

gitgitgadget bot commented Jun 2, 2025

There are issues in commit 118ab05:
contrib/subtree: Add -S/--gpg-sign
Prefixed commit message must be in lower case

@pweiskircher pweiskircher force-pushed the subtree-sign-the-second branch from 118ab05 to cd05da4 Compare June 2, 2025 14:02
Copy link

gitgitgadget bot commented Jun 2, 2025

There are issues in commit cd05da4:
contrib/subtree: Add -S/--gpg-sign
Prefixed commit message must be in lower case

@pweiskircher pweiskircher force-pushed the subtree-sign-the-second branch from cd05da4 to 45ae2c3 Compare June 2, 2025 14:07
@pweiskircher
Copy link
Author

@derrickstolee @dscho Hi! I've seen you give out some /allow privileges. May I?

@dscho
Copy link
Member

dscho commented Jun 2, 2025

/allow

Copy link

gitgitgadget bot commented Jun 2, 2025

User pweiskircher is now allowed to use GitGitGadget.

WARNING: pweiskircher has no public email address set on GitHub; GitGitGadget needs an email address to Cc: you on your contribution, so that you receive any feedback on the Git mailing list. Go to https://github.com/settings/profile to make your preferred email public to let GitGitGadget know which email address to use.

@pweiskircher
Copy link
Author

/preview

Copy link

gitgitgadget bot commented Jun 2, 2025

Preview email sent as [email protected]

@pweiskircher
Copy link
Author

/submit

Copy link

gitgitgadget bot commented Jun 2, 2025

Submitted as [email protected]

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-1928/pweiskircher/subtree-sign-the-second-v1

To fetch this version to local tag pr-1928/pweiskircher/subtree-sign-the-second-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-1928/pweiskircher/subtree-sign-the-second-v1

Copy link

gitgitgadget bot commented Jun 2, 2025

This patch series was integrated into seen via git@5e13850.

@gitgitgadget gitgitgadget bot added the seen label Jun 2, 2025
Copy link

gitgitgadget bot commented Jun 3, 2025

This branch is now known as pw/subtree-gpg-sign.

Copy link

gitgitgadget bot commented Jun 3, 2025

This patch series was integrated into seen via git@74f707e.

@@ -115,7 +115,7 @@ main () {
then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, "D. Ben Knoble" wrote (reply to this):

On Mon, Jun 2, 2025 at 12:41 PM Patrik Weiskircher via GitGitGadget
<[email protected]> wrote:
>
> From: Patrik Weiskircher <[email protected]>
>
> -S/--gpg-sign requires an optional parameter. Optional parameter
> handling only works unambiguous with git rev-parse --parseopt when using
> the --stuck-long option.

Here we mention "-S", but that flag isn't implemented yet, right?

Perhaps something like:

    Optional parameter handling only works unambiguous with git rev-parse
    --parseopt when using the --stuck-long option. To prepare for future commits
    which add flags with optional parameters, parse with --stuck-long.

>
> Signed-off-by: Patrik Weiskircher <[email protected]>
> ---
>  contrib/subtree/git-subtree.sh | 34 +++++++++++++---------------------
>  1 file changed, 13 insertions(+), 21 deletions(-)
>
> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
> index 15ae86db1b27..60b2431b8bba 100755
> --- a/contrib/subtree/git-subtree.sh
> +++ b/contrib/subtree/git-subtree.sh
> @@ -115,7 +115,7 @@ main () {
>         then
>                 set -- -h
>         fi
> -       set_args="$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
> +       set_args="$(echo "$OPTS_SPEC" | git rev-parse --parseopt --stuck-long -- "$@" || echo exit $?)"
>         eval "$set_args"
>         . git-sh-setup
>         require_work_tree
> @@ -131,9 +131,6 @@ main () {
>                 opt="$1"
>                 shift
>                 case "$opt" in
> -                       --annotate|-b|-P|-m|--onto)
> -                               shift
> -                               ;;
>                         --rejoin)
>                                 arg_split_rejoin=1
>                                 ;;
> @@ -177,42 +174,37 @@ main () {
>                 shift
>
>                 case "$opt" in
> -               -q)
> +               --quiet)
>                         arg_quiet=1
>                         ;;
> -               -d)
> +               --debug)
>                         arg_debug=1
>                         ;;
> -               --annotate)
> +               --annotate=*)
>                         test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
> -                       arg_split_annotate="$1"
> -                       shift
> +                       arg_split_annotate="${opt#*=}"
>                         ;;
>                 --no-annotate)
>                         test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
>                         arg_split_annotate=
>                         ;;
> -               -b)
> +               --branch=*)
>                         test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
> -                       arg_split_branch="$1"
> -                       shift
> +                       arg_split_branch="${opt#*=}"
>                         ;;
> -               -P)
> -                       arg_prefix="${1%/}"
> -                       shift
> +               --prefix=*)
> +                       arg_prefix="${opt#*=}"
>                         ;;
> -               -m)
> +               --message=*)
>                         test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command"
> -                       arg_addmerge_message="$1"
> -                       shift
> +                       arg_addmerge_message="${opt#*=}"
>                         ;;
>                 --no-prefix)
>                         arg_prefix=
>                         ;;
> -               --onto)
> +               --onto=*)
>                         test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
> -                       arg_split_onto="$1"
> -                       shift
> +                       arg_split_onto="${opt#*=}"
>                         ;;
>                 --no-onto)
>                         test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
> --
> gitgitgadget
>
>


-- 
D. Ben Knoble

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Patrik Weiskircher wrote (reply to this):

On Tue, Jun 3, 2025 at 4:42 PM D. Ben Knoble <[email protected]> wrote:
>
> On Mon, Jun 2, 2025 at 12:41 PM Patrik Weiskircher via GitGitGadget
> <[email protected]> wrote:
> >
> > From: Patrik Weiskircher <[email protected]>
> >
> > -S/--gpg-sign requires an optional parameter. Optional parameter
> > handling only works unambiguous with git rev-parse --parseopt when using
> > the --stuck-long option.
>
> Here we mention "-S", but that flag isn't implemented yet, right?
>
> Perhaps something like:
>
>     Optional parameter handling only works unambiguous with git rev-parse
>     --parseopt when using the --stuck-long option. To prepare for future commits
>     which add flags with optional parameters, parse with --stuck-long.
>

Makes sense! Changing that. What is a good policy to resubmit
something? Should I wait longer? Sorry, very new here!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, "Kristoffer Haugsbakk" wrote (reply to this):

On Wed, Jun 4, 2025, at 15:56, Patrik Weiskircher wrote:
>>
>> Here we mention "-S", but that flag isn't implemented yet, right?
>>
>> Perhaps something like:
>>
>>     Optional parameter handling only works unambiguous with git rev-parse
>>     --parseopt when using the --stuck-long option. To prepare for future commits
>>     which add flags with optional parameters, parse with --stuck-long.
>>
>
> Makes sense! Changing that. What is a good policy to resubmit
> something? Should I wait longer? Sorry, very new here!

• Force-push your branch to gitgitgadget
• Edit the PR description with something like “Changes since v1:” to
  summarize the changes
• (`/preview` comment)
• To send the next version: `/submit` comment again

I think that’s it. :)

I don’t think there’s a need to wait if you don’t want to.

-- 
Kristoffer Haugsbakk

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Junio C Hamano wrote (reply to this):

"Kristoffer Haugsbakk" <[email protected]> writes:

> On Wed, Jun 4, 2025, at 15:56, Patrik Weiskircher wrote:
>>>
>>> Here we mention "-S", but that flag isn't implemented yet, right?
>>>
>>> Perhaps something like:
>>>
>>>     Optional parameter handling only works unambiguous with git rev-parse
>>>     --parseopt when using the --stuck-long option. To prepare for future commits
>>>     which add flags with optional parameters, parse with --stuck-long.
>>>
>>
>> Makes sense! Changing that. What is a good policy to resubmit
>> something? Should I wait longer? Sorry, very new here!
>
> • Force-push your branch to gitgitgadget
> • Edit the PR description with something like “Changes since v1:” to
>   summarize the changes
> • (`/preview` comment)
> • To send the next version: `/submit` comment again
>
> I think that’s it. :)
>
> I don’t think there’s a need to wait if you don’t want to.

It would be nice for potential reviewers to give at least 24 hours
to ensure people anywhere on the globe have a chance to comment, and
a chance for you to respond to them, before sending your next
iteration.

Also, for future reference, when responding to a review comment that
causes you to drastically change the course of the series, you can
respond whenever you want to, but it is nice to other potential
reviewers to give at least 24 hours to voice their opinions, before
sending an updated series based on that comment, since suggested
changes in such a comment may be controversial and after seeing you
spend some time already to adjust to it, others may feel discouraged
to make you redo your series again even whey they think the
suggested changes are not taking us in the right direction.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Patrik Weiskircher wrote (reply to this):

On Wed, Jun 4, 2025 at 11:41 AM Junio C Hamano <[email protected]> wrote:
>
> "Kristoffer Haugsbakk" <[email protected]> writes:
>
> > On Wed, Jun 4, 2025, at 15:56, Patrik Weiskircher wrote:
> >>>
> >>> Here we mention "-S", but that flag isn't implemented yet, right?
> >>>
> >>> Perhaps something like:
> >>>
> >>>     Optional parameter handling only works unambiguous with git rev-parse
> >>>     --parseopt when using the --stuck-long option. To prepare for future commits
> >>>     which add flags with optional parameters, parse with --stuck-long.
> >>>
> >>
> >> Makes sense! Changing that. What is a good policy to resubmit
> >> something? Should I wait longer? Sorry, very new here!
> >
> > • Force-push your branch to gitgitgadget
> > • Edit the PR description with something like “Changes since v1:” to
> >   summarize the changes
> > • (`/preview` comment)
> > • To send the next version: `/submit` comment again
> >
> > I think that’s it. :)
> >
> > I don’t think there’s a need to wait if you don’t want to.
>
> It would be nice for potential reviewers to give at least 24 hours
> to ensure people anywhere on the globe have a chance to comment, and
> a chance for you to respond to them, before sending your next
> iteration.
>
> Also, for future reference, when responding to a review comment that
> causes you to drastically change the course of the series, you can
> respond whenever you want to, but it is nice to other potential
> reviewers to give at least 24 hours to voice their opinions, before
> sending an updated series based on that comment, since suggested
> changes in such a comment may be controversial and after seeing you
> spend some time already to adjust to it, others may feel discouraged
> to make you redo your series again even whey they think the
> suggested changes are not taking us in the right direction.

Makes sense! I'll keep that in mind for the future!

Copy link

gitgitgadget bot commented Jun 3, 2025

User "D. Ben Knoble" <[email protected]> has been added to the cc: list.

Optional parameter handling only works unambiguous with git rev-parse
--parseopt when using the --stuck-long option. To prepare for future commits
which add flags with optional parameters, parse with --stuck-long.

Signed-off-by: Patrik Weiskircher <[email protected]>
Allows optionally signing the commits that git subtree creates. This can
be necessary when working in a repository that requires gpg signed
commits.

Signed-off-by: Patrik Weiskircher <[email protected]>
@pweiskircher pweiskircher force-pushed the subtree-sign-the-second branch from 45ae2c3 to af5b4a6 Compare June 4, 2025 13:55
Copy link

gitgitgadget bot commented Jun 4, 2025

User Patrik Weiskircher <[email protected]> has been added to the cc: list.

Copy link

gitgitgadget bot commented Jun 4, 2025

User "Kristoffer Haugsbakk" <[email protected]> has been added to the cc: list.

@pweiskircher
Copy link
Author

/preview

Copy link

gitgitgadget bot commented Jun 4, 2025

Preview email sent as [email protected]

@pweiskircher
Copy link
Author

/submit

Copy link

gitgitgadget bot commented Jun 4, 2025

Submitted as [email protected]

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-1928/pweiskircher/subtree-sign-the-second-v2

To fetch this version to local tag pr-1928/pweiskircher/subtree-sign-the-second-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-1928/pweiskircher/subtree-sign-the-second-v2

Copy link

gitgitgadget bot commented Jun 4, 2025

On the Git mailing list, Junio C Hamano wrote (reply to this):

"Patrik Weiskircher via GitGitGadget" <[email protected]>
writes:

> Changes since v1:
>
>  * Adjusted commit message to not mention the not implemented flag yet.
>
> Patrik Weiskircher (2):
>   contrib/subtree: parse using --stuck-long
>   contrib/subtree: add -S/--gpg-sign
>
>  contrib/subtree/git-subtree.adoc   |  19 +++--
>  contrib/subtree/git-subtree.sh     |  66 ++++++++---------
>  contrib/subtree/t/t7900-subtree.sh | 113 +++++++++++++++++++++++++++++
>  3 files changed, 158 insertions(+), 40 deletions(-)

Still looking good.  Will queue.  Thanks.

Copy link

gitgitgadget bot commented Jun 4, 2025

This patch series was integrated into seen via git@8ab4c07.

Copy link

gitgitgadget bot commented Jun 5, 2025

This patch series was integrated into seen via git@d9eb3e4.

Copy link

gitgitgadget bot commented Jun 5, 2025

This patch series was integrated into next via git@5366ac6.

@gitgitgadget gitgitgadget bot added the next label Jun 5, 2025
Copy link

gitgitgadget bot commented Jun 5, 2025

There was a status update in the "New Topics" section about the branch pw/subtree-gpg-sign on the Git mailing list:

"git subtree" (in contrib/) learns to grok GPG signing its commits.

Will cook in 'next'.
source: <[email protected]>

Copy link

gitgitgadget bot commented Jun 6, 2025

This patch series was integrated into seen via git@312de21.

Copy link

gitgitgadget bot commented Jun 7, 2025

This patch series was integrated into seen via git@2f4dc6a.

Copy link

gitgitgadget bot commented Jun 7, 2025

There was a status update in the "Cooking" section about the branch pw/subtree-gpg-sign on the Git mailing list:

"git subtree" (in contrib/) learns to grok GPG signing its commits.

Will cook in 'next'.
source: <[email protected]>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants