Skip to content

Commit 6579bc0

Browse files
3coinsPiyush Jain
andauthored
Fixed error switching remote branch, fixes #741 (#1066)
Co-authored-by: Piyush Jain <[email protected]>
1 parent b0f4765 commit 6579bc0

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

jupyterlab_git/git.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,8 @@ async def checkout_branch(self, branchname, path):
935935
is_remote_branch = self._is_remote_branch(reference_name)
936936

937937
if is_remote_branch:
938-
cmd = ["git", "checkout", "--track", branchname]
938+
local_branchname = branchname.split("/")[-1]
939+
cmd = ["git", "checkout", "-B", local_branchname, branchname]
939940
else:
940941
cmd = ["git", "checkout", branchname]
941942

jupyterlab_git/tests/test_branch.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ async def test_checkout_branch_noref_failure():
120120

121121
@pytest.mark.asyncio
122122
async def test_checkout_branch_remoteref_success():
123-
branch = "test-branch"
123+
branch = "origin/test-branch"
124+
local_branch = "test-branch"
124125
curr_path = str(Path("/bin/test_curr_path"))
125126
stdout_message = "checkout output from git"
126127
stderr_message = ""
@@ -145,7 +146,7 @@ async def test_checkout_branch_remoteref_success():
145146
# Then
146147
mock__get_branch_reference.assert_has_calls([call(branch, curr_path)])
147148

148-
cmd = ["git", "checkout", "--track", branch]
149+
cmd = ["git", "checkout", "-B", local_branch, branch]
149150
mock_execute.assert_called_once_with(
150151
cmd,
151152
cwd=str(Path("/bin") / "test_curr_path"),
@@ -229,7 +230,8 @@ async def test_checkout_branch_headsref_success():
229230

230231
@pytest.mark.asyncio
231232
async def test_checkout_branch_remoteref_failure():
232-
branch = "test-branch"
233+
branch = "origin/test-branch"
234+
local_branch = "test-branch"
233235
stdout_message = ""
234236
stderr_message = (
235237
"error: pathspec '{}' did not match any file(s) known to git".format(branch)
@@ -253,7 +255,7 @@ async def test_checkout_branch_remoteref_failure():
253255
)
254256

255257
# Then
256-
cmd = ["git", "checkout", "--track", branch]
258+
cmd = ["git", "checkout", "-B", local_branch, branch]
257259
mock_execute.assert_called_once_with(
258260
cmd,
259261
cwd=str(Path("/bin") / "test_curr_path"),

0 commit comments

Comments
 (0)