3
3
"""
4
4
import json
5
5
6
-
7
6
from notebook .utils import url_path_join as ujoin
8
7
from notebook .base .handlers import APIHandler
9
8
@@ -29,8 +28,8 @@ def post(self):
29
28
'repo_url': 'https://github.com/path/to/myrepo'
30
29
}
31
30
"""
32
- data = json .loads (self .request .body .decode (' utf-8' ))
33
- response = self .git .clone (data [' current_path' ], data [' clone_url' ])
31
+ data = json .loads (self .request .body .decode (" utf-8" ))
32
+ response = self .git .clone (data [" current_path" ], data [" clone_url" ])
34
33
self .finish (json .dumps (response ))
35
34
36
35
@@ -290,9 +289,7 @@ def post(self):
290
289
)
291
290
else :
292
291
print ("switch to an old branch" )
293
- my_output = self .git .checkout_branch (
294
- data ["branchname" ], top_repo_path
295
- )
292
+ my_output = self .git .checkout_branch (data ["branchname" ], top_repo_path )
296
293
elif data ["checkout_all" ]:
297
294
my_output = self .git .checkout_all (top_repo_path )
298
295
else :
@@ -327,12 +324,10 @@ def post(self):
327
324
'current_path': 'current_file_browser_path',
328
325
}
329
326
"""
330
- current_path = self .get_json_body ()[' current_path' ]
327
+ current_path = self .get_json_body ()[" current_path" ]
331
328
current_branch = self .git .get_current_branch (current_path )
332
329
upstream = self .git .get_upstream_branch (current_path , current_branch )
333
- self .finish (json .dumps ({
334
- 'upstream' : upstream
335
- }))
330
+ self .finish (json .dumps ({"upstream" : upstream }))
336
331
337
332
338
333
class GitPullHandler (GitHandler ):
@@ -344,7 +339,7 @@ def post(self):
344
339
"""
345
340
POST request handler, pulls files from a remote branch to your current branch.
346
341
"""
347
- output = self .git .pull (self .get_json_body ()[' current_path' ])
342
+ output = self .git .pull (self .get_json_body ()[" current_path" ])
348
343
self .finish (json .dumps (output ))
349
344
350
345
@@ -359,28 +354,32 @@ def post(self):
359
354
POST request handler,
360
355
pushes committed files from your current branch to a remote branch
361
356
"""
362
- current_path = self .get_json_body ()[' current_path' ]
357
+ current_path = self .get_json_body ()[" current_path" ]
363
358
364
359
current_local_branch = self .git .get_current_branch (current_path )
365
- current_upstream_branch = self .git .get_upstream_branch (current_path , current_local_branch )
360
+ current_upstream_branch = self .git .get_upstream_branch (
361
+ current_path , current_local_branch
362
+ )
366
363
367
364
if current_upstream_branch and current_upstream_branch .strip ():
368
- upstream = current_upstream_branch .split ('/' )
365
+ upstream = current_upstream_branch .split ("/" )
369
366
if len (upstream ) == 1 :
370
367
# If upstream is a local branch
371
- remote = '.'
372
- branch = ':' .join ([' HEAD' , upstream [0 ]])
368
+ remote = "."
369
+ branch = ":" .join ([" HEAD" , upstream [0 ]])
373
370
else :
374
371
# If upstream is a remote branch
375
372
remote = upstream [0 ]
376
- branch = ':' .join ([' HEAD' , upstream [1 ]])
373
+ branch = ":" .join ([" HEAD" , upstream [1 ]])
377
374
378
375
response = self .git .push (remote , branch , current_path )
379
376
380
377
else :
381
378
response = {
382
- 'code' : 128 ,
383
- 'message' : 'fatal: The current branch {} has no upstream branch.' .format (current_local_branch )
379
+ "code" : 128 ,
380
+ "message" : "fatal: The current branch {} has no upstream branch." .format (
381
+ current_local_branch
382
+ ),
384
383
}
385
384
self .finish (json .dumps (response ))
386
385
@@ -423,6 +422,27 @@ def post(self):
423
422
)
424
423
425
424
425
+ class GitConfigHandler (GitHandler ):
426
+ """
427
+ Handler for 'git config' commands
428
+ """
429
+
430
+ def post (self ):
431
+ """
432
+ POST get (if no options are passed) or set configuration options
433
+ """
434
+ data = self .get_json_body ()
435
+ top_repo_path = data ["top_repo_path" ]
436
+ options = data .get ("options" , {})
437
+ response = self .git .config (top_repo_path , ** options )
438
+
439
+ if response ["code" ] != 0 :
440
+ self .set_status (500 )
441
+ else :
442
+ self .set_status (201 )
443
+ self .finish (json .dumps (response ))
444
+
445
+
426
446
def setup_handlers (web_app ):
427
447
"""
428
448
Setups all of the git command handlers.
@@ -450,6 +470,7 @@ def setup_handlers(web_app):
450
470
("/git/add_all_untracked" , GitAddAllUntrackedHandler ),
451
471
("/git/clone" , GitCloneHandler ),
452
472
("/git/upstream" , GitUpstreamHandler ),
473
+ ("/git/config" , GitConfigHandler ),
453
474
("/git/changed_files" , GitChangedFilesHandler )
454
475
]
455
476
0 commit comments