Exemplo n.º 1
0
 def __fetch_all(self):
     try:
         cmd(self.__bare_path(), [
             "git", "fetch", "--unshallow", self.cache.repository,
             self.__ref()
         ])
     except subprocess.CalledProcessError:
         # We may already have unshallowed this repository
         pass
Exemplo n.º 2
0
 def __commit_exists(self):
     try:
         cmd(self.__bare_path(), [
             "git", "cat-file", "-e", "{}^{{commit}}".format(self.revision)
         ])
         return True
     except subprocess.CalledProcessError as e:
         log.debug(
             "Did not find commit {} and instead got output: {}".format(
                 self.revision, e.output))
         return False
Exemplo n.º 3
0
def archive_ref(source, ref, destination):
    try:
        os.makedirs(destination)
    except FileExistsError:
        pass

    cmd(
        source,
        [
            "bash",
            # Bash will run the following safe bash, and accept the defs
            # of $1 and $2 via the following -s
            "-c",
            "git archive --format=tar \"$1\" | tar -x -C \"$2\"",

            # Passing ref and destination this way is much safer than
            # using interpolation
            "-s",
            ref,
            destination
        ])
Exemplo n.º 4
0
    def make_archive(self):
        if not self.__exists():
            log.warning("Fetching tag '{}' from {}".format(
                self.tag, self.cache.repository))
            with self.cache.lock():
                bare_path = self.__bare_path()
                ref = "refs/tags/{}".format(self.tag)
                setup_bare(bare_path)

                try:
                    cmd(bare_path, [
                        "git", "fetch", "--depth=1", self.cache.repository, ref
                    ])
                except subprocess.CalledProcessError as e:
                    log.debug(
                        "Did not find tag {}, instead got output: {}".format(
                            self.tag, e.output))

                    raise NixError("tag-not-found",
                                   "Tag {} not found".format(self.tag))

                archive_ref(bare_path, "FETCH_HEAD", self.__archive_path())

        return self.__archive_path()
Exemplo n.º 5
0
def setup_bare(path):
    if not os.path.isdir(path):
        log.debug("About to init a bare repository at {}".format(path))
        cmd(None, ["git", "init", "--bare", path])
Exemplo n.º 6
0
 def __deepen(self, depth):
     cmd(self.__bare_path(), [
         "git", "fetch", "--deepen",
         str(depth), self.cache.repository,
         self.__ref()
     ])