コード例 #1
0
ファイル: git.py プロジェクト: sweyrick/fabtools
def working_copy(remote_url, path=None, branch="master", update=True,
                 use_sudo=False, user=None):
    """
    Require a working copy of the repository from the ``remote_url``.

    Clones or fetchs from the repository under ``remote_url`` and checks out
    ``branch``.

    :param remote_url: URL of the remote repository (e.g.
                       https://github.com/ronnix/fabtools.git).  The given URL
                       will be the ``origin`` remote of the working copy.
    :type remote_url: str

    :param path: Absolute or relative path of the working copy on the
                 filesystem.  If this directory doesn't exist yet, a new
                 working copy is created through ``git clone``.  If the
                 directory does exist *and* ``update == True``, a
                 ``git fetch`` is issued.  If ``path is None`` the
                 ``git clone`` is issued in the current working directory and
                 the directory name of the working copy is created by ``git``.
    :type path: str

    :param branch: Branch to switch to after cloning or fetching.
    :type branch: str

    :param update: Whether or not to update an existing working copy via
                   ``git fetch``.
    :type update: bool

    :param use_sudo: If ``True`` execute ``git`` with
                     :func:`fabric.operations.sudo`, else with
                     :func:`fabric.operations.run`.
    :type use_sudo: bool

    :param user: If ``use_sudo is True``, run :func:`fabric.operations.sudo`
                 with the given user.  If ``use_sudo is False`` this parameter
                 has no effect.
    :type user: str
    """

    if is_dir(path, use_sudo=use_sudo) and update:
        # git fetch
        git.fetch(path=path, use_sudo=use_sudo, user=user)
        git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user)
        git.pull(path=path, use_sudo=use_sudo, user=user)

    elif is_dir(path, use_sudo=use_sudo) and not update:
        git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user)

    elif not is_dir(path, use_sudo=use_sudo):
        # git clone
        git.clone(remote_url, path=path, use_sudo=use_sudo, user=user)
        if path is None:
            path = remote_url.split('/')[-1].replace('.git', '')
        git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user)

    else:
        raise ValueError("Invalid combination of parameters.")
コード例 #2
0
ファイル: git.py プロジェクト: EvolveGlobal/deployer
def deploy_code(repo_url='', app_dir='', user='', remote='origin', branch='master'):

    raw_branch = ''
    if '/' in branch:
        remote, raw_branch = branch.split('/')

    print(green('Fetching {}'.format(remote)))
    git.fetch(app_dir, remote=remote)

    print(green('Checking out {}'.format(branch)))
    git.checkout(app_dir, branch=branch)

    print(green('Pulling updates from {}'.format(branch)))
    if raw_branch:
        git.pull(app_dir, remote=remote, branch=raw_branch)
    else:
        git.pull(app_dir, remote=remote, branch=branch)
コード例 #3
0
ファイル: git.py プロジェクト: dhackner/fabtools
def working_copy(remote_url, path=None, branch="master", update=True,
                 use_sudo=False, user=None):
    """
    Require a working copy of the repository from the ``remote_url``.

    The ``path`` is optional, and defaults to the last segment of the
    remote repository URL, without its ``.git`` suffix.

    If the ``path`` does not exist, this will clone the remote
    repository and check out the specified branch.

    If the ``path`` exists and ``update`` is ``True``, it will fetch
    changes from the remote repository, check out the specified branch,
    then merge the remote changes into the working copy.

    If the ``path`` exists and ``update`` is ``False``, it will only
    check out the specified branch, without fetching remote changesets.

    :param remote_url: URL of the remote repository (e.g.
                       https://github.com/ronnix/fabtools.git).  The given URL
                       will be the ``origin`` remote of the working copy.
    :type remote_url: str

    :param path: Absolute or relative path of the working copy on the
                 filesystem.  If this directory doesn't exist yet, a new
                 working copy is created through ``git clone``.  If the
                 directory does exist *and* ``update == True``, a
                 ``git fetch`` is issued.  If ``path is None`` the
                 ``git clone`` is issued in the current working directory and
                 the directory name of the working copy is created by ``git``.
    :type path: str

    :param branch: Branch to check out.
    :type branch: str

    :param update: Whether or not to fetch and merge remote changesets.
    :type update: bool

    :param use_sudo: If ``True`` execute ``git`` with
                     :func:`fabric.operations.sudo`, else with
                     :func:`fabric.operations.run`.
    :type use_sudo: bool

    :param user: If ``use_sudo is True``, run :func:`fabric.operations.sudo`
                 with the given user.  If ``use_sudo is False`` this parameter
                 has no effect.
    :type user: str
    """

    command()

    if path is None:
        path = remote_url.split('/')[-1].rstrip('.git')

    if is_dir(path, use_sudo=use_sudo) and update:
        git.fetch(path=path, use_sudo=use_sudo, user=user)
        git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user)
        git.pull(path=path, use_sudo=use_sudo, user=user)

    elif is_dir(path, use_sudo=use_sudo) and not update:
        git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user)

    elif not is_dir(path, use_sudo=use_sudo):
        git.clone(remote_url, path=path, use_sudo=use_sudo, user=user)
        git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user)

    else:
        raise ValueError("Invalid combination of parameters.")
コード例 #4
0
ファイル: git.py プロジェクト: tachang/fabtools
def working_copy(remote_url, path=None, branch="master", update=True,
                 use_sudo=False, user=None):
    """
    Require a working copy of the repository from the ``remote_url``.

    The ``path`` is optional, and defaults to the last segment of the
    remote repository URL, without its ``.git`` suffix.

    If the ``path`` does not exist, this will clone the remote
    repository and check out the specified branch.

    If the ``path`` exists and ``update`` is ``True``, it will fetch
    changes from the remote repository, check out the specified branch,
    then merge the remote changes into the working copy.

    If the ``path`` exists and ``update`` is ``False``, it will only
    check out the specified branch, without fetching remote changesets.

    :param remote_url: URL of the remote repository (e.g.
                       https://github.com/ronnix/fabtools.git).  The given URL
                       will be the ``origin`` remote of the working copy.
    :type remote_url: str

    :param path: Absolute or relative path of the working copy on the
                 filesystem.  If this directory doesn't exist yet, a new
                 working copy is created through ``git clone``.  If the
                 directory does exist *and* ``update == True``, a
                 ``git fetch`` is issued.  If ``path is None`` the
                 ``git clone`` is issued in the current working directory and
                 the directory name of the working copy is created by ``git``.
    :type path: str

    :param branch: Branch to check out.
    :type branch: str

    :param update: Whether or not to fetch and merge remote changesets.
    :type update: bool

    :param use_sudo: If ``True`` execute ``git`` with
                     :func:`fabric.operations.sudo`, else with
                     :func:`fabric.operations.run`.
    :type use_sudo: bool

    :param user: If ``use_sudo is True``, run :func:`fabric.operations.sudo`
                 with the given user.  If ``use_sudo is False`` this parameter
                 has no effect.
    :type user: str
    """

    if path is None:
        path = remote_url.split('/')[-1].rstrip('.git')

    if is_dir(path, use_sudo=use_sudo) and update:
        git.fetch(path=path, use_sudo=use_sudo, user=user)
        git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user)
        git.pull(path=path, use_sudo=use_sudo, user=user)

    elif is_dir(path, use_sudo=use_sudo) and not update:
        git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user)

    elif not is_dir(path, use_sudo=use_sudo):
        git.clone(remote_url, path=path, use_sudo=use_sudo, user=user)
        git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user)

    else:
        raise ValueError("Invalid combination of parameters.")