(
tmp_path_factory: pytest.TempPathFactory,
)
| 1881 | |
| 1882 | |
| 1883 | def test_gitignore_file_unignored( |
| 1884 | tmp_path_factory: pytest.TempPathFactory, |
| 1885 | ) -> None: |
| 1886 | env_file = ".env" |
| 1887 | gitignore_file = ".gitignore" |
| 1888 | |
| 1889 | # Template in v1 has a file with a single line; |
| 1890 | # in v2 it changes that line. |
| 1891 | # Meanwhile, downstream project made the same change. |
| 1892 | src, dst = map(tmp_path_factory.mktemp, ("src", "dst")) |
| 1893 | |
| 1894 | # First, create the template with an initial file |
| 1895 | build_file_tree( |
| 1896 | { |
| 1897 | (src / gitignore_file): "", |
| 1898 | (src / env_file): "", |
| 1899 | (src / "{{_copier_conf.answers_file}}.jinja"): ( |
| 1900 | "{{_copier_answers|to_nice_yaml}}" |
| 1901 | ), |
| 1902 | } |
| 1903 | ) |
| 1904 | |
| 1905 | with local.cwd(src): |
| 1906 | git_init("hello template") |
| 1907 | git("tag", "v1") |
| 1908 | |
| 1909 | # Generate the project a first time, assert the file exists |
| 1910 | run_copy(str(src), dst) |
| 1911 | for f in (env_file, gitignore_file): |
| 1912 | assert (dst / f).exists() |
| 1913 | assert load_answersfile_data(dst).get("_commit") == "v1" |
| 1914 | |
| 1915 | # Start versioning the generated project |
| 1916 | with local.cwd(dst): |
| 1917 | git_init("hello project") |
| 1918 | |
| 1919 | # Add a file to the `.gitignore` file |
| 1920 | with local.cwd(src): |
| 1921 | Path(gitignore_file).write_text(env_file) |
| 1922 | git("commit", "-am", "ignore file") |
| 1923 | git("tag", "v2") |
| 1924 | |
| 1925 | # Update the generated project |
| 1926 | run_update(dst_path=dst, overwrite=True) |
| 1927 | assert load_answersfile_data(dst).get("_commit") == "v2" |
| 1928 | |
| 1929 | # Commit project changes. |
| 1930 | with local.cwd(dst): |
| 1931 | git("commit", "-am", "update to template v2") |
| 1932 | |
| 1933 | # Remove the file previously added to `.gitignore` |
| 1934 | with local.cwd(src): |
| 1935 | Path(gitignore_file).write_text("") |
| 1936 | git("commit", "-am", "un-ignore file") |
| 1937 | git("tag", "v3") |
| 1938 | |
| 1939 | # Update the generated project. |
| 1940 | # This would fail if `git add` was called without the `--force` flag; |
nothing calls this directly
no test coverage detected