3
3
"""
4
4
import json
5
5
import os
6
+ from pathlib import Path
6
7
7
8
from notebook .utils import url_path_join as ujoin , url2path
8
9
from notebook .base .handlers import APIHandler
@@ -32,8 +33,10 @@ def post(self):
32
33
}'
33
34
}
34
35
"""
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
+ )
37
40
self .finish (json .dumps (response ))
38
41
39
42
@@ -238,11 +241,7 @@ def post(self):
238
241
"""
239
242
POST request handler, adds all the changed files.
240
243
"""
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" ]))
246
245
247
246
248
247
class GitAddAllUntrackedHandler (GitHandler ):
@@ -255,11 +254,7 @@ def post(self):
255
254
"""
256
255
POST request handler, adds all the untracked files.
257
256
"""
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" ]))
263
258
264
259
265
260
class GitResetHandler (GitHandler ):
@@ -379,7 +374,7 @@ def post(self):
379
374
POST request handler, pulls files from a remote branch to your current branch.
380
375
"""
381
376
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 ))
383
378
384
379
self .finish (json .dumps (response ))
385
380
@@ -396,7 +391,7 @@ def post(self):
396
391
pushes committed files from your current branch to a remote branch
397
392
"""
398
393
data = self .get_json_body ()
399
- current_path = data [' current_path' ]
394
+ current_path = data [" current_path" ]
400
395
401
396
current_local_branch = self .git .get_current_branch (current_path )
402
397
current_upstream_branch = self .git .get_upstream_branch (
@@ -414,7 +409,9 @@ def post(self):
414
409
remote = upstream [0 ]
415
410
branch = ":" .join (["HEAD" , upstream [1 ]])
416
411
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
+ )
418
415
419
416
else :
420
417
response = {
@@ -440,15 +437,9 @@ def post(self):
440
437
self .finish (my_output )
441
438
442
439
443
-
444
440
class GitChangedFilesHandler (GitHandler ):
445
-
446
441
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 ())))
452
443
453
444
454
445
class GitConfigHandler (GitHandler ):
@@ -471,6 +462,7 @@ def post(self):
471
462
self .set_status (201 )
472
463
self .finish (json .dumps (response ))
473
464
465
+
474
466
class GitDiffContentHandler (GitHandler ):
475
467
"""
476
468
Handler for plain text diffs. Uses git show $REF:$FILE
@@ -489,12 +481,11 @@ def post(self):
489
481
490
482
491
483
class GitServerRootHandler (GitHandler ):
492
-
493
484
def get (self ):
494
485
# 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
+
498
489
499
490
def setup_handlers (web_app ):
500
491
"""
0 commit comments