Skip to content

Commit 12f25dd

Browse files
committed
Cleaned up passing of branch on query string
The following changes ensure branch is only passed when it has been defined: - branch becomes keyword parameter to GitPuller - branch only addd to query string when not undefined - branch only encoded into url when exists
1 parent 8423af4 commit 12f25dd

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

nbgitpuller/handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get(self):
5252

5353
try:
5454
repo = self.get_argument('repo')
55-
branch = self.get_argument('branch')
55+
branch = self.get_argument('branch', None)
5656
depth = self.get_argument('depth', None)
5757
if depth:
5858
depth = int(depth)
@@ -73,7 +73,7 @@ def get(self):
7373
self.set_header('content-type', 'text/event-stream')
7474
self.set_header('cache-control', 'no-cache')
7575

76-
gp = GitPuller(repo, branch, repo_dir, depth=depth, parent=self.settings['nbapp'])
76+
gp = GitPuller(repo, repo_dir, branch=branch, depth=depth, parent=self.settings['nbapp'])
7777

7878
q = Queue()
7979

nbgitpuller/pull.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,16 @@ def _depth_default(self):
6666
where the GitPuller class hadn't been loaded already."""
6767
return int(os.environ.get('NBGITPULLER_DEPTH', 1))
6868

69-
def __init__(self, git_url, branch_name, repo_dir, **kwargs):
70-
assert git_url and branch_name
69+
def __init__(self, git_url, repo_dir, **kwargs):
70+
assert git_url
7171

7272
self.git_url = git_url
73+
self.branch_name = kwargs.pop("branch")
7374

74-
if branch_name == "None":
75+
if self.branch_name is None:
7576
self.branch_name = self.resolve_default_branch()
76-
elif not self.branch_exists(branch_name):
77-
raise ValueError(f"{branch_name}: branch not found in {self.git_url}")
78-
else:
79-
self.branch_name = branch_name
77+
elif not self.branch_exists(self.branch_name):
78+
raise ValueError(f"Branch: {self.branch_name} -- not found in repo: {self.git_url}")
8079

8180
self.repo_dir = repo_dir
8281
newargs = {k: v for k, v in kwargs.items() if v is not None}
@@ -304,13 +303,11 @@ def main():
304303

305304
parser = argparse.ArgumentParser(description='Synchronizes a github repository with a local repository.')
306305
parser.add_argument('git_url', help='Url of the repo to sync')
307-
parser.add_argument('branch_name', default='master', help='Branch of repo to sync', nargs='?')
308306
parser.add_argument('repo_dir', default='.', help='Path to clone repo under', nargs='?')
309307
args = parser.parse_args()
310308

311309
for line in GitPuller(
312310
args.git_url,
313-
args.branch_name,
314311
args.repo_dir
315312
).pull():
316313
print(line)

nbgitpuller/static/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ require([
4444
// Start git pulling handled by SyncHandler, declared in handlers.py
4545
var syncUrlParams = {
4646
repo: this.repo,
47-
branch: this.branch,
4847
targetpath: this.targetpath
4948
}
5049
if (typeof this.depth !== 'undefined' && this.depth != undefined) {
5150
syncUrlParams['depth'] = this.depth;
5251
}
52+
if (typeof this.branch !== 'undefined' && this.branch != undefined) {
53+
syncUrlParams['branch'] = this.branch;
54+
}
5355
var syncUrl = this.baseUrl + 'git-pull/api?' + $.param(syncUrlParams);
5456

5557
this.eventSource = new EventSource(syncUrl);

nbgitpuller/templates/status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
data-base-url="{{ base_url | urlencode }}"
66
data-repo="{{ repo | urlencode }}"
77
data-path="{{ path | urlencode }}"
8-
data-branch="{{ branch | urlencode }}"
8+
{% if branch %}data-branch="{{ branch | urlencode }}"{% endif %}
99
{% if depth %}data-depth="{{ depth | urlencode }}"{% endif %}
1010
data-targetpath="{{ targetpath | urlencode }}"
1111
{% endblock %}

tests/test_gitpuller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Puller(Repository):
6464
def __init__(self, remote, path='puller', branch="master", *args, **kwargs):
6565
super().__init__(path)
6666
remotepath = "file://%s" % os.path.abspath(remote.path)
67-
self.gp = GitPuller(remotepath, branch, path, *args, **kwargs)
67+
self.gp = GitPuller(remotepath, path, branch=branch, *args, **kwargs)
6868

6969
def pull_all(self):
7070
for line in self.gp.pull():

0 commit comments

Comments
 (0)