Skip to content

Commit 47613e2

Browse files
thoralf-gutierrezfcollonval
authored andcommitted
Fix #427 - filename split in detailed log (#428)
1 parent 43e66ea commit 47613e2

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

jupyterlab_git/git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def detailed_log(self, selected_hash, current_path):
280280
Execute git log -1 --stat --numstat --oneline command (used to get
281281
insertions & deletions per file) & return the result.
282282
"""
283-
p = Popen(
283+
p = subprocess.Popen(
284284
["git", "log", "-1", "--stat", "--numstat", "--oneline", selected_hash],
285285
stdout=PIPE,
286286
stderr=PIPE,
@@ -305,7 +305,7 @@ def detailed_log(self, selected_hash, current_path):
305305
note[count] = words[i]
306306
count += 1
307307
for num in range(1, int(length / 2)):
308-
line_info = line_array[num].split()
308+
line_info = line_array[num].split(maxsplit=2)
309309
words = line_info[2].split("/")
310310
length = len(words)
311311
result.append(
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# python lib
2+
from subprocess import PIPE
3+
from mock import patch, call, Mock
4+
5+
# local lib
6+
from jupyterlab_git.git import Git
7+
8+
9+
@patch('subprocess.Popen')
10+
def test_detailed_log(mock_subproc_popen):
11+
# Given
12+
process_output = [
13+
'f29660a (HEAD, origin/feature) Commit message',
14+
'10 3 notebook_without_spaces.ipynb',
15+
'11 4 Notebook with spaces.ipynb',
16+
'12 5 path/notebook_without_spaces.ipynb',
17+
'13 6 path/Notebook with spaces.ipynb',
18+
' notebook_without_spaces.ipynb | 13 ++++++++---',
19+
' Notebook with spaces.ipynb | 15 +++++++++----',
20+
' path/notebook_without_spaces.ipynb | 17 ++++++++++-----',
21+
' path/Notebook with spaces.ipynb | 19 +++++++++++------',
22+
' 4 files changed, 46 insertions(+), 18 deletions(-)'
23+
]
24+
process_mock = Mock(returncode=0)
25+
process_mock.communicate.side_effect = [
26+
('\n'.join(process_output).encode('utf-8'), ''.encode('utf-8')),
27+
]
28+
mock_subproc_popen.return_value = process_mock
29+
30+
expected_response = {
31+
'code': 0,
32+
'modified_file_note': ' 4 files changed, 46 insertions(+), 18 deletions(-)',
33+
'modified_files_count': '4',
34+
'number_of_insertions': '46',
35+
'number_of_deletions': '18',
36+
'modified_files': [
37+
{
38+
'modified_file_path': 'notebook_without_spaces.ipynb',
39+
'modified_file_name': 'notebook_without_spaces.ipynb',
40+
'insertion': '10',
41+
'deletion': '3'
42+
},
43+
{
44+
'modified_file_path': 'Notebook with spaces.ipynb',
45+
'modified_file_name': 'Notebook with spaces.ipynb',
46+
'insertion': '11',
47+
'deletion': '4'
48+
},
49+
{
50+
'modified_file_path': 'path/notebook_without_spaces.ipynb',
51+
'modified_file_name': 'notebook_without_spaces.ipynb',
52+
'insertion': '12',
53+
'deletion': '5'
54+
},
55+
{
56+
'modified_file_path': 'path/Notebook with spaces.ipynb',
57+
'modified_file_name': 'Notebook with spaces.ipynb',
58+
'insertion': '13',
59+
'deletion': '6'
60+
}
61+
]
62+
}
63+
64+
# When
65+
actual_response = Git(root_dir='/bin').detailed_log(
66+
selected_hash='f29660a2472e24164906af8653babeb48e4bf2ab',
67+
current_path='test_curr_path')
68+
69+
# Then
70+
mock_subproc_popen.assert_has_calls([
71+
call(
72+
['git', 'log', '-1', '--stat', '--numstat', '--oneline', 'f29660a2472e24164906af8653babeb48e4bf2ab'],
73+
stdout=PIPE,
74+
stderr=PIPE,
75+
cwd='/bin/test_curr_path'
76+
),
77+
call().communicate(),
78+
], any_order=False)
79+
80+
assert expected_response == actual_response

0 commit comments

Comments
 (0)