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 __HOLE__:
            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
dataset/ETHPy150Open robmadole/jig/src/jig/commands/base.py/add_plugin