11import  os 
22import  re 
33import  tempfile 
4+ from  pathlib  import  Path 
45
56import  pytest 
67
78from  commitizen  import  cmd , defaults 
89from  commitizen .config  import  BaseConfig 
910
11+ SIGNER  =  "GitHub Action" 
12+ SIGNER_MAIL  =  "action@github.com" 
13+ 
14+ 
15+ @pytest .fixture (autouse = True ) 
16+ def  git_sandbox (monkeypatch : pytest .MonkeyPatch , tmp_path : Path ):
17+     """Ensure git commands are executed without the current user settings""" 
18+     monkeypatch .setenv ("GIT_CONFIG_GLOBAL" , str (tmp_path  /  "gitconfig" ))
19+     cmd .run (f"git config --global user.name { SIGNER }  " )
20+     cmd .run (f"git config --global user.email { SIGNER_MAIL }  " )
21+ 
1022
1123@pytest .fixture (scope = "function" ) 
1224def  tmp_git_project (tmpdir ):
@@ -36,9 +48,6 @@ def _get_gpg_keyid(signer_mail):
3648
3749@pytest .fixture (scope = "function" ) 
3850def  tmp_commitizen_project_with_gpg (tmp_commitizen_project ):
39-     signer  =  "GitHub Action" 
40-     signer_mail  =  "action@github.com" 
41- 
4251    # create a temporary GPGHOME to store a temporary keyring. 
4352    # Home path must be less than 104 characters 
4453    gpg_home  =  tempfile .TemporaryDirectory (suffix = "_cz" )
@@ -47,17 +56,15 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project):
4756
4857    # create a key (a keyring will be generated within GPUPGHOME) 
4958    c  =  cmd .run (
50-         f"gpg --batch --yes --debug-quick-random --passphrase '' --quick-gen-key '{ signer }   { signer_mail }  '" 
59+         f"gpg --batch --yes --debug-quick-random --passphrase '' --quick-gen-key '{ SIGNER }   { SIGNER_MAIL }  '" 
5160    )
5261    if  c .return_code  !=  0 :
5362        raise  Exception (f"gpg keygen failed with err: '{ c .err }  '" )
54-     key_id  =  _get_gpg_keyid (signer_mail )
63+     key_id  =  _get_gpg_keyid (SIGNER_MAIL )
5564    assert  key_id 
5665
57-     # configure git 
66+     # configure git to use gpg signing  
5867    cmd .run ("git config commit.gpgsign true" )
59-     cmd .run (f"git config user.name { signer }  " )
60-     cmd .run (f"git config user.email { signer_mail }  " )
6168    cmd .run (f"git config user.signingkey { key_id }  " )
6269
6370    yield  tmp_commitizen_project 
0 commit comments