Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
with open(tmppath / ".gitignore", "w") as ignore:
ignore.write("*.py[co]\n")
index = repo.index
index.add([".gitignore"])
author = Actor("An author", "author@example.com")
committer = Actor("A committer", "committer@example.com")
index.commit("ignore python cache", author=author, committer=committer)
config = DEFAULT_CONFIG
config.path = tmpdir
with pytest.raises(WilyIgnoreGitRepositoryError):
archiver = GitArchiver(config)
with open(tmppath / ".gitignore", "w") as ignore:
ignore.write(".wily/")
index.add([".gitignore"])
commit1 = index.commit("commit1", author=author, committer=committer)
# Write a test file to the repo
with open(tmppath / "blah.py", "w") as ignore:
ignore.write("*.py[co]\n")
index.add(["blah.py"])
config = DEFAULT_CONFIG
config.path = tmpdir
with pytest.raises(DirtyGitRepositoryError):
archiver = GitArchiver(config)
archiver.revisions(tmpdir, 2)
# First commit
with open(tmppath / ".gitignore", "w") as ignore:
ignore.write(".wily/")
index.add([".gitignore"])
commit1 = index.commit("commit1", author=author, committer=committer)
# Second commit
with open(tmppath / "test.py", "w") as file1:
file1.write("print(1)")
index.add(["test.py"])
commit2 = index.commit("commit2", author=author, committer=committer)
config = DEFAULT_CONFIG
config.path = tmpdir
archiver = GitArchiver(config)
assert archiver.config == config
revisions = archiver.revisions(tmpdir, 3)
assert len(revisions) == 2
assert revisions[0].message == "commit2"
assert revisions[0].author_email == "author@example.com"
assert revisions[0].author_name == "An author"
assert (
revisions[0].key in commit2.name_rev
and revisions[0].key not in commit1.name_rev
)
assert revisions[1].message == "commit1"
assert revisions[1].author_email == "author@example.com"
assert revisions[1].author_name == "An author"
assert (
# Write a test file to the repo
with open(tmppath / ".gitignore", "w") as ignore_f:
ignore_f.write(ignore)
index = repo.index
index.add([".gitignore"])
author = Actor("An author", "author@example.com")
committer = Actor("A committer", "committer@example.com")
index.commit("ignore python cache", author=author, committer=committer)
config = DEFAULT_CONFIG
config.path = tmpdir
archiver = GitArchiver(config)
assert archiver.config == config
def test_git_init(repo):
with patch("wily.archivers.git.Repo", return_value=repo):
test_config = wily.config.DEFAULT_CONFIG
test_config.path = repo.path
archiver = git.GitArchiver(test_config)
assert archiver.repo is not None
assert archiver.config == test_config
def test_git_revisions(repo, tmpdir):
with patch("wily.archivers.git.Repo", return_value=repo):
test_config = wily.config.DEFAULT_CONFIG
test_config.path = repo.path
archiver = git.GitArchiver(test_config)
revisions = archiver.revisions(tmpdir, 99)
assert archiver.repo is not None
assert archiver.config == test_config
assert revisions[0].key == "1234"
assert revisions[1].key == "1234"
assert revisions[0].author_name == "Mr Test"
author_email: str
date: str
message: str
files: List[str]
from wily.archivers.git import GitArchiver
from wily.archivers.filesystem import FilesystemArchiver
"""Type for an operator"""
Archiver = namedtuple("Archiver", "name cls description")
"""Git Operator defined in `wily.archivers.git`"""
ARCHIVER_GIT = Archiver(name="git", cls=GitArchiver, description="Git archiver")
"""Filesystem archiver"""
ARCHIVER_FILESYSTEM = Archiver(
name="filesystem", cls=FilesystemArchiver, description="Filesystem archiver"
)
"""Set of all available archivers"""
ALL_ARCHIVERS = {a.name: a for a in [ARCHIVER_GIT, ARCHIVER_FILESYSTEM]}
def resolve_archiver(name):
"""
Get the :class:`wily.archivers.Archiver` for a given name.
:param name: The name of the archiver
:type name: ``str``