Skip to content

Commit d4b4b85

Browse files
author
Tom Nijboer
committed
test: add big directory to test_udpatediff.py to test dir exclude
1 parent 8fd40ee commit d4b4b85

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

tests/test_updatediff.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def test_updatediff(tmp_path_factory: pytest.TempPathFactory) -> None:
6262
Thanks for your attention.
6363
"""
6464
),
65+
(repo / ".gitignore.jinja"): ".venv/\n**/.cache/\n",
6566
}
6667
)
6768
with local.cwd(repo):
@@ -2089,3 +2090,119 @@ def test_skip_if_exists_templated(tmp_path_factory: pytest.TempPathFactory) -> N
20892090

20902091
run_update(str(dst), overwrite=True)
20912092
assert (dst / "skip-if-exists.txt").read_text() == "baz"
2093+
2094+
2095+
@pytest.mark.impure
2096+
def test_exclude_with_gitignore(tmp_path_factory: pytest.TempPathFactory) -> None:
2097+
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
2098+
# Prepare repo bundle
2099+
repo = src / "repo"
2100+
bundle = src / "demo_updatediff_repo.bundle"
2101+
build_file_tree(
2102+
{
2103+
(repo / ".copier-answers.yml.jinja"): (
2104+
"""\
2105+
# Changes here will be overwritten by Copier
2106+
{{ _copier_answers|to_nice_yaml }}
2107+
"""
2108+
),
2109+
(repo / "copier.yml"): (
2110+
"""\
2111+
_envops:
2112+
"keep_trailing_newline": True
2113+
project_name: to become a pirate
2114+
author_name: Guybrush
2115+
"""
2116+
),
2117+
(repo / "README.txt.jinja"): (
2118+
"""
2119+
Let me introduce myself.
2120+
2121+
My name is {{author_name}}, and my project is {{project_name}}.
2122+
2123+
Thanks for your attention.
2124+
"""
2125+
),
2126+
(repo / ".gitignore.jinja"): ".venv/\n**/.cache/\n",
2127+
}
2128+
)
2129+
with local.cwd(repo):
2130+
git("init")
2131+
git("add", ".")
2132+
git("commit", "-m", "Guybrush wants to be a pirate")
2133+
git("tag", "v0.0.1")
2134+
build_file_tree(
2135+
{
2136+
(repo / "README.txt.jinja"): (
2137+
"""
2138+
Let me introduce myself.
2139+
2140+
My name is {{author_name}}.
2141+
2142+
My project is {{project_name}}.
2143+
2144+
Thanks for your attention.
2145+
"""
2146+
),
2147+
}
2148+
)
2149+
with local.cwd(repo):
2150+
git("init")
2151+
git("add", ".")
2152+
git("commit", "-m", "Update README format")
2153+
git("bundle", "create", bundle, "--all")
2154+
git("tag", "v0.0.2")
2155+
2156+
# Generate repo bundle
2157+
target = dst / "target"
2158+
readme = target / "README.txt"
2159+
commit = git["commit", "--all"]
2160+
# Run copier 1st time, with specific tag
2161+
CopierApp.run(
2162+
[
2163+
"copier",
2164+
"copy",
2165+
str(bundle),
2166+
str(target),
2167+
"--defaults",
2168+
"--overwrite",
2169+
"--vcs-ref=v0.0.1",
2170+
],
2171+
exit=False,
2172+
)
2173+
# Check it's copied OK
2174+
assert load_answersfile_data(target) == {
2175+
"_commit": "v0.0.1",
2176+
"_src_path": str(bundle),
2177+
"author_name": "Guybrush",
2178+
"project_name": "to become a pirate",
2179+
}
2180+
assert readme.read_text() == dedent(
2181+
"""
2182+
Let me introduce myself.
2183+
2184+
My name is Guybrush, and my project is to become a pirate.
2185+
2186+
Thanks for your attention.
2187+
"""
2188+
)
2189+
# Init destination as a new independent git repo
2190+
with local.cwd(target):
2191+
git("init")
2192+
# Commit changes
2193+
# Test .gitignore by creating files in the ignored directories
2194+
venv_dir = target / ".venv"
2195+
venv_dir.mkdir()
2196+
cache_dir = target / "test_cache/.cache"
2197+
cache_dir.mkdir(parents=True)
2198+
for i in range(3000):
2199+
(venv_dir / f"file_{i}.txt").write_text(f"dummy {i}")
2200+
(cache_dir / f"file_{i}.txt").write_text(f"dummy cache {i}")
2201+
git("add", ".")
2202+
commit("-m", "hello world")
2203+
# Update target to latest tag and check it's updated in answers file
2204+
CopierApp.run(["copier", "update", "--defaults", "--UNSAFE"], exit=False)
2205+
assert venv_dir.exists()
2206+
assert (venv_dir / "file_0.txt").exists()
2207+
assert cache_dir.exists()
2208+
assert (cache_dir / "file_0.txt").exists()

0 commit comments

Comments
 (0)