def test_annotated_tag(self): with util.TemporaryGitDirectory() as repo: with open(os.path.join(repo, "asd.txt"), "w") as f: f.write("Hello") util.quiet_check_call(["git", "-C", repo, "add", "-A"]) util.quiet_check_call(["git", "-C", repo, "commit", "-m", "Test"]) loop.run_until_complete(repour.asgit.annotated_tag(expect_ok, repo, "pull-1234567890-root", "Annotation")) out = subprocess.check_output(["git", "-C", repo, "tag", "-l", "-n"]) self.assertIn(b"pull-1234567890-root Annotation", out)
def test_annotated_tag(self): with util.TemporaryGitDirectory() as repo: with open(os.path.join(repo, "asd.txt"), "w") as f: f.write("Hello") util.quiet_check_call(["git", "add", "-A"], cwd=repo) util.quiet_check_call(["git", "commit", "-m", "Test"], cwd=repo) loop.run_until_complete(repour.asgit.annotated_tag(expect_ok, repo, "pull-1234567890-root", "Annotation")) out = subprocess.check_output(["git", "tag", "-l", "-n"], cwd=repo) self.assertIn(b"pull-1234567890-root Annotation", out)
def test_fixed_date_commit(self): with util.TemporaryGitDirectory() as repo: with open(os.path.join(repo, "asd.txt"), "w") as f: f.write("Hello") util.quiet_check_call(["git", "add", "-A"], cwd=repo) loop.run_until_complete(repour.asgit.fixed_date_commit(expect_ok, repo, "Test")) out = subprocess.check_output(["git", "log", "-1", "--pretty=fuller"], cwd=repo) self.assertIn(b"AuthorDate: Thu Jan 1 00:00:00 1970 +0000", out) self.assertIn(b"CommitDate: Thu Jan 1 00:00:00 1970 +0000", out)
def test_fixed_date_commit(self): with util.TemporaryGitDirectory() as repo: with open(os.path.join(repo, "asd.txt"), "w") as f: f.write("Hello") util.quiet_check_call(["git", "-C", repo, "add", "-A"]) loop.run_until_complete(repour.asgit.fixed_date_commit(expect_ok, repo, "Test")) out = subprocess.check_output(["git", "-C", repo, "log", "-1", "--pretty=fuller"]) self.assertIn(b"AuthorDate: Thu Jan 1 00:00:00 1970 +0000", out) self.assertIn(b"CommitDate: Thu Jan 1 00:00:00 1970 +0000", out)
def test_prepare_new_branch(self): with util.TemporaryGitDirectory() as repo: with open(os.path.join(repo, "asd.txt"), "w") as f: f.write("Hello") loop.run_until_complete(repour.asgit.prepare_new_branch(expect_ok, repo, "pull-1234567890", orphan=True)) util.quiet_check_call(["git", "commit", "-m", "Test"], cwd=repo) with open(os.path.join(repo, "asd.txt"), "w") as f: f.write("Hello Hello") loop.run_until_complete(repour.asgit.prepare_new_branch(expect_ok, repo, "adjust-1234567890")) util.quiet_check_call(["git", "commit", "-m", "Test"], cwd=repo)
def test_prepare_new_branch(self): with util.TemporaryGitDirectory() as repo: with open(os.path.join(repo, "asd.txt"), "w") as f: f.write("Hello") loop.run_until_complete(repour.asgit.prepare_new_branch(expect_ok, repo, "pull-1234567890", orphan=True)) util.quiet_check_call(["git", "-C", repo, "commit", "-m", "Test"]) with open(os.path.join(repo, "asd.txt"), "w") as f: f.write("Hello Hello") loop.run_until_complete(repour.asgit.prepare_new_branch(expect_ok, repo, "adjust-1234567890")) util.quiet_check_call(["git", "-C", repo, "commit", "-m", "Test"])
def setUpClass(cls): # Dummy git origin cls.origin_git_cls = util.TemporaryGitDirectory() cls.origin_git = cls.origin_git_cls.__enter__() with open(os.path.join(cls.origin_git, "asd.txt"), "w") as f: f.write("Origin") util.quiet_check_call(["git", "-C", cls.origin_git, "add", "-A"]) util.quiet_check_call(["git", "-C", cls.origin_git, "commit", "-m", "Some origin commit"]) cls.origin_git = "file://" + cls.origin_git # Dummy archive origin tar_buf = io.BytesIO() with tarfile.open(fileobj=tar_buf, mode="w:xz") as t: i = tarfile.TarInfo("asd.txt") b = io.BytesIO(b"Hello\n") b.seek(0, io.SEEK_END) i.size = b.tell() b.seek(0) t.addfile(i, b) # Dummy archive origin (with single root dir) srd_tar_buf = io.BytesIO() with tarfile.open(fileobj=srd_tar_buf, mode="w:xz") as t: i = tarfile.TarInfo("srd/asd.txt") b = io.BytesIO(b"Hello\n") b.seek(0, io.SEEK_END) i.size = b.tell() b.seek(0) t.addfile(i, b) util.setup_http( cls=cls, loop=loop, routes=[ ("GET", "/test.tar.xz", util.http_write_handler(tar_buf)), ("GET", "/srd_test.tar.xz", util.http_write_handler(srd_tar_buf)), ], )
def test_push_with_tags(self): with util.TemporaryGitDirectory(bare=True) as remote: with util.TemporaryGitDirectory(origin=remote) as repo: with open(os.path.join(repo, "asd.txt"), "w") as f: f.write("Goodbye") util.quiet_check_call(["git", "add", "-A"], cwd=repo) util.quiet_check_call(["git", "commit", "-m", "Test Commit"], cwd=repo) util.quiet_check_call(["git", "tag", "test-tag"], cwd=repo) loop.run_until_complete(repour.asgit.push_with_tags(expect_ok, repo, "master")) remote_tags = subprocess.check_output(["git", "tag", "-l", "-n"], cwd=repo) self.assertIn(b"test-tag Test Commit", remote_tags)
def test_push_with_tags(self): with util.TemporaryGitDirectory(bare=True) as remote: with util.TemporaryGitDirectory(origin=remote) as repo: with open(os.path.join(repo, "asd.txt"), "w") as f: f.write("Goodbye") util.quiet_check_call(["git", "-C", repo, "add", "-A"]) util.quiet_check_call(["git", "-C", repo, "commit", "-m", "Test Commit"]) util.quiet_check_call(["git", "-C", repo, "tag", "test-tag"]) loop.run_until_complete(repour.asgit.push_with_tags(expect_ok, repo, "master")) remote_tags = subprocess.check_output(["git", "-C", repo, "tag", "-l", "-n"]) self.assertIn(b"test-tag Test Commit", remote_tags)
def setUpClass(cls): # Dummy git origin cls.origin_git_cls = util.TemporaryGitDirectory(ro_url="fake-ro-url") cls.origin_git = cls.origin_git_cls.__enter__() with open(os.path.join(cls.origin_git.readwrite, "asd.txt"), "w") as f: f.write("Hello") util.quiet_check_call(["git", "-C", cls.origin_git.readwrite, "add", "-A"]) util.quiet_check_call(["git", "-C", cls.origin_git.readwrite, "commit", "-m", "Pull"]) # Convert to bare os.remove(os.path.join(cls.origin_git.readwrite, "asd.txt")) git_dir = os.path.join(cls.origin_git.readwrite, ".git") for fn in os.listdir(git_dir): shutil.move(os.path.join(git_dir, fn), cls.origin_git.readwrite) os.rmdir(git_dir) util.quiet_check_call(["git", "-C", cls.origin_git.readwrite, "config", "--bool", "core.bare", "true"])