diff --git a/jupyterlab_git/git.py b/jupyterlab_git/git.py index 77888b60..39b1e639 100644 --- a/jupyterlab_git/git.py +++ b/jupyterlab_git/git.py @@ -1323,6 +1323,15 @@ async def init(self, path): } return {"code": code, "actions": actions} + async def _empty_commit_for_init(self, path): + cmd = ["git", "commit", "--allow-empty", "-m", '"First Commit"'] + + code, _, error = await self.__execute(cmd, cwd=path) + + if code != 0: + return {"code": code, "command": " ".join(cmd), "message": error} + return {"code": code} + async def _maybe_run_actions(self, name, cwd): code = 0 actions = None diff --git a/jupyterlab_git/handlers.py b/jupyterlab_git/handlers.py index 1a109dad..5bdc4abb 100644 --- a/jupyterlab_git/handlers.py +++ b/jupyterlab_git/handlers.py @@ -715,6 +715,9 @@ async def post(self, path: str = ""): """ body = await self.git.init(self.url2localpath(path)) + if body["code"] == 0: + body = await self.git._empty_commit_for_init(self.url2localpath(path)) + if body["code"] != 0: self.set_status(500)