honor signed commits in ghstack

Summary: Pass `-S` with the keyid when `ghstack` calls `git commit-tree`, if appropriate.

Reviewed By: quark-zju

Differential Revision: D41791483

fbshipit-source-id: 7384d5dfc2775e5268b6c3a221bc64a54ac32804
This commit is contained in:
Michael Bolin 2022-12-12 14:26:34 -08:00 committed by Facebook GitHub Bot
parent f6bef0c4c6
commit 0bbd19f6d9
3 changed files with 8 additions and 6 deletions

View File

@ -262,6 +262,7 @@ query UsernameQuery {
user_name, user_email = gituser.get_identity_or_raise(ui)
sh = ghstack.sapling_shell.SaplingShell(
conf=conf,
ui=ui,
git_dir=git_dir,
user_name=user_name,
user_email=user_email,

View File

@ -3,6 +3,7 @@ import logging
import os
from typing import Any, Dict, Optional, List
from edenscm import gpg
import ghstack
import ghstack.config
from ghstack.ghs_types import GitCommitHash
@ -14,6 +15,7 @@ class SaplingShell(ghstack.shell.Shell):
def __init__(self,
*,
conf: ghstack.config.Config,
ui = None, # Sapling ui object.
git_dir: str,
user_name: str,
user_email: str,
@ -32,6 +34,7 @@ class SaplingShell(ghstack.shell.Shell):
"""
super().__init__(quiet=quiet, cwd=cwd, testing=testing)
self.conf = conf
self.ui = ui
self.git_dir = git_dir
self.user_name = user_name
self.user_email = user_email
@ -132,7 +135,9 @@ class SaplingShell(ghstack.shell.Shell):
"""Run `git commit-tree`, adding GPG flags, if appropriate.
"""
config_flags = ['-c', f'user.name={self.user_name}', '-c', f'user.email={self.user_email}']
full_args = config_flags + ["commit-tree"] + list(args)
keyid = gpg.get_gpg_keyid(self.ui)
gpg_args = [f'-S{keyid}'] if keyid else []
full_args = config_flags + ["commit-tree"] + gpg_args + list(args)
stdout = self.git(*full_args, **kwargs)
if isinstance(stdout, str):
return GitCommitHash(stdout)

View File

@ -287,14 +287,10 @@ class Shell(object):
) -> GitCommitHash:
"""Run `git commit-tree`, adding GPG flags, if appropriate.
"""
gpg_args = self.get_gpg_args()
gpg_args = gpg_args_if_necessary(self)
full_args = ["commit-tree"] + gpg_args + list(args)
return GitCommitHash(self.git(*full_args, **kwargs))
def get_gpg_args(self) -> List[str]:
"""args to include with `git commit` or `git commit-tree` for GPG signing"""
return gpg_args_if_necessary(self)
@overload # noqa: F811
def hg(self, *args: str) -> str:
...