From 608fb6d095409dd7ff51c16c1f417f1bc1f4da91 Mon Sep 17 00:00:00 2001 From: greg mooney Date: Wed, 11 Jun 2025 11:12:14 +0200 Subject: [PATCH 1/3] Create empty commit if needed --- jupyterlab_git/handlers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/jupyterlab_git/handlers.py b/jupyterlab_git/handlers.py index 34d09c506..0f9283024 100644 --- a/jupyterlab_git/handlers.py +++ b/jupyterlab_git/handlers.py @@ -516,6 +516,15 @@ async def post(self, path: str = ""): if data["checkout_branch"]: if data["new_check"]: + # Need to check if startpoint is valid + isStartPointValid = await self.git._get_branch_reference( + data["startpoint"], local_path + ) + + # If start point is not valid, we need to make an empty commit + if not isStartPointValid: + await self.git._empty_commit_for_init(local_path) + body = await self.git.checkout_new_branch( data["branchname"], data["startpoint"], local_path ) From a2943d0048bbcda1630a3ea4b0a0a4e686f1837c Mon Sep 17 00:00:00 2001 From: greg mooney Date: Wed, 11 Jun 2025 11:17:27 +0200 Subject: [PATCH 2/3] Rename empty commit method --- jupyterlab_git/git.py | 2 +- jupyterlab_git/handlers.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jupyterlab_git/git.py b/jupyterlab_git/git.py index 2859bfb5f..a4ae5e9e8 100644 --- a/jupyterlab_git/git.py +++ b/jupyterlab_git/git.py @@ -1323,7 +1323,7 @@ async def init(self, path): } return {"code": code, "actions": actions} - async def _empty_commit_for_init(self, path): + async def _empty_commit(self, path): cmd = ["git", "commit", "--allow-empty", "-m", '"First Commit"'] code, _, error = await self.__execute(cmd, cwd=path) diff --git a/jupyterlab_git/handlers.py b/jupyterlab_git/handlers.py index 0f9283024..70fb88fea 100644 --- a/jupyterlab_git/handlers.py +++ b/jupyterlab_git/handlers.py @@ -523,7 +523,7 @@ async def post(self, path: str = ""): # If start point is not valid, we need to make an empty commit if not isStartPointValid: - await self.git._empty_commit_for_init(local_path) + await self.git._empty_commit(local_path) body = await self.git.checkout_new_branch( data["branchname"], data["startpoint"], local_path @@ -725,7 +725,7 @@ 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)) + body = await self.git._empty_commit(self.url2localpath(path)) if body["code"] != 0: self.set_status(500) From 7cbe4dda5983b0b2f9435d9603606ba843dde33f Mon Sep 17 00:00:00 2001 From: Greg Mooney Date: Thu, 12 Jun 2025 10:35:11 +0200 Subject: [PATCH 3/3] Use snake case for consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: MichaƂ Krassowski <5832902+krassowski@users.noreply.github.com> --- jupyterlab_git/handlers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyterlab_git/handlers.py b/jupyterlab_git/handlers.py index 70fb88fea..83a118ad7 100644 --- a/jupyterlab_git/handlers.py +++ b/jupyterlab_git/handlers.py @@ -517,12 +517,12 @@ async def post(self, path: str = ""): if data["checkout_branch"]: if data["new_check"]: # Need to check if startpoint is valid - isStartPointValid = await self.git._get_branch_reference( + is_start_point_valid = await self.git._get_branch_reference( data["startpoint"], local_path ) # If start point is not valid, we need to make an empty commit - if not isStartPointValid: + if not is_start_point_valid: await self.git._empty_commit(local_path) body = await self.git.checkout_new_branch(