-- -- --- --- --- --- --- --- ------- ------- ------- |
import pathlib
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
import pytest
-- -- --- --- --- --- --- --- ------- ------- ------- |
from git.repo.base import Repo
-- -- --- --- --- --- --- --- ------- ------- ------- |
from git.util import Actor
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.archivers.git import DirtyGitRepositoryError, GitArchiver
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.config import DEFAULT_CONFIG
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
def test_git_end_to_end(tmpdir):
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
"""
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
Complete end-to-end test of the git integration
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
"""
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
repo = Repo.init(path=tmpdir)
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
tmppath = pathlib.Path(tmpdir)
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
index = repo.index
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
author = Actor("An author", "author@example.com")
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
committer = Actor("A committer", "committer@example.com")
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
# First commit
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
with open(tmppath / ".gitignore", "w") as ignore:
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
ignore.write(".wily/")
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
index.add([".gitignore"])
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
commit1 = index.commit("commit1", author=author, committer=committer)
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
# Second commit
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
with open(tmppath / "test.py", "w") as file1:
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
file1.write("print(1)")
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
index.add(["test.py"])
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
commit2 = index.commit("commit2", author=author, committer=committer)
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
repo.close()
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
config = DEFAULT_CONFIG
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
config.path = tmpdir
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
archiver = GitArchiver(config)
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
assert archiver.config == config
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
revisions = archiver.revisions(tmpdir, 3)
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
assert len(revisions) == 2
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
assert revisions[0].message == "commit2"
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
assert revisions[0].author_email == "author@example.com"
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
assert revisions[0].author_name == "An author"
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
assert (
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
revisions[0].key in commit2.name_rev
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
and revisions[0].key not in commit1.name_rev
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
)
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
assert revisions[1].message == "commit1"
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
assert revisions[1].author_email == "author@example.com"
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
assert revisions[1].author_name == "An author"
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
assert (
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
revisions[1].key in commit1.name_rev
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
and revisions[1].key not in commit2.name_rev
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
)
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
checkout = archiver.checkout(revisions[1], None)
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
assert not (tmppath / "test.py").exists()
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
finish = archiver.finish()
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
-- -- 006 020 019 037 026 056 0263.22 1460.90 0005.55 |
assert (tmppath / "test.py").exists()
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
def test_dirty_git(tmpdir):
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
"""Check that repository fails to initialise if unchecked files are in the repo"""
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
repo = Repo.init(path=tmpdir)
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
tmppath = pathlib.Path(tmpdir)
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
index = repo.index
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
author = Actor("An author", "author@example.com")
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
committer = Actor("A committer", "committer@example.com")
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
# First commit
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
with open(tmppath / ".gitignore", "w") as ignore:
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
ignore.write(".wily/")
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
index.add([".gitignore"])
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
commit1 = index.commit("commit1", author=author, committer=committer)
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
# Write a test file to the repo
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
with open(tmppath / "blah.py", "w") as ignore:
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
ignore.write("*.py[co]\n")
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
index.add(["blah.py"])
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
repo.close()
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
config = DEFAULT_CONFIG
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
config.path = tmpdir
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
with pytest.raises(DirtyGitRepositoryError):
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
archiver = GitArchiver(config)
-- 01 001 003 002 004 004 006 0012.00 0008.00 0000.67 |
archiver.revisions(tmpdir, 2)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
def test_detached_head(tmpdir):
-- -- 002 004 003 006 006 009 0023.26 0034.90 0001.50 |
"""Check that repo can initialize in detached head state"""
-- -- --- --- --- --- --- --- ------- ------- ------- |
repo = Repo.init(path=tmpdir)
-- -- --- --- --- --- --- --- ------- ------- ------- |
tmppath = pathlib.Path(tmpdir)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
index = repo.index
-- -- --- --- --- --- --- --- ------- ------- ------- |
author = Actor("An author", "author@example.com")
-- -- --- --- --- --- --- --- ------- ------- ------- |
committer = Actor("A committer", "committer@example.com")
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
# First commit
-- -- --- --- --- --- --- --- ------- ------- ------- |
with open(tmppath / "test.py", "w") as ignore:
-- -- --- --- --- --- --- --- ------- ------- ------- |
ignore.write("print('hello world')")
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
index.add(["test.py"])
-- -- --- --- --- --- --- --- ------- ------- ------- |
commit1 = index.commit("commit1", author=author, committer=committer)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
# Second commit
-- -- --- --- --- --- --- --- ------- ------- ------- |
with open(tmppath / "test.py", "w") as ignore:
-- -- --- --- --- --- --- --- ------- ------- ------- |
ignore.write("print('hello world')\nprint(1)")
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
index.add(["test.py"])
-- -- --- --- --- --- --- --- ------- ------- ------- |
commit2 = index.commit("commit2", author=author, committer=committer)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
repo.git.checkout(commit2.hexsha)
-- -- --- --- --- --- --- --- ------- ------- ------- |
repo.close()
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
config = DEFAULT_CONFIG
-- -- --- --- --- --- --- --- ------- ------- ------- |
config.path = tmpdir
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
archiver = GitArchiver(config)
-- -- --- --- --- --- --- --- ------- ------- ------- |
assert archiver.revisions(tmpdir, 1) is not None