Skip to content

Commit 8b40388

Browse files
committed
dulwich: workaround for codespaces system config
1 parent 74b3a98 commit 8b40388

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/scmrepo/git/backend/dulwich/__init__.py

+27-3
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,36 @@ def commit(self, msg: str, no_verify: bool = False):
291291
try:
292292
commit(self.root_dir, message=msg, no_verify=no_verify)
293293
except InvalidUserIdentity as exc:
294-
raise SCMError(
295-
"Git username and email must be configured"
296-
) from exc
294+
identity = self._get_codespaces_identity()
295+
if identity is not None:
296+
commit(
297+
self.root_dir,
298+
message=msg,
299+
no_verify=no_verify,
300+
committer=identity,
301+
author=identity,
302+
)
303+
else:
304+
raise SCMError(
305+
"Git username and email must be configured"
306+
) from exc
297307
except TimezoneFormatError as exc:
298308
raise SCMError("Invalid Git timestamp") from exc
299309

310+
def _get_codespaces_identity(self) -> Optional[bytes]:
311+
from dulwich.config import ConfigFile, StackedConfig
312+
from dulwich.repo import get_user_identity
313+
314+
if "CODESPACES" not in os.environ:
315+
return None
316+
try:
317+
config = StackedConfig(
318+
[ConfigFile.from_path("/usr/local/etc/gitconfig")]
319+
)
320+
return get_user_identity(config)
321+
except Exception: # pylint: disable=broad-except
322+
return None
323+
300324
def checkout(
301325
self,
302326
branch: str,

0 commit comments

Comments
 (0)