From aaa31e10c5d6e06acdee070064e5bcc3983e3944 Mon Sep 17 00:00:00 2001 From: greg mooney Date: Tue, 22 Oct 2024 16:48:24 +0200 Subject: [PATCH] Add empty commit when initing repo --- jupyterlab_git/git.py | 9 +++++++++ jupyterlab_git/handlers.py | 3 +++ 2 files changed, 12 insertions(+) diff --git a/jupyterlab_git/git.py b/jupyterlab_git/git.py index 77888b60f..39b1e6396 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 1a109dadc..5bdc4abb0 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)