Skip to content

Commit 5e6c871

Browse files
authored
Merge pull request #366 from fcollonval/fix-author
Identity feature
2 parents f1e7640 + 851912b commit 5e6c871

File tree

17 files changed

+1003
-327
lines changed

17 files changed

+1003
-327
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ cache:
55
pip: true
66
directories:
77
- /home/travis/.yarn-cache/
8-
install: pip install pytest jupyterlab
8+
install: pip install pytest "jupyterlab>=1.0.3"
99
script:
1010
- pytest tests/unit
1111
- yarn
1212
- yarn build
1313
- yarn test
1414
- pip install .
15+
- jupyter serverextension enable --py jupyterlab_git
1516
- jupyter labextension install .
1617
- python -m jupyterlab.browser_check
1718
- yarn run lint

jupyterlab_git/git.py

Lines changed: 153 additions & 96 deletions
Large diffs are not rendered by default.

jupyterlab_git/handlers.py

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
import json
55

6-
76
from notebook.utils import url_path_join as ujoin
87
from notebook.base.handlers import APIHandler
98

@@ -29,8 +28,8 @@ def post(self):
2928
'repo_url': 'https://github.com/path/to/myrepo'
3029
}
3130
"""
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"])
3433
self.finish(json.dumps(response))
3534

3635

@@ -290,9 +289,7 @@ def post(self):
290289
)
291290
else:
292291
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)
296293
elif data["checkout_all"]:
297294
my_output = self.git.checkout_all(top_repo_path)
298295
else:
@@ -327,12 +324,10 @@ def post(self):
327324
'current_path': 'current_file_browser_path',
328325
}
329326
"""
330-
current_path = self.get_json_body()['current_path']
327+
current_path = self.get_json_body()["current_path"]
331328
current_branch = self.git.get_current_branch(current_path)
332329
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}))
336331

337332

338333
class GitPullHandler(GitHandler):
@@ -344,7 +339,7 @@ def post(self):
344339
"""
345340
POST request handler, pulls files from a remote branch to your current branch.
346341
"""
347-
output = self.git.pull(self.get_json_body()['current_path'])
342+
output = self.git.pull(self.get_json_body()["current_path"])
348343
self.finish(json.dumps(output))
349344

350345

@@ -359,28 +354,32 @@ def post(self):
359354
POST request handler,
360355
pushes committed files from your current branch to a remote branch
361356
"""
362-
current_path = self.get_json_body()['current_path']
357+
current_path = self.get_json_body()["current_path"]
363358

364359
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+
)
366363

367364
if current_upstream_branch and current_upstream_branch.strip():
368-
upstream = current_upstream_branch.split('/')
365+
upstream = current_upstream_branch.split("/")
369366
if len(upstream) == 1:
370367
# If upstream is a local branch
371-
remote = '.'
372-
branch = ':'.join(['HEAD', upstream[0]])
368+
remote = "."
369+
branch = ":".join(["HEAD", upstream[0]])
373370
else:
374371
# If upstream is a remote branch
375372
remote = upstream[0]
376-
branch = ':'.join(['HEAD', upstream[1]])
373+
branch = ":".join(["HEAD", upstream[1]])
377374

378375
response = self.git.push(remote, branch, current_path)
379376

380377
else:
381378
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+
),
384383
}
385384
self.finish(json.dumps(response))
386385

@@ -423,6 +422,27 @@ def post(self):
423422
)
424423

425424

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+
426446
def setup_handlers(web_app):
427447
"""
428448
Setups all of the git command handlers.
@@ -450,6 +470,7 @@ def setup_handlers(web_app):
450470
("/git/add_all_untracked", GitAddAllUntrackedHandler),
451471
("/git/clone", GitCloneHandler),
452472
("/git/upstream", GitUpstreamHandler),
473+
("/git/config", GitConfigHandler),
453474
("/git/changed_files", GitChangedFilesHandler)
454475
]
455476

0 commit comments

Comments
 (0)