Bugfix: Gitignore file empty newlines (#1232)
This commit is contained in:
parent
7962e897e9
commit
91d872fb4c
@ -180,11 +180,10 @@ def initialize_gitignore():
|
|||||||
# Subtract current ignored files.
|
# Subtract current ignored files.
|
||||||
if os.path.exists(constants.GITIGNORE_FILE):
|
if os.path.exists(constants.GITIGNORE_FILE):
|
||||||
with open(constants.GITIGNORE_FILE, "r") as f:
|
with open(constants.GITIGNORE_FILE, "r") as f:
|
||||||
files -= set(f.read().replace(" ", "").strip().splitlines())
|
files |= set([line.strip() for line in f.readlines()])
|
||||||
|
# Write files to the .gitignore file.
|
||||||
# Add the new files to the .gitignore file.
|
with open(constants.GITIGNORE_FILE, "w") as f:
|
||||||
with open(constants.GITIGNORE_FILE, "a") as f:
|
f.write(f"{(path_ops.join(sorted(files))).lstrip()}")
|
||||||
f.write(f"\n{path_ops.join(files)}")
|
|
||||||
|
|
||||||
|
|
||||||
def initialize_app_directory(app_name: str, template: constants.Template):
|
def initialize_app_directory(app_name: str, template: constants.Template):
|
||||||
|
@ -502,9 +502,7 @@ def test_initialize_non_existent_gitignore(tmp_path, mocker, gitignore_exists):
|
|||||||
mocker: The mock object.
|
mocker: The mock object.
|
||||||
gitignore_exists: Whether a gitignore file exists in the root dir.
|
gitignore_exists: Whether a gitignore file exists in the root dir.
|
||||||
"""
|
"""
|
||||||
sep = os.sep
|
|
||||||
expected = constants.DEFAULT_GITIGNORE.copy()
|
expected = constants.DEFAULT_GITIGNORE.copy()
|
||||||
|
|
||||||
mocker.patch("pynecone.constants.GITIGNORE_FILE", tmp_path / ".gitignore")
|
mocker.patch("pynecone.constants.GITIGNORE_FILE", tmp_path / ".gitignore")
|
||||||
|
|
||||||
gitignore_file = tmp_path / ".gitignore"
|
gitignore_file = tmp_path / ".gitignore"
|
||||||
@ -512,8 +510,7 @@ def test_initialize_non_existent_gitignore(tmp_path, mocker, gitignore_exists):
|
|||||||
if gitignore_exists:
|
if gitignore_exists:
|
||||||
gitignore_file.touch()
|
gitignore_file.touch()
|
||||||
gitignore_file.write_text(
|
gitignore_file.write_text(
|
||||||
"""
|
"""pynecone.db
|
||||||
pynecone.db
|
|
||||||
__pycache__/
|
__pycache__/
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
@ -521,7 +518,5 @@ def test_initialize_non_existent_gitignore(tmp_path, mocker, gitignore_exists):
|
|||||||
prerequisites.initialize_gitignore()
|
prerequisites.initialize_gitignore()
|
||||||
|
|
||||||
assert gitignore_file.exists()
|
assert gitignore_file.exists()
|
||||||
file_content = gitignore_file.open().read()
|
file_content = [line.strip() for line in gitignore_file.open().readlines()]
|
||||||
file_content.replace(f"{sep}{sep}", sep)
|
assert set(file_content) - expected == set()
|
||||||
|
|
||||||
assert set(file_content.split()) == expected
|
|
||||||
|
Loading…
Reference in New Issue
Block a user