Skip to content

Commit 27ac6a5

Browse files
authored
Merge pull request #719 from fcollonval/auto-backport-of-pr-717-on-0.11.x
Backport of #717 Add unit tests for ignore feature
2 parents 9a00d0b + 1bcd4f5 commit 27ac6a5

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

jupyterlab_git/tests/test_ignore.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import pytest
2+
3+
from jupyterlab_git.git import Git
4+
5+
from .testutils import FakeContentManager, maybe_future
6+
7+
8+
@pytest.mark.parametrize("ignore_content", [None, "dummy", "dummy\n"])
9+
@pytest.mark.asyncio
10+
async def test_ensure_gitignore(tmp_path, ignore_content):
11+
# Given
12+
ignore_file = tmp_path / ".gitignore"
13+
if ignore_content is not None:
14+
ignore_file.write_text(ignore_content)
15+
16+
# When
17+
actual_response = await Git(FakeContentManager("/bin")).ensure_gitignore(
18+
str(tmp_path)
19+
)
20+
21+
# Then
22+
assert {"code": 0} == actual_response
23+
content = ignore_file.read_text()
24+
assert len(content) == 0 or content.endswith("\n")
25+
26+
27+
@pytest.mark.asyncio
28+
async def test_ensure_gitignore_failure(tmp_path):
29+
# Given
30+
ignore_file = tmp_path / ".gitignore"
31+
ignore_file.write_text("dummy")
32+
ignore_file.chmod(200) # Set read only to generate an error
33+
34+
# When
35+
response = await Git(FakeContentManager("/bin")).ensure_gitignore(str(tmp_path))
36+
37+
# Then
38+
assert response["code"] == -1
39+
40+
41+
@pytest.mark.asyncio
42+
async def test_ignore(tmp_path):
43+
# Given
44+
ignore_file = tmp_path / ".gitignore"
45+
ignore_file.write_text("dummy")
46+
file_ignore = "to_ignore.txt"
47+
48+
# When
49+
response = await Git(FakeContentManager("/bin")).ignore(str(tmp_path), file_ignore)
50+
51+
# Then
52+
assert {"code": 0} == response
53+
content = ignore_file.read_text()
54+
content.endswith("{}\n".format(file_ignore))
55+
56+
57+
@pytest.mark.asyncio
58+
async def test_ignore_failure(tmp_path):
59+
# Given
60+
ignore_file = tmp_path / ".gitignore"
61+
ignore_file.write_text("dummy")
62+
ignore_file.chmod(200) # Set read only to generate an error
63+
64+
# When
65+
response = await Git(FakeContentManager("/bin")).ignore(
66+
str(tmp_path), "to_ignore.txt"
67+
)
68+
69+
# Then
70+
assert response["code"] == -1

src/model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,8 @@ export class GitExtension implements IGitExtension {
12011201
/**
12021202
* Make request to ignore one file.
12031203
*
1204-
* @param filename Optional name of the files to add
1204+
* @param filePath File to ignore
1205+
* @param useExtension Whether to ignore the file or its extension
12051206
*/
12061207
async ignore(filePath: string, useExtension: boolean): Promise<Response> {
12071208
await this.ready;

0 commit comments

Comments
 (0)