示例#1
0
    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)
示例#2
0
    def test_no_adjust(self):
        with util.TemporaryGitDirectory(bare=True, ro_url="fake-ro-url") as remote:
            with tempfile.TemporaryDirectory() as repo:
                with open(os.path.join(repo, "asd.txt"), "w") as f:
                    f.write("Hello")

                @asyncio.coroutine
                def repo_provider(p):
                    return remote

                d = loop.run_until_complete(repour.pull.process_source_tree(
                    pullspec={
                        "name": "test",
                        "type": "git",
                        "ref": "v1.0",
                        "url": "git://example.com",
                        "adjust": False,
                    },
                    repo_provider=repo_provider,
                    adjust_provider=None,
                    repo_dir=repo,
                    origin_type="git",
                    origin_ref="v1.0",
                ))

                self.assertRegex(d["branch"], r'^branch-pull-[0-9a-f]+$')
                self.assertRegex(d["tag"], r'^repour-[0-9a-f]+$')
示例#3
0
    def test_archive(self):
        with util.TemporaryGitDirectory(bare=True, ro_url="fake-ro-url") as remote:
            with tempfile.TemporaryDirectory() as repo:
                @asyncio.coroutine
                def adjust(d):
                    return "test"

                @asyncio.coroutine
                def repo_provider(p):
                    return remote

                d = loop.run_until_complete(repour.pull.pull(
                    pullspec={
                        "name": "test",
                        "type": "archive",
                        "url": self.url + "/test.tar.xz",
                    },
                    repo_provider=repo_provider,
                    adjust_provider=adjust,
                ))
                self.assertIsInstance(d, dict)

                new_d = loop.run_until_complete(repour.pull.pull(
                    pullspec={
                        "name": "test",
                        "type": "archive",
                        "url": self.url + "/srd_test.tar.xz",
                    },
                    repo_provider=repo_provider,
                    adjust_provider=adjust,
                ))
                # Single root directory should be shucked, resulting in deduplication
                self.assertEqual(d, new_d)
示例#4
0
    def test_setup_commiter(self):
        with util.TemporaryGitDirectory() as repo:
            loop.run_until_complete(repour.asgit.setup_commiter(expect_ok, repo))
            out = subprocess.check_output(["git", "-C", repo, "config", "--local", "-l"])

        self.assertIn(b"user.name=", out)
        self.assertIn(b"user.email=", out)
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
    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"])
示例#8
0
 def test_to_internal(self):
     with util.TemporaryGitDirectory(bare=True, ro_url="fake-ro-url") as remote:
         with tempfile.TemporaryDirectory() as repo:
             with open(os.path.join(repo, "asd.txt"), "w") as f:
                 f.write("Hello")
             d = loop.run_until_complete(repour.pull.to_internal(
                 internal_repo_url=remote,
                 dirname=repo,
                 origin_ref="v1.0",
                 origin_url="git://example.com/repo",
                 origin_type="git",
             ))
             self.assertIsInstance(d, dict)
         out = subprocess.check_output(["git", "-C", remote.readwrite, "tag", "-l", "-n5"])
         self.assertIn(b"""Origin: git://example.com/repo
 Reference: v1.0
 Type: git""", out)
示例#9
0
    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)),
            ],
        )
示例#10
0
    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"])
示例#11
0
    def test_with_adjust(self):
        with util.TemporaryGitDirectory(bare=True, ro_url="fake-ro-url") as remote:
            with tempfile.TemporaryDirectory() as repo:
                with open(os.path.join(repo, "asd.txt"), "w") as f:
                    f.write("Hello")

                @asyncio.coroutine
                def adjust(d):
                    with open(os.path.join(repo, "asd.txt"), "w") as f:
                        f.write("Hello Hello")
                    return "test"

                @asyncio.coroutine
                def repo_provider(p):
                    return remote

                d = loop.run_until_complete(repour.pull.process_source_tree(
                    pullspec={
                        "name": "test",
                        "type": "git",
                        "ref": "v1.0",
                        "url": "git://example.com",
                        "adjust": True,
                    },
                    repo_provider=repo_provider,
                    adjust_provider=adjust,
                    repo_dir=repo,
                    origin_type="git",
                    origin_ref="v1.0",
                ))

                self.assertRegex(d["branch"], r'^branch-adjust-[0-9a-f]+$')
                self.assertRegex(d["tag"], r'^repour-[0-9a-f]+$')
                self.assertRegex(d["pull"]["branch"], r'^branch-pull-[0-9a-f]+$')
                self.assertRegex(d["pull"]["tag"], r'^repour-[0-9a-f]+$')

                # Verify adjust commit is child of pull commit
                out = subprocess.check_output(["git", "-C", remote.readwrite, "rev-list", "--parents", "-n1", d["tag"]])
                adjust_commit, adjust_parent = out.decode("utf-8").strip().split(" ")
                out = subprocess.check_output(["git", "-C", remote.readwrite, "rev-list", "-n1", d["pull"]["tag"]])
                pull_commit = out.decode("utf-8").strip()

                self.assertEqual(adjust_parent, pull_commit)
                self.assertNotEqual(adjust_commit, pull_commit)
示例#12
0
    def test_hg(self):
        with util.TemporaryGitDirectory(bare=True, ro_url="fake-ro-url") as remote:
            with util.TemporaryHgDirectory(add_commit=True) as origin_hg:
                @asyncio.coroutine
                def adjust(d):
                    return "test"

                @asyncio.coroutine
                def repo_provider(p):
                    return remote

                d = loop.run_until_complete(repour.pull.pull(
                    pullspec={
                        "name": "test",
                        "type": "hg",
                        "ref": "tip",
                        "url": origin_hg,
                    },
                    repo_provider=repo_provider,
                    adjust_provider=adjust,
                ))
                self.assertIsInstance(d, dict)
示例#13
0
    def test_git(self):
        with util.TemporaryGitDirectory(bare=True, ro_url="fake-ro-url") as remote:
            with tempfile.TemporaryDirectory() as repo:
                @asyncio.coroutine
                def adjust(d):
                    return "test"

                @asyncio.coroutine
                def repo_provider(p):
                    return remote

                d_shallow = loop.run_until_complete(repour.pull.pull(
                    pullspec={
                        "name": "test",
                        "type": "git",
                        "ref": "master",
                        "url": self.origin_git,
                    },
                    repo_provider=repo_provider,
                    adjust_provider=adjust,
                ))
                self.assertIsInstance(d_shallow, dict)

                d_deep = loop.run_until_complete(repour.pull.pull(
                    pullspec={
                        "name": "test",
                        "type": "git",
                        # Use HEAD here, normally would expect this to be a
                        # commit id, but does the same thing of triggering deep
                        # clone.
                        "ref": "HEAD",
                        "url": self.origin_git,
                    },
                    repo_provider=repo_provider,
                    adjust_provider=adjust,
                ))
                # Deduplication should be activated
                self.assertEqual(d_deep, d_shallow)
示例#14
0
    def test_normal(self):
        with util.TemporaryGitDirectory(bare=True,
                                        ro_url="fake-ro-url") as remote:

            tag = None

            with util.TemporaryGitDirectory(origin=remote.readwrite) as repo:
                # Simulated pull
                with open(os.path.join(repo, "asd.txt"), "w") as f:
                    f.write("Hello")
                p = loop.run_until_complete(
                    asgit.push_new_dedup_branch(
                        expect_ok=expect_ok,
                        repo_dir=repo,
                        repo_url=remote,
                        operation_name="Pull",
                        operation_description="Blah",
                        orphan=True,
                        real_commit_time=True,
                    ))
                self.assertEqual(p["url"]["readwrite"], remote.readwrite)
                self.assertEqual(p["url"]["readonly"], "fake-ro-url")

                tag = p["tag"]

                time.sleep(2)

                # No changes
                nc = loop.run_until_complete(
                    asgit.push_new_dedup_branch(
                        expect_ok=expect_ok,
                        repo_dir=repo,
                        repo_url=remote,
                        operation_name="Adjust",
                        operation_description="Bleh",
                        no_change_ok=True,
                        force_continue_on_no_changes=True,
                        real_commit_time=True,
                    ))

            with util.TemporaryGitDirectory(origin=remote.readwrite,
                                            ref=tag) as repo:
                # Changes
                with open(os.path.join(repo, "asd.txt"), "w") as f:
                    f.write("Hello Hello")
                c = loop.run_until_complete(
                    asgit.push_new_dedup_branch(
                        expect_ok=expect_ok,
                        repo_dir=repo,
                        repo_url=remote,
                        operation_name="Adjust",
                        operation_description="Bleh",
                        no_change_ok=True,
                        force_continue_on_no_changes=True,
                        real_commit_time=True,
                    ))
                self.assertIsNotNone(c)
                self.assertIn("tag", c)
                self.assertIn("repour", c["tag"])
                self.assertIn("url", c)
                self.assertEqual(remote.readwrite, c["url"]["readwrite"])
                self.assertEqual("fake-ro-url", c["url"]["readonly"])

            with util.TemporaryGitDirectory(origin=remote.readwrite,
                                            ref=tag) as repo:
                # Changes, already existing
                # Sleep to make sure commit date are different, if duplicate commit generated
                time.sleep(5)
                with open(os.path.join(repo, "asd.txt"), "w") as f:
                    f.write("Hello Hello")
                ce = loop.run_until_complete(
                    asgit.push_new_dedup_branch(
                        expect_ok=expect_ok,
                        repo_dir=repo,
                        repo_url=remote,
                        operation_name="Adjust",
                        operation_description="Bleh",
                        no_change_ok=True,
                        force_continue_on_no_changes=True,
                        real_commit_time=True,
                    ))
                self.assertIsNotNone(ce)
                self.assertEqual(ce, c)
示例#15
0
    def test_normal(self):
        with util.TemporaryGitDirectory(bare=True, ro_url="fake-ro-url") as remote:
            with util.TemporaryGitDirectory(origin=remote.readwrite) as repo:
                # Simulated pull
                with open(os.path.join(repo, "asd.txt"), "w") as f:
                    f.write("Hello")
                p = loop.run_until_complete(repour.asgit.push_new_dedup_branch(
                    expect_ok=expect_ok,
                    repo_dir=repo,
                    repo_url=remote,
                    operation_name="Pull",
                    operation_description="Blah",
                    orphan=True,
                ))
                self.assertEqual(
                    first=p,
                    second={
                        "branch": "branch-pull-0fe965e93b0cf7c91b9d44c14d9847e459c465c2",
                        "tag": "repour-0fe965e93b0cf7c91b9d44c14d9847e459c465c2",
                        "url": {
                            "readwrite": remote.readwrite,
                            "readonly": "fake-ro-url",
                        },
                    },
                )

                # No changes
                nc = loop.run_until_complete(repour.asgit.push_new_dedup_branch(
                    expect_ok=expect_ok,
                    repo_dir=repo,
                    repo_url=remote,
                    operation_name="Adjust",
                    operation_description="Bleh",
                    no_change_ok=True,
                ))
                self.assertIsNone(nc)

            with util.TemporaryGitDirectory(
                origin=remote.readwrite,
                ref="repour-0fe965e93b0cf7c91b9d44c14d9847e459c465c2",
            ) as repo:
                # Changes
                with open(os.path.join(repo, "asd.txt"), "w") as f:
                    f.write("Hello Hello")
                c = loop.run_until_complete(repour.asgit.push_new_dedup_branch(
                    expect_ok=expect_ok,
                    repo_dir=repo,
                    repo_url=remote,
                    operation_name="Adjust",
                    operation_description="Bleh",
                    no_change_ok=True,
                ))
                self.assertIsNotNone(c)
                self.assertIn("branch", c)
                self.assertIn("adjust", c["branch"])
                self.assertIn("tag", c)
                self.assertIn("repour", c["tag"])
                self.assertIn("url", c)
                self.assertEqual(remote.readwrite, c["url"]["readwrite"])
                self.assertEqual("fake-ro-url", c["url"]["readonly"])

            with util.TemporaryGitDirectory(
                origin=remote.readwrite,
                ref="repour-0fe965e93b0cf7c91b9d44c14d9847e459c465c2",
            ) as repo:
                # Changes, already existing
                with open(os.path.join(repo, "asd.txt"), "w") as f:
                    f.write("Hello Hello")
                ce = loop.run_until_complete(repour.asgit.push_new_dedup_branch(
                    expect_ok=expect_ok,
                    repo_dir=repo,
                    repo_url=remote,
                    operation_name="Adjust",
                    operation_description="Bleh",
                    no_change_ok=True,
                ))
                self.assertIsNotNone(ce)
                self.assertEqual(ce, c)

            with util.TemporaryGitDirectory(
                origin=remote.readwrite,
                ref="branch-adjust-121fe90b54a7701c314a16bf2a1ede63243e1fa7",
            ) as repo:
                # No changes
                nca = loop.run_until_complete(repour.asgit.push_new_dedup_branch(
                    expect_ok=expect_ok,
                    repo_dir=repo,
                    repo_url=remote,
                    operation_name="Adjust",
                    operation_description="Bleh",
                    no_change_ok=True,
                ))
                self.assertIsNone(nca)