Beispiel #1
0
    def test_remote_different_branch_has_updates(self):
        """
        If the remote has a non-"master" branch as the default.
        """
        # Create a new branch on the remote
        alternate = self.remote_repo.create_head('alternate')
        self.remote_repo.head.reference = alternate
        self.remote_repo.head.reset(index=True, working_tree=True)

        # Clone the remote branch locally
        self.local_workingdir = mkdtemp()
        clone(self.remote_workingdir, self.local_workingdir,
              branch='alternate')
        self.local_repo = Repo(self.local_workingdir)

        # If we check now, no new updates have been made
        self.assertFalse(remote_has_updates(self.local_workingdir))

        # Let the clock rollover
        sleep(1.0)

        # Commit to the 'alternate' branch on the remote
        self.commit(self.remote_workingdir, 'a.txt', 'aaa')

        self.assertTrue(remote_has_updates(self.local_workingdir))
Beispiel #2
0
Datei: base.py Projekt: dmore/jig
def add_plugin(pm, plugin, gitdir):
    """
    Adds a plugin by filename or URL.

    Where ``pm`` is an instance of :py:class:`PluginManager` and ``plugin``
    is either the URL to a Git Jig plugin repository or the file name of a
    Jig plugin. The ``gitdir`` is the path to the Git repository which will
    be used to find the :file:`.jig/plugins` directory.
    """
    # If this looks like a URL we will clone it first
    url = urlparse(plugin)

    if url.scheme:
        # This is a URL, let's clone it first into .jig/plugins
        # directory.
        plugin_parts = plugin.rsplit('@', 1)

        branch = None
        try:
            branch = plugin_parts[1]
        except IndexError:
            pass

        to_dir = join(gitdir, JIG_DIR_NAME, JIG_PLUGIN_DIR, uuid().hex)
        clone(plugin_parts[0], to_dir, branch)
        plugin = to_dir

    try:
        return pm.add(plugin)
    except PluginError:
        # Clean-up the cloned directory becuase this wasn't installed correctly
        if url.scheme:
            rmtree(plugin)

        raise
Beispiel #3
0
    def test_remote_different_branch_has_updates(self):
        """
        If the remote has a non-"master" branch as the default.
        """
        # Create a new branch on the remote
        alternate = self.remote_repo.create_head('alternate')
        self.remote_repo.head.reference = alternate
        self.remote_repo.head.reset(index=True, working_tree=True)

        # Clone the remote branch locally
        self.local_workingdir = mkdtemp()
        clone(self.remote_workingdir,
              self.local_workingdir,
              branch='alternate')
        self.local_repo = Repo(self.local_workingdir)

        # If we check now, no new updates have been made
        self.assertFalse(remote_has_updates(self.local_workingdir))

        # Let the clock rollover
        sleep(1.0)

        # Commit to the 'alternate' branch on the remote
        self.commit(self.remote_workingdir, 'a.txt', 'aaa')

        self.assertTrue(remote_has_updates(self.local_workingdir))
Beispiel #4
0
def add_plugin(pm, plugin, gitdir):
    """
    Adds a plugin by filename or URL.

    Where ``pm`` is an instance of :py:class:`PluginManager` and ``plugin``
    is either the URL to a Git Jig plugin repository or the file name of a
    Jig plugin. The ``gitdir`` is the path to the Git repository which will
    be used to find the :file:`.jig/plugins` directory.
    """
    # If this looks like a URL we will clone it first
    url = urlparse(plugin)

    if url.scheme:
        # This is a URL, let's clone it first into .jig/plugins
        # directory.
        plugin_parts = plugin.rsplit('@', 1)

        branch = None
        try:
            branch = plugin_parts[1]
        except IndexError:
            pass

        to_dir = join(gitdir, JIG_DIR_NAME, JIG_PLUGIN_DIR, uuid().hex)
        clone(plugin_parts[0], to_dir, branch)
        plugin = to_dir

    try:
        return pm.add(plugin)
    except PluginError:
        # Clean-up the cloned directory becuase this wasn't installed correctly
        if url.scheme:
            rmtree(plugin)

        raise
Beispiel #5
0
    def test_local_directory_clone(self):
        """
        Clones a local file-based Git repository.
        """
        to_dir = join(self.workingdir, 'a')

        clone(self.gitrepodir, to_dir)

        self.assertTrue(is_git_repo(to_dir))
Beispiel #6
0
    def test_local_directory_clone(self):
        """
        Clones a local file-based Git repository.
        """
        to_dir = join(self.workingdir, 'a')

        clone(self.gitrepodir, to_dir)

        self.assertTrue(is_git_repo(to_dir))
Beispiel #7
0
    def setUp(self):
        super(TestRemoteHasUpdates, self).setUp()

        repo, working_dir, diffs = self.repo_from_fixture('repo01')

        self.remote_repo = repo
        self.remote_workingdir = working_dir

        self.local_workingdir = mkdtemp()

        clone(self.remote_workingdir, self.local_workingdir)

        self.local_repo = Repo(self.local_workingdir)
Beispiel #8
0
    def setUp(self):
        super(TestRemoteHasUpdates, self).setUp()

        repo, working_dir, diffs = self.repo_from_fixture('repo01')

        self.remote_repo = repo
        self.remote_workingdir = working_dir

        self.local_workingdir = mkdtemp()

        clone(self.remote_workingdir, self.local_workingdir)

        self.local_repo = Repo(self.local_workingdir)
Beispiel #9
0
    def test_clone_branch(self):
        """
        Clone a specific branch of a repository.
        """
        with patch.object(Git, 'execute'):
            to_dir = join(self.workingdir, 'a')

            Git.execute.return_value = 'Cloning into X'

            clone('http://github.com/user/repo', to_dir, branch='alternate')

            Git.execute.assert_called_with([
                'git', 'clone', '--branch', 'alternate',
                'http://github.com/user/repo', to_dir
            ])
Beispiel #10
0
    def test_clone_invalid_repo(self):
        """
        Invalid repo raises error.
        """
        with patch.object(Git, 'execute'):
            to_dir = join(self.workingdir, 'a')

            Git.execute.side_effect = GitCommandError(['command'],
                                                      128,
                                                      stderr='bad command')

            with self.assertRaises(GitCloneError) as gce:
                clone('http://github.com/user/repo', to_dir)

            self.assertIn("'command' returned exit status 128: bad command",
                          gce.exception)
Beispiel #11
0
    def test_clone_invalid_repo(self):
        """
        Invalid repo raises error.
        """
        with patch.object(Git, 'execute'):
            to_dir = join(self.workingdir, 'a')

            Git.execute.side_effect = GitCommandError(
                ['command'], 128, stderr='bad command'
            )

            with self.assertRaises(GitCloneError) as gce:
                clone('http://github.com/user/repo', to_dir)

            self.assertIn(
                "'command' returned exit status 128: bad command",
                gce.exception
            )
Beispiel #12
0
    def test_clone_branch(self):
        """
        Clone a specific branch of a repository.
        """
        with patch.object(Git, 'execute'):
            to_dir = join(self.workingdir, 'a')

            Git.execute.return_value = 'Cloning into X'

            clone(
                'http://github.com/user/repo',
                to_dir,
                branch='alternate'
            )

            Git.execute.assert_called_with([
                'git', 'clone', '--branch', 'alternate',
                'http://github.com/user/repo', to_dir
            ])
Beispiel #13
0
    def test_clone_valid_repo(self):
        """
        Valid repo can be cloned.
        """
        with patch.object(Git, 'execute'):
            to_dir = join(self.workingdir, 'a')

            Git.execute.return_value = 'Cloning into X'

            gitobj = clone('http://github.com/user/repo', to_dir)

            Git.execute.assert_called_with(
                ['git', 'clone', 'http://github.com/user/repo', to_dir])

        self.assertIsInstance(gitobj, Git)
Beispiel #14
0
    def test_clone_valid_repo(self):
        """
        Valid repo can be cloned.
        """
        with patch.object(Git, 'execute'):
            to_dir = join(self.workingdir, 'a')

            Git.execute.return_value = 'Cloning into X'

            gitobj = clone('http://github.com/user/repo', to_dir)

            Git.execute.assert_called_with([
                'git', 'clone', 'http://github.com/user/repo', to_dir
            ])

        self.assertIsInstance(gitobj, Git)
Beispiel #15
0
 def clone_local(plugin, to_dir, branch):
     # Instead of jumping on the Internet to clone this, we will use the
     # local numbered directory repository we setup above. This will
     # allow our update to occur with a git pull and avoid network
     # traffic which is always faster for tests.
     clone(dir_to_clone, to_dir)
Beispiel #16
0
 def clone_local(plugin, to_dir, branch):
     # Instead of jumping on the Internet to clone this, we will use the
     # local numbered directory repository we setup above. This will
     # allow our update to occur with a git pull and avoid network
     # traffic which is always faster for tests.
     clone(dir_to_clone, to_dir)