Skip to content

Commit 22b5174

Browse files
gjmooneyjtpiokrassowski
authored
Fix branch creation for empty clone (#1411)
* Create empty commit if needed * Rename empty commit method * Use snake case for consistency Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com> --------- Co-authored-by: Jeremy Tuloup <jeremy.tuloup@gmail.com> Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
1 parent 7351e3a commit 22b5174

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

jupyterlab_git/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ async def init(self, path):
13231323
}
13241324
return {"code": code, "actions": actions}
13251325

1326-
async def _empty_commit_for_init(self, path):
1326+
async def _empty_commit(self, path):
13271327
cmd = ["git", "commit", "--allow-empty", "-m", '"First Commit"']
13281328

13291329
code, _, error = await self.__execute(cmd, cwd=path)

jupyterlab_git/handlers.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,15 @@ async def post(self, path: str = ""):
516516

517517
if data["checkout_branch"]:
518518
if data["new_check"]:
519+
# Need to check if startpoint is valid
520+
is_start_point_valid = await self.git._get_branch_reference(
521+
data["startpoint"], local_path
522+
)
523+
524+
# If start point is not valid, we need to make an empty commit
525+
if not is_start_point_valid:
526+
await self.git._empty_commit(local_path)
527+
519528
body = await self.git.checkout_new_branch(
520529
data["branchname"], data["startpoint"], local_path
521530
)
@@ -716,7 +725,7 @@ async def post(self, path: str = ""):
716725
body = await self.git.init(self.url2localpath(path))
717726

718727
if body["code"] == 0:
719-
body = await self.git._empty_commit_for_init(self.url2localpath(path))
728+
body = await self.git._empty_commit(self.url2localpath(path))
720729

721730
if body["code"] != 0:
722731
self.set_status(500)

0 commit comments

Comments
 (0)