|
| 1 | +import os, pytest |
| 2 | + |
| 3 | +# Testcases issue https://github.com/tj/git-extras/issues/1081 |
| 4 | +class TestGitArchiveFile: |
| 5 | + def test_init(self, temp_repo): |
| 6 | + git = temp_repo.get_repo_git() |
| 7 | + tmp_file = temp_repo.get_file(0) |
| 8 | + temp_repo.writefile(tmp_file, "data") |
| 9 | + git.add(".") |
| 10 | + git.commit("-m", "test: add data") |
| 11 | + git.tag("0.1.0", "-m", "bump: 0.1.0") |
| 12 | + |
| 13 | + def test_archive_file_on_tags_branch(self, temp_repo): |
| 14 | + git = temp_repo.get_repo_git() |
| 15 | + git.checkout("-b", "tags0.1.0") |
| 16 | + temp_repo.invoke_installed_extras_command("archive-file") |
| 17 | + filename = "{0}.{1}.zip".format(temp_repo.get_repo_dirname(), git.describe()) |
| 18 | + assert filename in os.listdir() |
| 19 | + |
| 20 | + def test_archive_file_on_any_not_tags_branch_without_default_branch(self, temp_repo): |
| 21 | + git = temp_repo.get_repo_git() |
| 22 | + git.checkout("-b", "not-tags-branch") |
| 23 | + temp_repo.invoke_installed_extras_command("archive-file") |
| 24 | + filename = "{0}.{1}.{2}.zip".format( |
| 25 | + temp_repo.get_repo_dirname(), |
| 26 | + git.describe("--always", "--long"), |
| 27 | + "not-tags-branch") |
| 28 | + assert filename in os.listdir() |
| 29 | + |
| 30 | + def test_archive_file_on_any_not_tags_branch_with_default_branch(self, temp_repo): |
| 31 | + git = temp_repo.get_repo_git() |
| 32 | + git.checkout("master") |
| 33 | + git.config("git-extras.default-branch", "master") |
| 34 | + temp_repo.invoke_installed_extras_command("archive-file") |
| 35 | + filename = "{0}.{1}.zip".format( |
| 36 | + temp_repo.get_repo_dirname(), |
| 37 | + git.describe("--always", "--long")) |
| 38 | + assert filename in os.listdir() |
| 39 | + |
| 40 | + def test_archive_file_on_branch_name_has_slash(self, temp_repo): |
| 41 | + git = temp_repo.get_repo_git() |
| 42 | + git.checkout("-b", "feature/slash") |
| 43 | + temp_repo.invoke_installed_extras_command("archive-file") |
| 44 | + filename = "{0}.{1}.{2}.zip".format( |
| 45 | + temp_repo.get_repo_dirname(), |
| 46 | + git.describe("--always", "--long"), |
| 47 | + "feature-slash") |
| 48 | + assert filename in os.listdir() |
| 49 | + |
| 50 | + @pytest.mark.parametrize("named_temp_repo", ["backslash\\dir"], indirect=True) |
| 51 | + def test_archive_file_on_dirname_has_backslash(self, named_temp_repo): |
| 52 | + named_temp_repo.invoke_installed_extras_command("archive-file") |
| 53 | + git = named_temp_repo.get_repo_git() |
| 54 | + filename = "{0}.{1}.{2}.zip".format( |
| 55 | + "backslash-dir", |
| 56 | + git.describe("--always", "--long"), |
| 57 | + "master") |
| 58 | + assert filename in os.listdir() |
| 59 | + |
| 60 | + def test_archive_file_on_tag_name_has_slash(self, temp_repo): |
| 61 | + temp_repo.switch_cwd_under_repo() |
| 62 | + git = temp_repo.get_repo_git() |
| 63 | + git.checkout("master") |
| 64 | + git.tag("--delete", "0.1.0") |
| 65 | + git.tag("0.1.0/slash", "-m", "bump: 0.1.0") |
| 66 | + temp_repo.invoke_installed_extras_command("archive-file") |
| 67 | + description_include_version = git.describe("--always", "--long") |
| 68 | + filename = "{0}.{1}.zip".format( |
| 69 | + temp_repo.get_repo_dirname(), |
| 70 | + description_include_version.replace("/", "-")) |
| 71 | + assert filename in os.listdir() |
0 commit comments