File tree 1 file changed +22
-2
lines changed
1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 15
15
Union ,
16
16
)
17
17
18
- from funcy import cached_property
18
+ from funcy import cached_property , first
19
19
20
20
from scmrepo .exceptions import (
21
21
CloneError ,
32
32
33
33
34
34
if TYPE_CHECKING :
35
+ from pygit2 import Signature
36
+
35
37
from scmrepo .progress import GitProgressEvent
36
38
37
39
@@ -123,14 +125,32 @@ def _resolve_refish(self, refish: str):
123
125
return commit , ref
124
126
125
127
@property
126
- def default_signature (self ):
128
+ def default_signature (self ) -> "Signature" :
127
129
try :
128
130
return self .repo .default_signature
129
131
except KeyError as exc :
132
+ signature = self ._get_codespaces_signature ()
133
+ if signature is not None :
134
+ return signature
130
135
raise SCMError (
131
136
"Git username and email must be configured"
132
137
) from exc
133
138
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
+
134
154
@staticmethod
135
155
def _get_checkout_strategy (strategy : Optional [int ] = None ):
136
156
from pygit2 import (
You can’t perform that action at this time.
0 commit comments