Skip to content

Commit b3f3fbe

Browse files
ameier38jaipreet-s
authored andcommitted
Fix/push pull windows (#344)
* fix/push-pull-windows: fixes #291; add GIT_TERMINAL_PROMPT in env arg * fix/push-pull-windows: update push pull functions * fix/push-pull-windows: update tests * fix/push-pull-windows: update clone tests * fix/push-pull-windows: fix tests to actually check env * fix/push-pull-windows: remove unused import * fix/push-pull-windows: remove temp variable
1 parent e989c40 commit b3f3fbe

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

jupyterlab_git/git.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ def clone(self, current_path, repo_url):
2323
:param repo_url: the URL of the repository to be cloned.
2424
:return: response with status code and error message.
2525
"""
26+
env = os.environ.copy()
27+
env['GIT_TERMINAL_PROMPT'] = '0'
2628
p = subprocess.Popen(
27-
['GIT_TERMINAL_PROMPT=0 git clone {}'.format(unquote(repo_url))],
29+
['git', 'clone', unquote(repo_url)],
2830
shell=True,
2931
stdout=PIPE,
3032
stderr=PIPE,
3133
cwd=os.path.join(self.root_dir, current_path),
34+
env=env,
3235
)
3336
_, error = p.communicate()
3437

@@ -449,13 +452,15 @@ def pull(self, curr_fb_path):
449452
Execute git pull --no-commit. Disables prompts for the password to avoid the terminal hanging while waiting
450453
for auth.
451454
"""
452-
455+
env = os.environ.copy()
456+
env['GIT_TERMINAL_PROMPT'] = '0'
453457
p = subprocess.Popen(
454-
['GIT_TERMINAL_PROMPT=0 git pull --no-commit'],
458+
['git', 'pull', '--no-commit'],
455459
shell=True,
456460
stdout=PIPE,
457461
stderr=PIPE,
458462
cwd=os.path.join(self.root_dir, curr_fb_path),
463+
env=env,
459464
)
460465
_, error = p.communicate()
461466

@@ -472,12 +477,15 @@ def push(self, remote, branch, curr_fb_path):
472477
"""
473478
Execute `git push $UPSTREAM $BRANCH`. The choice of upstream and branch is up to the caller.
474479
"""
480+
env = os.environ.copy()
481+
env['GIT_TERMINAL_PROMPT'] = '0'
475482
p = subprocess.Popen(
476-
['GIT_TERMINAL_PROMPT=0 git push {} {}'.format(remote, branch)],
483+
['git', 'push', remote, branch],
477484
shell=True,
478485
stdout=PIPE,
479486
stderr=PIPE,
480487
cwd=os.path.join(self.root_dir, curr_fb_path),
488+
env=env,
481489
)
482490
_, error = p.communicate()
483491

tests/unit/test_clone.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77

88
@patch('subprocess.Popen')
9+
@patch('os.environ', {'TEST': 'test'})
910
def test_git_clone_success(mock_subproc_popen):
1011
# Given
1112
process_mock = Mock()
@@ -22,18 +23,20 @@ def test_git_clone_success(mock_subproc_popen):
2223
# Then
2324
mock_subproc_popen.assert_has_calls([
2425
call(
25-
['GIT_TERMINAL_PROMPT=0 git clone ghjkhjkl'],
26+
['git', 'clone', 'ghjkhjkl'],
2627
stdout=PIPE,
2728
stderr=PIPE,
2829
cwd='/bin/test_curr_path',
29-
shell=True
30+
shell=True,
31+
env={'TEST': 'test', 'GIT_TERMINAL_PROMPT': '0'},
3032
),
3133
call().communicate()
3234
])
3335
assert {'code': 0} == actual_response
3436

3537

3638
@patch('subprocess.Popen')
39+
@patch('os.environ', {'TEST': 'test'})
3740
def test_git_clone_failure_from_git(mock_subproc_popen):
3841
"""
3942
Git internally will throw an error if it is an invalid URL, or if there is a permissions issue. We want to just
@@ -55,11 +58,12 @@ def test_git_clone_failure_from_git(mock_subproc_popen):
5558
# Then
5659
mock_subproc_popen.assert_has_calls([
5760
call(
58-
['GIT_TERMINAL_PROMPT=0 git clone ghjkhjkl'],
61+
['git', 'clone', 'ghjkhjkl'],
5962
stdout=PIPE,
6063
stderr=PIPE,
6164
cwd='/bin/test_curr_path',
62-
shell=True
65+
shell=True,
66+
env={'TEST': 'test', 'GIT_TERMINAL_PROMPT': '0'},
6367
),
6468
call().communicate()
6569
])

tests/unit/test_pushpull.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77

88
@patch('subprocess.Popen')
9+
@patch('os.environ', {'TEST': 'test'})
910
def test_git_pull_fail(mock_subproc_popen):
1011
# Given
1112
process_mock = Mock()
@@ -22,18 +23,20 @@ def test_git_pull_fail(mock_subproc_popen):
2223
# Then
2324
mock_subproc_popen.assert_has_calls([
2425
call(
25-
['GIT_TERMINAL_PROMPT=0 git pull --no-commit'],
26+
['git', 'pull', '--no-commit'],
2627
stdout=PIPE,
2728
stderr=PIPE,
2829
cwd='/bin/test_curr_path',
29-
shell=True
30+
shell=True,
31+
env={'TEST': 'test', 'GIT_TERMINAL_PROMPT': '0'},
3032
),
3133
call().communicate()
3234
])
3335
assert {'code': 1, 'message': 'Authentication failed'} == actual_response
3436

3537

3638
@patch('subprocess.Popen')
39+
@patch('os.environ', {'TEST': 'test'})
3740
def test_git_pull_success(mock_subproc_popen):
3841
# Given
3942
process_mock = Mock()
@@ -50,18 +53,20 @@ def test_git_pull_success(mock_subproc_popen):
5053
# Then
5154
mock_subproc_popen.assert_has_calls([
5255
call(
53-
['GIT_TERMINAL_PROMPT=0 git pull --no-commit'],
56+
['git', 'pull', '--no-commit'],
5457
stdout=PIPE,
5558
stderr=PIPE,
5659
cwd='/bin/test_curr_path',
57-
shell=True
60+
shell=True,
61+
env={'TEST': 'test', 'GIT_TERMINAL_PROMPT': '0'},
5862
),
5963
call().communicate()
6064
])
6165
assert {'code': 0} == actual_response
6266

6367

6468
@patch('subprocess.Popen')
69+
@patch('os.environ', {'TEST': 'test'})
6570
def test_git_push_fail(mock_subproc_popen):
6671
# Given
6772
process_mock = Mock()
@@ -78,18 +83,20 @@ def test_git_push_fail(mock_subproc_popen):
7883
# Then
7984
mock_subproc_popen.assert_has_calls([
8085
call(
81-
['GIT_TERMINAL_PROMPT=0 git push test_origin HEAD:test_master'],
86+
['git', 'push', 'test_origin', 'HEAD:test_master'],
8287
stdout=PIPE,
8388
stderr=PIPE,
8489
cwd='/bin/test_curr_path',
85-
shell=True
90+
shell=True,
91+
env={'TEST': 'test', 'GIT_TERMINAL_PROMPT': '0'},
8692
),
8793
call().communicate()
8894
])
8995
assert {'code': 1, 'message': 'Authentication failed'} == actual_response
9096

9197

9298
@patch('subprocess.Popen')
99+
@patch('os.environ', {'TEST': 'test'})
93100
def test_git_push_success(mock_subproc_popen):
94101
# Given
95102
process_mock = Mock()
@@ -106,11 +113,12 @@ def test_git_push_success(mock_subproc_popen):
106113
# Then
107114
mock_subproc_popen.assert_has_calls([
108115
call(
109-
['GIT_TERMINAL_PROMPT=0 git push . HEAD:test_master'],
116+
['git', 'push', '.', 'HEAD:test_master'],
110117
stdout=PIPE,
111118
stderr=PIPE,
112119
cwd='/bin/test_curr_path',
113-
shell=True
120+
shell=True,
121+
env={'TEST': 'test', 'GIT_TERMINAL_PROMPT': '0'},
114122
),
115123
call().communicate()
116124
])

0 commit comments

Comments
 (0)