diff --git a/jupyterlab_git/git.py b/jupyterlab_git/git.py index 2859bfb5..a4ae5e9e 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 34d09c50..83a118ad 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 + 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 is_start_point_valid: + await self.git._empty_commit(local_path) + body = await self.git.checkout_new_branch( data["branchname"], data["startpoint"], local_path ) @@ -716,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)