Skip to content

Commit c498ec6

Browse files
authored
Merge pull request #507 from fcollonval/471-root_dir-as-posix
Format root directory folder as posix
2 parents e59b8e2 + 4d0aa98 commit c498ec6

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

jupyterlab_git/handlers.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import json
55
import os
6+
from pathlib import Path
67

78
from notebook.utils import url_path_join as ujoin, url2path
89
from notebook.base.handlers import APIHandler
@@ -32,8 +33,10 @@ def post(self):
3233
}'
3334
}
3435
"""
35-
data = json.loads(self.request.body.decode('utf-8'))
36-
response = self.git.clone(data['current_path'], data['clone_url'], data.get('auth', None))
36+
data = json.loads(self.request.body.decode("utf-8"))
37+
response = self.git.clone(
38+
data["current_path"], data["clone_url"], data.get("auth", None)
39+
)
3740
self.finish(json.dumps(response))
3841

3942

@@ -238,11 +241,7 @@ def post(self):
238241
"""
239242
POST request handler, adds all the changed files.
240243
"""
241-
self.finish(
242-
self.git.add_all_unstaged(
243-
self.get_json_body()["top_repo_path"]
244-
)
245-
)
244+
self.finish(self.git.add_all_unstaged(self.get_json_body()["top_repo_path"]))
246245

247246

248247
class GitAddAllUntrackedHandler(GitHandler):
@@ -255,11 +254,7 @@ def post(self):
255254
"""
256255
POST request handler, adds all the untracked files.
257256
"""
258-
self.finish(
259-
self.git.add_all_untracked(
260-
self.get_json_body()["top_repo_path"]
261-
)
262-
)
257+
self.finish(self.git.add_all_untracked(self.get_json_body()["top_repo_path"]))
263258

264259

265260
class GitResetHandler(GitHandler):
@@ -379,7 +374,7 @@ def post(self):
379374
POST request handler, pulls files from a remote branch to your current branch.
380375
"""
381376
data = self.get_json_body()
382-
response = self.git.pull(data['current_path'], data.get('auth', None))
377+
response = self.git.pull(data["current_path"], data.get("auth", None))
383378

384379
self.finish(json.dumps(response))
385380

@@ -396,7 +391,7 @@ def post(self):
396391
pushes committed files from your current branch to a remote branch
397392
"""
398393
data = self.get_json_body()
399-
current_path = data['current_path']
394+
current_path = data["current_path"]
400395

401396
current_local_branch = self.git.get_current_branch(current_path)
402397
current_upstream_branch = self.git.get_upstream_branch(
@@ -414,7 +409,9 @@ def post(self):
414409
remote = upstream[0]
415410
branch = ":".join(["HEAD", upstream[1]])
416411

417-
response = self.git.push(remote, branch, current_path, data.get('auth', None))
412+
response = self.git.push(
413+
remote, branch, current_path, data.get("auth", None)
414+
)
418415

419416
else:
420417
response = {
@@ -440,15 +437,9 @@ def post(self):
440437
self.finish(my_output)
441438

442439

443-
444440
class GitChangedFilesHandler(GitHandler):
445-
446441
def post(self):
447-
self.finish(
448-
json.dumps(
449-
self.git.changed_files(**self.get_json_body())
450-
)
451-
)
442+
self.finish(json.dumps(self.git.changed_files(**self.get_json_body())))
452443

453444

454445
class GitConfigHandler(GitHandler):
@@ -471,6 +462,7 @@ def post(self):
471462
self.set_status(201)
472463
self.finish(json.dumps(response))
473464

465+
474466
class GitDiffContentHandler(GitHandler):
475467
"""
476468
Handler for plain text diffs. Uses git show $REF:$FILE
@@ -489,12 +481,11 @@ def post(self):
489481

490482

491483
class GitServerRootHandler(GitHandler):
492-
493484
def get(self):
494485
# Similar to https://github.com/jupyter/nbdime/blob/master/nbdime/webapp/nb_server_extension.py#L90-L91
495-
self.finish(json.dumps({
496-
"server_root": getattr(self.contents_manager, 'root_dir', None)
497-
}))
486+
root_dir = getattr(self.contents_manager, "root_dir", None)
487+
self.finish(json.dumps({"server_root": Path(root_dir).as_posix()}))
488+
498489

499490
def setup_handlers(web_app):
500491
"""

0 commit comments

Comments
 (0)