コード例 #1
0
    def test_creation_and_removal(self, bare_rw_repo):
        new_name = "test_new_one"
        arg_list = (new_name, "git@server:hello.git")
        remote = Remote.create(bare_rw_repo, *arg_list)
        self.assertEqual(remote.name, "test_new_one")
        self.assertIn(remote, bare_rw_repo.remotes)
        self.assertTrue(remote.exists())

        # create same one again
        self.failUnlessRaises(GitCommandError, Remote.create, bare_rw_repo,
                              *arg_list)

        Remote.remove(bare_rw_repo, new_name)
        self.assertTrue(remote.exists(
        ))  # We still have a cache that doesn't know we were deleted by name
        remote._clear_cache()
        assert not remote.exists(
        )  # Cache should be renewed now. This is an issue ...

        for remote in bare_rw_repo.remotes:
            if remote.name == new_name:
                raise AssertionError("Remote removal failed")
            # END if deleted remote matches existing remote's name
        # END for each remote

        # Issue #262 - the next call would fail if bug wasn't fixed
        bare_rw_repo.create_remote('bogus', '/bogus/path', mirror='push')
コード例 #2
0
ファイル: helper.py プロジェクト: andy-maier/GitPython
        def remote_repo_creator(self):
            rw_daemon_repo_dir = tempfile.mktemp(prefix="daemon_repo-%s-" % func.__name__)
            rw_repo_dir = tempfile.mktemp(prefix="daemon_cloned_repo-%s-" % func.__name__)

            rw_daemon_repo = self.rorepo.clone(rw_daemon_repo_dir, shared=True, bare=True)
            # recursive alternates info ?
            rw_repo = rw_daemon_repo.clone(rw_repo_dir, shared=True, bare=False, n=True)
            try:
                rw_repo.head.commit = working_tree_ref
                rw_repo.head.reference.checkout()

                # prepare for git-daemon
                rw_daemon_repo.daemon_export = True

                # this thing is just annoying !
                with rw_daemon_repo.config_writer() as crw:
                    section = "daemon"
                    try:
                        crw.add_section(section)
                    except Exception:
                        pass
                    crw.set(section, "receivepack", True)

                # Initialize the remote - first do it as local remote and pull, then
                # we change the url to point to the daemon.
                d_remote = Remote.create(rw_repo, "daemon_origin", rw_daemon_repo_dir)
                d_remote.fetch()

                base_daemon_path, rel_repo_dir = osp.split(rw_daemon_repo_dir)

                remote_repo_url = Git.polish_url("git://localhost:%s/%s" % (GIT_DAEMON_PORT, rel_repo_dir))
                with d_remote.config_writer as cw:
                    cw.set('url', remote_repo_url)

                with git_daemon_launched(Git.polish_url(base_daemon_path, is_cygwin=False),  # No daemon in Cygwin.
                                         '127.0.0.1',
                                         GIT_DAEMON_PORT):
                    # Try listing remotes, to diagnose whether the daemon is up.
                    rw_repo.git.ls_remote(d_remote)

                    with cwd(rw_repo.working_dir):
                        try:
                            return func(self, rw_repo, rw_daemon_repo)
                        except:
                            log.info("Keeping repos after failure: \n  rw_repo_dir: %s \n  rw_daemon_repo_dir: %s",
                                     rw_repo_dir, rw_daemon_repo_dir)
                            rw_repo_dir = rw_daemon_repo_dir = None
                            raise

            finally:
                rw_repo.git.clear_cache()
                rw_daemon_repo.git.clear_cache()
                del rw_repo
                del rw_daemon_repo
                import gc
                gc.collect()
                if rw_repo_dir:
                    rmtree(rw_repo_dir)
                if rw_daemon_repo_dir:
                    rmtree(rw_daemon_repo_dir)
コード例 #3
0
        def remote_repo_creator(self):
            remote_repo_dir = tempfile.mktemp("remote_repo_%s" % func.__name__)
            repo_dir = tempfile.mktemp("remote_clone_non_bare_repo")

            rw_remote_repo = self.rorepo.clone(remote_repo_dir,
                                               shared=True,
                                               bare=True)
            rw_repo = rw_remote_repo.clone(
                repo_dir, shared=True, bare=False,
                n=True)  # recursive alternates info ?
            rw_repo.head.commit = working_tree_ref
            rw_repo.head.reference.checkout()

            # prepare for git-daemon
            rw_remote_repo.daemon_export = True

            # this thing is just annoying !
            crw = rw_remote_repo.config_writer()
            section = "daemon"
            try:
                crw.add_section(section)
            except Exception:
                pass
            crw.set(section, "receivepack", True)
            # release lock
            del (crw)

            # initialize the remote - first do it as local remote and pull, then
            # we change the url to point to the daemon. The daemon should be started
            # by the user, not by us
            d_remote = Remote.create(rw_repo, "daemon_origin", remote_repo_dir)
            d_remote.fetch()
            remote_repo_url = "git://localhost%s" % remote_repo_dir

            # some oddity: on windows, python 2.5, it for some reason does not realize
            # that it has the config_writer property, but instead calls __getattr__
            # which will not yield the expected results. 'pinging' the members
            # with a dir call creates the config_writer property that we require
            # ... bugs like these make me wonder wheter python really wants to be used
            # for production. It doesn't happen on linux though.
            dir(d_remote)
            d_remote.config_writer.set('url', remote_repo_url)

            # try to list remotes to diagnoes whether the server is up
            try:
                rw_repo.git.ls_remote(d_remote)
            except GitCommandError, e:
                print str(e)
                if os.name == 'nt':
                    raise AssertionError(
                        'git-daemon needs to run this test, but windows does not have one. Otherwise, run: git-daemon "%s"'
                        % tempfile.gettempdir())
                else:
                    raise AssertionError(
                        'Please start a git-daemon to run this test, execute: git-daemon "%s"'
                        % tempfile.gettempdir())
コード例 #4
0
ファイル: pr_test.py プロジェクト: lsst-sqre/neophile
async def test_get_github_repo(tmp_path: Path, session: ClientSession) -> None:
    repo = Repo.init(str(tmp_path))

    config = Configuration(github_user="******", github_token="some-token")
    pr = PullRequester(tmp_path, config, session)

    remote = Remote.create(repo, "origin", "[email protected]:foo/bar.git")
    assert pr._get_github_repo() == GitHubRepository(owner="foo", repo="bar")

    remote.set_url("https://github.com/foo/bar.git")
    assert pr._get_github_repo() == GitHubRepository(owner="foo", repo="bar")

    remote.set_url("ssh://[email protected]/foo/bar")
    assert pr._get_github_repo() == GitHubRepository(owner="foo", repo="bar")
コード例 #5
0
ファイル: helper.py プロジェクト: devs1991/test_edx_docmode
        def remote_repo_creator(self):
            remote_repo_dir = _mktemp("remote_repo_%s" % func.__name__)
            repo_dir = _mktemp("remote_clone_non_bare_repo")

            rw_remote_repo = self.rorepo.clone(remote_repo_dir,
                                               shared=True,
                                               bare=True)
            rw_repo = rw_remote_repo.clone(
                repo_dir, shared=True, bare=False,
                n=True)  # recursive alternates info ?
            rw_repo.head.commit = working_tree_ref
            rw_repo.head.reference.checkout()

            # prepare for git-daemon
            rw_remote_repo.daemon_export = True

            # this thing is just annoying !
            crw = rw_remote_repo.config_writer()
            section = "daemon"
            try:
                crw.add_section(section)
            except Exception:
                pass
            crw.set(section, "receivepack", True)
            # release lock
            del (crw)

            # initialize the remote - first do it as local remote and pull, then
            # we change the url to point to the daemon. The daemon should be started
            # by the user, not by us
            d_remote = Remote.create(rw_repo, "daemon_origin", remote_repo_dir)
            d_remote.fetch()
            remote_repo_url = "git://localhost%s" % remote_repo_dir

            d_remote.config_writer.set('url', remote_repo_url)

            # try to list remotes to diagnoes whether the server is up
            try:
                rw_repo.git.ls_remote(d_remote)
            except GitCommandError, e:
                print str(e)
                if os.name == 'nt':
                    raise AssertionError(
                        'git-daemon needs to run this test, but windows does not have one. Otherwise, run: git-daemon "%s"'
                        % os.path.dirname(_mktemp()))
                else:
                    raise AssertionError(
                        'Please start a git-daemon to run this test, execute: git-daemon "%s"'
                        % os.path.dirname(_mktemp()))
コード例 #6
0
		def remote_repo_creator(self):
			remote_repo_dir = tempfile.mktemp("remote_repo_%s" % func.__name__)
			repo_dir = tempfile.mktemp("remote_clone_non_bare_repo")
			
			rw_remote_repo = self.rorepo.clone(remote_repo_dir, shared=True, bare=True)
			rw_repo = rw_remote_repo.clone(repo_dir, shared=True, bare=False, n=True)		# recursive alternates info ?
			rw_repo.head.commit = working_tree_ref
			rw_repo.head.reference.checkout()
			
			# prepare for git-daemon
			rw_remote_repo.daemon_export = True
			
			# this thing is just annoying !
			crw = rw_remote_repo.config_writer()
			section = "daemon"
			try:
				crw.add_section(section)
			except Exception:
				pass
			crw.set(section, "receivepack", True)
			# release lock
			del(crw)
			
			# initialize the remote - first do it as local remote and pull, then 
			# we change the url to point to the daemon. The daemon should be started
			# by the user, not by us
			d_remote = Remote.create(rw_repo, "daemon_origin", remote_repo_dir)
			d_remote.fetch()
			remote_repo_url = "git://localhost%s" % remote_repo_dir
			
			# some oddity: on windows, python 2.5, it for some reason does not realize
			# that it has the config_writer property, but instead calls __getattr__
			# which will not yield the expected results. 'pinging' the members
			# with a dir call creates the config_writer property that we require 
			# ... bugs like these make me wonder wheter python really wants to be used
			# for production. It doesn't happen on linux though.
			dir(d_remote)
			d_remote.config_writer.set('url', remote_repo_url)
			
			# try to list remotes to diagnoes whether the server is up
			try:
				rw_repo.git.ls_remote(d_remote)
			except GitCommandError,e:
				print str(e)
				if os.name == 'nt':
					raise AssertionError('git-daemon needs to run this test, but windows does not have one. Otherwise, run: git-daemon "%s"'%tempfile.gettempdir()) 
				else:
					raise AssertionError('Please start a git-daemon to run this test, execute: git-daemon "%s"'%tempfile.gettempdir())
コード例 #7
0
ファイル: helper.py プロジェクト: CrypticGator/rmtoo
        def remote_repo_creator(self):
            remote_repo_dir = _mktemp("remote_repo_%s" % func.__name__)
            repo_dir = _mktemp("remote_clone_non_bare_repo")

            rw_remote_repo = self.rorepo.clone(remote_repo_dir, shared=True, bare=True)
            rw_repo = rw_remote_repo.clone(repo_dir, shared=True, bare=False, n=True)  # recursive alternates info ?
            rw_repo.head.commit = working_tree_ref
            rw_repo.head.reference.checkout()

            # prepare for git-daemon
            rw_remote_repo.daemon_export = True

            # this thing is just annoying !
            crw = rw_remote_repo.config_writer()
            section = "daemon"
            try:
                crw.add_section(section)
            except Exception:
                pass
            crw.set(section, "receivepack", True)
            # release lock
            del (crw)

            # initialize the remote - first do it as local remote and pull, then
            # we change the url to point to the daemon. The daemon should be started
            # by the user, not by us
            d_remote = Remote.create(rw_repo, "daemon_origin", remote_repo_dir)
            d_remote.fetch()
            remote_repo_url = "git://localhost%s" % remote_repo_dir

            d_remote.config_writer.set("url", remote_repo_url)

            # try to list remotes to diagnoes whether the server is up
            try:
                rw_repo.git.ls_remote(d_remote)
            except GitCommandError, e:
                print str(e)
                if os.name == "nt":
                    raise AssertionError(
                        'git-daemon needs to run this test, but windows does not have one. Otherwise, run: git-daemon "%s"'
                        % os.path.dirname(_mktemp())
                    )
                else:
                    raise AssertionError(
                        'Please start a git-daemon to run this test, execute: git-daemon "%s"'
                        % os.path.dirname(_mktemp())
                    )
コード例 #8
0
ファイル: test_remote.py プロジェクト: ankurshr01/django_blog
    def test_creation_and_removal(self, bare_rw_repo):
        new_name = "test_new_one"
        arg_list = (new_name, "git@server:hello.git")
        remote = Remote.create(bare_rw_repo, *arg_list)
        assert remote.name == "test_new_one"
        assert remote in bare_rw_repo.remotes
        assert remote.exists()

        # create same one again
        self.failUnlessRaises(GitCommandError, Remote.create, bare_rw_repo, *arg_list)

        Remote.remove(bare_rw_repo, new_name)
        assert remote.exists()      # We still have a cache that doesn't know we were deleted by name
        remote._clear_cache()
        assert not remote.exists()  # Cache should be renewed now. This is an issue ...

        for remote in bare_rw_repo.remotes:
            if remote.name == new_name:
                raise AssertionError("Remote removal failed")
コード例 #9
0
ファイル: test_remote.py プロジェクト: yarikoptic/GitPython
    def test_creation_and_removal(self, bare_rw_repo):
        new_name = "test_new_one"
        arg_list = (new_name, "git@server:hello.git")
        remote = Remote.create(bare_rw_repo, *arg_list)
        assert remote.name == "test_new_one"
        assert remote in bare_rw_repo.remotes
        assert remote.exists()

        # create same one again
        self.failUnlessRaises(GitCommandError, Remote.create, bare_rw_repo, *arg_list)

        Remote.remove(bare_rw_repo, new_name)
        assert remote.exists()      # We still have a cache that doesn't know we were deleted by name
        remote._clear_cache()
        assert not remote.exists()  # Cache should be renewed now. This is an issue ...

        for remote in bare_rw_repo.remotes:
            if remote.name == new_name:
                raise AssertionError("Remote removal failed")
コード例 #10
0
ファイル: pr_test.py プロジェクト: lsst-sqre/neophile
async def test_get_authenticated_remote(tmp_path: Path,
                                        session: ClientSession) -> None:
    repo = Repo.init(str(tmp_path))

    config = Configuration(github_user="******", github_token="some-token")
    pr = PullRequester(tmp_path, config, session)

    remote = Remote.create(repo, "origin", "https://github.com/foo/bar")
    url = pr._get_authenticated_remote()
    assert url == "https://*****:*****@github.com/foo/bar"

    remote.set_url("https://[email protected]:8080/foo/bar")
    url = pr._get_authenticated_remote()
    assert url == "https://*****:*****@github.com:8080/foo/bar"

    remote.set_url("[email protected]:bar/foo")
    url = pr._get_authenticated_remote()
    assert url == "https://*****:*****@github.com/bar/foo"

    remote.set_url("ssh://*****:*****@github.com/baz/stuff")
    url = pr._get_authenticated_remote()
    assert url == "https://*****:*****@github.com/baz/stuff"
コード例 #11
0
ファイル: test_remote.py プロジェクト: ChannyAzar/GitPython
    def test_creation_and_removal(self, bare_rw_repo):
        new_name = "test_new_one"
        arg_list = (new_name, "git@server:hello.git")
        remote = Remote.create(bare_rw_repo, *arg_list)
        assert remote.name == "test_new_one"
        assert remote in bare_rw_repo.remotes
        assert remote.exists()

        # create same one again
        self.failUnlessRaises(GitCommandError, Remote.create, bare_rw_repo, *arg_list)

        Remote.remove(bare_rw_repo, new_name)
        assert remote.exists()      # We still have a cache that doesn't know we were deleted by name
        remote._clear_cache()
        assert not remote.exists()  # Cache should be renewed now. This is an issue ...

        for remote in bare_rw_repo.remotes:
            if remote.name == new_name:
                raise AssertionError("Remote removal failed")
            # END if deleted remote matches existing remote's name
        # END for each remote

        # Issue #262 - the next call would fail if bug wasn't fixed
        bare_rw_repo.create_remote('bogus', '/bogus/path', mirror='push')
コード例 #12
0
ファイル: helper.py プロジェクト: synapseattack/GitPython
        def remote_repo_creator(self):
            remote_repo_dir = tempfile.mktemp("remote_repo_%s" % func.__name__)
            repo_dir = tempfile.mktemp("remote_clone_non_bare_repo")

            rw_remote_repo = self.rorepo.clone(remote_repo_dir,
                                               shared=True,
                                               bare=True)
            # recursive alternates info ?
            rw_repo = rw_remote_repo.clone(repo_dir,
                                           shared=True,
                                           bare=False,
                                           n=True)
            rw_repo.head.commit = working_tree_ref
            rw_repo.head.reference.checkout()

            # prepare for git-daemon
            rw_remote_repo.daemon_export = True

            # this thing is just annoying !
            with rw_remote_repo.config_writer() as crw:
                section = "daemon"
                try:
                    crw.add_section(section)
                except Exception:
                    pass
                crw.set(section, "receivepack", True)

            # Initialize the remote - first do it as local remote and pull, then
            # we change the url to point to the daemon.
            d_remote = Remote.create(rw_repo, "daemon_origin", remote_repo_dir)
            d_remote.fetch()

            base_path, rel_repo_dir = osp.split(remote_repo_dir)

            remote_repo_url = Git.polish_url("git://localhost:%s/%s" %
                                             (GIT_DAEMON_PORT, rel_repo_dir))
            with d_remote.config_writer as cw:
                cw.set('url', remote_repo_url)

            try:
                gd = launch_git_daemon(Git.polish_url(base_path), '127.0.0.1',
                                       GIT_DAEMON_PORT)
            except Exception as ex:
                if is_win:
                    msg = textwrap.dedent("""
                    The `git-daemon.exe` must be in PATH.
                    For MINGW, look into .\Git\mingw64\libexec\git-core\), but problems with paths might appear.
                    CYGWIN has no daemon, but if one exists, it gets along fine (has also paths problems)
                    Anyhow, alternatively try starting `git-daemon` manually:"""
                                          )
                else:
                    msg = "Please try starting `git-daemon` manually:"
                msg += textwrap.dedent("""
                    git daemon --enable=receive-pack  --base-path=%s  %s
                You can also run the daemon on a different port by passing --port=<port>"
                and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to <port>
                """ % (base_path, base_path))
                raise AssertionError(ex, msg)
                # END make assertion
            else:
                # Try listing remotes, to diagnose whether the daemon is up.
                rw_repo.git.ls_remote(d_remote)

                # adjust working dir
                prev_cwd = os.getcwd()
                os.chdir(rw_repo.working_dir)

                try:
                    return func(self, rw_repo, rw_remote_repo)
                except:
                    log.info(
                        "Keeping repos after failure: repo_dir = %s, remote_repo_dir = %s",
                        repo_dir, remote_repo_dir)
                    repo_dir = remote_repo_dir = None
                    raise
                finally:
                    os.chdir(prev_cwd)

            finally:
                try:
                    log.debug("Killing git-daemon...")
                    gd.proc.kill()
                except:
                    ## Either it has died (and we're here), or it won't die, again here...
                    pass

                rw_repo.git.clear_cache()
                rw_remote_repo.git.clear_cache()
                rw_repo = rw_remote_repo = None
                import gc
                gc.collect()
                if repo_dir:
                    rmtree(repo_dir)
                if remote_repo_dir:
                    rmtree(remote_repo_dir)

                if gd is not None:
                    gd.proc.wait()
コード例 #13
0
ファイル: helper.py プロジェクト: ChannyAzar/GitPython
        def remote_repo_creator(self):
            remote_repo_dir = _mktemp("remote_repo_%s" % func.__name__)
            repo_dir = _mktemp("remote_clone_non_bare_repo")

            rw_remote_repo = self.rorepo.clone(remote_repo_dir, shared=True, bare=True)
            # recursive alternates info ?
            rw_repo = rw_remote_repo.clone(repo_dir, shared=True, bare=False, n=True)
            rw_repo.head.commit = working_tree_ref
            rw_repo.head.reference.checkout()

            # prepare for git-daemon
            rw_remote_repo.daemon_export = True

            # this thing is just annoying !
            crw = rw_remote_repo.config_writer()
            section = "daemon"
            try:
                crw.add_section(section)
            except Exception:
                pass
            crw.set(section, "receivepack", True)
            # release lock
            crw.release()
            del(crw)

            # initialize the remote - first do it as local remote and pull, then
            # we change the url to point to the daemon. The daemon should be started
            # by the user, not by us
            d_remote = Remote.create(rw_repo, "daemon_origin", remote_repo_dir)
            d_remote.fetch()
            remote_repo_url = "git://localhost:%s%s" % (GIT_DAEMON_PORT, remote_repo_dir)

            d_remote.config_writer.set('url', remote_repo_url)

            temp_dir = osp(_mktemp())
            # On windows, this will fail ... we deal with failures anyway and default to telling the user to do it
            try:
                gd = Git().daemon(temp_dir, enable='receive-pack', listen='127.0.0.1', port=GIT_DAEMON_PORT,
                                  as_process=True)
                # yes, I know ... fortunately, this is always going to work if sleep time is just large enough
                time.sleep(0.5)
            except Exception:
                gd = None
            # end

            # try to list remotes to diagnoes whether the server is up
            try:
                rw_repo.git.ls_remote(d_remote)
            except GitCommandError as e:
                # We assume in good faith that we didn't start the daemon - but make sure we kill it anyway
                # Of course we expect it to work here already, but maybe there are timing constraints
                # on some platforms ?
                if gd is not None:
                    os.kill(gd.proc.pid, 15)
                print(str(e))
                if os.name == 'nt':
                    msg = "git-daemon needs to run this test, but windows does not have one. "
                    msg += 'Otherwise, run: git-daemon "%s"' % temp_dir
                    raise AssertionError(msg)
                else:
                    msg = 'Please start a git-daemon to run this test, execute: git daemon --enable=receive-pack "%s"'
                    msg += 'You can also run the daemon on a different port by passing --port=<port>'
                    msg += 'and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to <port>'
                    msg %= temp_dir
                    raise AssertionError(msg)
                # END make assertion
            # END catch ls remote error

            # adjust working dir
            prev_cwd = os.getcwd()
            os.chdir(rw_repo.working_dir)
            try:
                try:
                    return func(self, rw_repo, rw_remote_repo)
                except:
                    print("Keeping repos after failure: repo_dir = %s, remote_repo_dir = %s"
                          % (repo_dir, remote_repo_dir), file=sys.stderr)
                    repo_dir = remote_repo_dir = None
                    raise
            finally:
                # gd.proc.kill() ... no idea why that doesn't work
                if gd is not None:
                    os.kill(gd.proc.pid, 15)

                os.chdir(prev_cwd)
                rw_repo.git.clear_cache()
                rw_remote_repo.git.clear_cache()
                if repo_dir:
                    shutil.rmtree(repo_dir, onerror=_rmtree_onerror)
                if remote_repo_dir:
                    shutil.rmtree(remote_repo_dir, onerror=_rmtree_onerror)

                if gd is not None:
                    gd.proc.wait()
コード例 #14
0
ファイル: cli_test.py プロジェクト: lsst-sqre/neophile
def test_analyze_pr(tmp_path: Path, mock_push: Mock) -> None:
    runner = CliRunner()
    repo = Repo.init(str(tmp_path))
    Remote.create(repo, "origin", "https://github.com/foo/bar")
    src = (Path(__file__).parent / "data" / "kubernetes" / "gafaelfawr" /
           "Chart.yaml")
    dst = tmp_path / "Chart.yaml"
    shutil.copy(src, dst)
    repo.index.add(str(dst))
    actor = Actor("Someone", "*****@*****.**")
    repo.index.commit("Initial commit", author=actor, committer=actor)
    sqre = dict_to_yaml({"entries": {"gafaelfawr": [{"version": "1.4.0"}]}})
    payload = {"name": "Someone", "email": "*****@*****.**"}
    created_pr = False

    def check_pr_post(url: str, **kwargs: Any) -> CallbackResult:
        change = "Update gafaelfawr Helm chart from 1.3.1 to 1.4.0"
        assert json.loads(kwargs["data"]) == {
            "title": CommitMessage.title,
            "body": f"- {change}\n",
            "head": "u/neophile",
            "base": "master",
            "maintainer_can_modify": True,
            "draft": False,
        }

        assert repo.head.ref.name == "u/neophile"
        yaml = YAML()
        data = yaml.load(dst)
        assert data["dependencies"][0]["version"] == "1.4.0"
        commit = repo.head.commit
        assert commit.author.name == "Someone"
        assert commit.author.email == "*****@*****.**"
        assert commit.message == f"{CommitMessage.title}\n\n- {change}\n"

        nonlocal created_pr
        created_pr = True
        return CallbackResult(status=201)

    with aioresponses() as mock:
        mock.get("https://lsst-sqre.github.io/charts/index.yaml", body=sqre)
        mock.get("https://api.github.com/user", payload=payload)
        mock.get(
            "https://api.github.com/repos/foo/bar",
            payload={"default_branch": "master"},
        )
        pattern = re.compile(r"https://api.github.com/repos/foo/bar/pulls\?.*")
        mock.get(pattern, payload=[])
        mock.post(
            "https://api.github.com/repos/foo/bar/pulls",
            callback=check_pr_post,
        )
        result = runner.invoke(
            main,
            ["analyze", "--path", str(tmp_path), "--pr"],
            env={"NEOPHILE_CACHE_ENABLED": "0"},
        )

    assert created_pr
    assert result.exit_code == 0
    assert mock_push.call_args_list == [
        call("u/neophile:u/neophile", force=True)
    ]
    assert repo.head.ref.name == "master"
コード例 #15
0
ファイル: helper.py プロジェクト: qiufengyu21/GitPython-1
        def remote_repo_creator(self):
            rw_daemon_repo_dir = tempfile.mktemp(prefix="daemon_repo-%s-" %
                                                 func.__name__)
            rw_repo_dir = tempfile.mktemp(prefix="daemon_cloned_repo-%s-" %
                                          func.__name__)

            rw_daemon_repo = self.rorepo.clone(rw_daemon_repo_dir,
                                               shared=True,
                                               bare=True)
            # recursive alternates info ?
            rw_repo = rw_daemon_repo.clone(rw_repo_dir,
                                           shared=True,
                                           bare=False,
                                           n=True)
            try:
                rw_repo.head.commit = working_tree_ref
                rw_repo.head.reference.checkout()

                # prepare for git-daemon
                rw_daemon_repo.daemon_export = True

                # this thing is just annoying !
                with rw_daemon_repo.config_writer() as crw:
                    section = "daemon"
                    try:
                        crw.add_section(section)
                    except Exception:
                        pass
                    crw.set(section, "receivepack", True)

                # Initialize the remote - first do it as local remote and pull, then
                # we change the url to point to the daemon.
                d_remote = Remote.create(rw_repo, "daemon_origin",
                                         rw_daemon_repo_dir)
                d_remote.fetch()

                base_daemon_path, rel_repo_dir = osp.split(rw_daemon_repo_dir)

                remote_repo_url = Git.polish_url(
                    "git://localhost:%s/%s" % (GIT_DAEMON_PORT, rel_repo_dir))
                with d_remote.config_writer as cw:
                    cw.set('url', remote_repo_url)

                with git_daemon_launched(
                        Git.polish_url(
                            base_daemon_path,
                            is_cygwin=False),  # No daemon in Cygwin.
                        '127.0.0.1',
                        GIT_DAEMON_PORT):
                    # Try listing remotes, to diagnose whether the daemon is up.
                    rw_repo.git.ls_remote(d_remote)

                    with cwd(rw_repo.working_dir):
                        try:
                            return func(self, rw_repo, rw_daemon_repo)
                        except:
                            log.info(
                                "Keeping repos after failure: \n  rw_repo_dir: %s \n  rw_daemon_repo_dir: %s",
                                rw_repo_dir, rw_daemon_repo_dir)
                            rw_repo_dir = rw_daemon_repo_dir = None
                            raise

            finally:
                rw_repo.git.clear_cache()
                rw_daemon_repo.git.clear_cache()
                del rw_repo
                del rw_daemon_repo
                gc.collect()
                gitdb.util.mman.collect()
                gc.collect()
                if rw_repo_dir:
                    rmtree(rw_repo_dir)
                if rw_daemon_repo_dir:
                    rmtree(rw_daemon_repo_dir)
コード例 #16
0
        def remote_repo_creator(self):
            remote_repo_dir = _mktemp("remote_repo_%s" % func.__name__)
            repo_dir = _mktemp("remote_clone_non_bare_repo")

            rw_remote_repo = self.rorepo.clone(remote_repo_dir,
                                               shared=True,
                                               bare=True)
            # recursive alternates info ?
            rw_repo = rw_remote_repo.clone(repo_dir,
                                           shared=True,
                                           bare=False,
                                           n=True)
            rw_repo.head.commit = working_tree_ref
            rw_repo.head.reference.checkout()

            # prepare for git-daemon
            rw_remote_repo.daemon_export = True

            # this thing is just annoying !
            crw = rw_remote_repo.config_writer()
            section = "daemon"
            try:
                crw.add_section(section)
            except Exception:
                pass
            crw.set(section, "receivepack", True)
            # release lock
            crw.release()
            del (crw)

            # initialize the remote - first do it as local remote and pull, then
            # we change the url to point to the daemon. The daemon should be started
            # by the user, not by us
            d_remote = Remote.create(rw_repo, "daemon_origin", remote_repo_dir)
            d_remote.fetch()
            remote_repo_url = "git://localhost:%s%s" % (GIT_DAEMON_PORT,
                                                        remote_repo_dir)

            d_remote.config_writer.set('url', remote_repo_url)

            temp_dir = osp(_mktemp())
            # On windows, this will fail ... we deal with failures anyway and default to telling the user to do it
            try:
                gd = Git().daemon(temp_dir,
                                  enable='receive-pack',
                                  listen='127.0.0.1',
                                  port=GIT_DAEMON_PORT,
                                  as_process=True)
                # yes, I know ... fortunately, this is always going to work if sleep time is just large enough
                time.sleep(0.5)
            except Exception:
                gd = None
            # end

            # try to list remotes to diagnoes whether the server is up
            try:
                rw_repo.git.ls_remote(d_remote)
            except GitCommandError as e:
                # We assume in good faith that we didn't start the daemon - but make sure we kill it anyway
                # Of course we expect it to work here already, but maybe there are timing constraints
                # on some platforms ?
                if gd is not None:
                    os.kill(gd.proc.pid, 15)
                print(str(e))
                if os.name == 'nt':
                    msg = "git-daemon needs to run this test, but windows does not have one. "
                    msg += 'Otherwise, run: git-daemon "%s"' % temp_dir
                    raise AssertionError(msg)
                else:
                    msg = 'Please start a git-daemon to run this test, execute: git daemon --enable=receive-pack "%s"'
                    msg += 'You can also run the daemon on a different port by passing --port=<port>'
                    msg += 'and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to <port>'
                    msg %= temp_dir
                    raise AssertionError(msg)
                # END make assertion
            # END catch ls remote error

            # adjust working dir
            prev_cwd = os.getcwd()
            os.chdir(rw_repo.working_dir)
            try:
                try:
                    return func(self, rw_repo, rw_remote_repo)
                except:
                    print(
                        "Keeping repos after failure: repo_dir = %s, remote_repo_dir = %s"
                        % (repo_dir, remote_repo_dir),
                        file=sys.stderr)
                    repo_dir = remote_repo_dir = None
                    raise
            finally:
                # gd.proc.kill() ... no idea why that doesn't work
                if gd is not None:
                    os.kill(gd.proc.pid, 15)

                os.chdir(prev_cwd)
                rw_repo.git.clear_cache()
                rw_remote_repo.git.clear_cache()
                if repo_dir:
                    shutil.rmtree(repo_dir, onerror=_rmtree_onerror)
                if remote_repo_dir:
                    shutil.rmtree(remote_repo_dir, onerror=_rmtree_onerror)

                if gd is not None:
                    gd.proc.wait()
コード例 #17
0
ファイル: helper.py プロジェクト: dhaba/GitPython
        def remote_repo_creator(self):
            remote_repo_dir = _mktemp("remote_repo_%s" % func.__name__)
            repo_dir = _mktemp("remote_clone_non_bare_repo")

            rw_remote_repo = self.rorepo.clone(remote_repo_dir,
                                               shared=True,
                                               bare=True)
            # recursive alternates info ?
            rw_repo = rw_remote_repo.clone(repo_dir,
                                           shared=True,
                                           bare=False,
                                           n=True)
            rw_repo.head.commit = working_tree_ref
            rw_repo.head.reference.checkout()

            # prepare for git-daemon
            rw_remote_repo.daemon_export = True

            # this thing is just annoying !
            with rw_remote_repo.config_writer() as crw:
                section = "daemon"
                try:
                    crw.add_section(section)
                except Exception:
                    pass
                crw.set(section, "receivepack", True)

            # initialize the remote - first do it as local remote and pull, then
            # we change the url to point to the daemon. The daemon should be started
            # by the user, not by us
            d_remote = Remote.create(rw_repo, "daemon_origin", remote_repo_dir)
            d_remote.fetch()
            remote_repo_url = "git://localhost:%s%s" % (GIT_DAEMON_PORT,
                                                        remote_repo_dir)

            with d_remote.config_writer as cw:
                cw.set('url', remote_repo_url)

            temp_dir = osp(_mktemp())
            gd = launch_git_daemon(temp_dir, '127.0.0.1', GIT_DAEMON_PORT)
            try:
                # yes, I know ... fortunately, this is always going to work if sleep time is just large enough
                time.sleep(0.5)
                # end

                # try to list remotes to diagnoes whether the server is up
                try:
                    rw_repo.git.ls_remote(d_remote)
                except GitCommandError as e:
                    # We assume in good faith that we didn't start the daemon - but make sure we kill it anyway
                    # Of course we expect it to work here already, but maybe there are timing constraints
                    # on some platforms ?
                    try:
                        gd.proc.terminate()
                    except Exception as ex:
                        log.debug(
                            "Ignoring %r while terminating proc after %r.", ex,
                            e)
                    log.warning('git(%s) ls-remote failed due to:%s',
                                rw_repo.git_dir, e)
                    if is_win:
                        msg = textwrap.dedent("""
                        MINGW yet has problems with paths, and `git-daemon.exe` must be in PATH
                        (look into .\Git\mingw64\libexec\git-core\);
                        CYGWIN has no daemon, but if one exists, it gets along fine (has also paths problems)
                        Anyhow, alternatively try starting `git-daemon` manually:"""
                                              )
                    else:
                        msg = "Please try starting `git-daemon` manually:"

                    msg += textwrap.dedent("""
                        git daemon --enable=receive-pack '%s'
                    You can also run the daemon on a different port by passing --port=<port>"
                    and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to <port>
                    """ % temp_dir)
                    from nose import SkipTest
                    raise SkipTest(msg) if is_win else AssertionError(msg)
                    # END make assertion
                # END catch ls remote error

                # adjust working dir
                prev_cwd = os.getcwd()
                os.chdir(rw_repo.working_dir)

                try:
                    return func(self, rw_repo, rw_remote_repo)
                except:
                    log.info(
                        "Keeping repos after failure: repo_dir = %s, remote_repo_dir = %s",
                        repo_dir, remote_repo_dir)
                    repo_dir = remote_repo_dir = None
                    raise
                finally:
                    os.chdir(prev_cwd)

            finally:
                try:
                    gd.proc.kill()
                except:
                    ## Either it has died (and we're here), or it won't die, again here...
                    pass

                rw_repo.git.clear_cache()
                rw_remote_repo.git.clear_cache()
                rw_repo = rw_remote_repo = None
                import gc
                gc.collect()
                if repo_dir:
                    rmtree(repo_dir)
                if remote_repo_dir:
                    rmtree(remote_repo_dir)

                if gd is not None:
                    gd.proc.wait()