File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 1515 Union ,
1616)
1717
18- from funcy import cached_property
18+ from funcy import cached_property , first
1919
2020from scmrepo .exceptions import (
2121 CloneError ,
3232
3333
3434if TYPE_CHECKING :
35+ from pygit2 import Signature
36+
3537 from scmrepo .progress import GitProgressEvent
3638
3739
@@ -123,14 +125,32 @@ def _resolve_refish(self, refish: str):
123125 return commit , ref
124126
125127 @property
126- def default_signature (self ):
128+ def default_signature (self ) -> "Signature" :
127129 try :
128130 return self .repo .default_signature
129131 except KeyError as exc :
132+ signature = self ._get_codespaces_signature ()
133+ if signature is not None :
134+ return signature
130135 raise SCMError (
131136 "Git username and email must be configured"
132137 ) from exc
133138
139+ def _get_codespaces_signature (self ) -> Optional ["Signature" ]:
140+ from pygit2 import Config , Signature
141+
142+ if "CODESPACES" not in os .environ :
143+ return None
144+ try :
145+ config = Config ("/usr/local/etc/gitconfig" )
146+ name = first (config .get_multivar ("user.name" ))
147+ email = first (config .get_multivar ("user.email" ))
148+ if name and email :
149+ return Signature (name , email )
150+ except Exception : # pylint: disable=broad-except
151+ pass
152+ return None
153+
134154 @staticmethod
135155 def _get_checkout_strategy (strategy : Optional [int ] = None ):
136156 from pygit2 import (
You can’t perform that action at this time.
0 commit comments