git_remote_helpers / git / non_local.pyon commit Add tests for submodule sync --recursive (44fa0ef)
   1import os
   2import subprocess
   3
   4from git_remote_helpers.util import check_call, die, warn
   5
   6
   7class NonLocalGit(object):
   8    """Handler to interact with non-local repos.
   9    """
  10
  11    def __init__(self, repo):
  12        """Creates a new non-local handler for the specified repo.
  13        """
  14
  15        self.repo = repo
  16
  17    def clone(self, base):
  18        """Clones the non-local repo to base.
  19
  20        Does nothing if a clone already exists.
  21        """
  22
  23        path = os.path.join(self.repo.get_base_path(base), '.git')
  24
  25        # already cloned
  26        if os.path.exists(path):
  27            return path
  28
  29        os.makedirs(path)
  30        args = ["git", "clone", "--bare", "--quiet", self.repo.gitpath, path]
  31
  32        check_call(args)
  33
  34        return path
  35
  36    def update(self, base):
  37        """Updates checkout of the non-local repo in base.
  38        """
  39
  40        path = os.path.join(self.repo.get_base_path(base), '.git')
  41
  42        if not os.path.exists(path):
  43            die("could not find repo at %s", path)
  44
  45        args = ["git", "--git-dir=" + path, "fetch", "--quiet", self.repo.gitpath]
  46        check_call(args)
  47
  48        args = ["git", "--git-dir=" + path, "update-ref", "refs/heads/master", "FETCH_HEAD"]
  49        child = check_call(args)
  50
  51    def push(self, base):
  52        """Pushes from the non-local repo to base.
  53        """
  54
  55        path = os.path.join(self.repo.get_base_path(base), '.git')
  56
  57        if not os.path.exists(path):
  58            die("could not find repo at %s", path)
  59
  60        args = ["git", "--git-dir=" + path, "push", "--quiet", self.repo.gitpath, "--all"]
  61        child = check_call(args)