def do_import(self, base): """Imports a fast-import stream to the given directory. Simply delegates to git fast-import. """ dirname = self.repo.get_base_path(base) if self.repo.local(): gitdir = self.repo.gitpath else: gitdir = os.path.abspath(os.path.join(dirname, '.git')) path = os.path.abspath(os.path.join(dirname, 'git.marks')) if not os.path.exists(dirname): os.makedirs(dirname) args = [ "git", "--git-dir=" + gitdir, "fast-import", "--quiet", "--export-marks=" + path ] if os.path.exists(path): args.append("--import-marks=" + path) check_call(args)
def update(self, base): """Updates checkout of the non-local repo in base. """ path = os.path.join(self.repo.get_base_path(base), '.git') if not os.path.exists(path): die("could not find repo at %s", path) args = ["git", "--git-dir=" + path, "fetch", "--quiet", self.repo.gitpath] check_call(args) args = ["git", "--git-dir=" + path, "update-ref", "refs/heads/master", "FETCH_HEAD"] child = check_call(args)
def get_revs(self): """Fetches all revs from the remote. """ args = ["git", "ls-remote", self.gitpath] path = ".cached_revs" ofile = open(path, "w") check_call(args, stdout=ofile) output = open(path).readlines() self.revmap = dict(sanitize(i) for i in output) if "HEAD" in self.revmap: del self.revmap["HEAD"] self.revs_ = self.revmap.keys() ofile.close()
def clone(self, base): """Clones the non-local repo to base. Does nothing if a clone already exists. """ path = os.path.join(self.repo.get_base_path(base), '.git') # already cloned if os.path.exists(path): return path os.makedirs(path) args = ["git", "clone", "--bare", "--quiet", self.repo.gitpath, path] check_call(args) return path
def update(self, base): """Updates checkout of the non-local repo in base. """ path = os.path.join(self.repo.get_base_path(base), '.git') if not os.path.exists(path): die("could not find repo at %s", path) args = [ "git", "--git-dir=" + path, "fetch", "--quiet", self.repo.gitpath ] check_call(args) args = [ "git", "--git-dir=" + path, "update-ref", "refs/heads/master", "FETCH_HEAD" ] child = check_call(args)
def export_repo(self, base, refs=None): """Exports a fast-export stream for the given directory. Simply delegates to git fast-epxort and pipes it through sed to make the refs show up under the prefix rather than the default refs/heads. This is to demonstrate how the export data can be stored under it's own ref (using the refspec capability). If None, refs defaults to ["HEAD"]. """ if not refs: refs = ["HEAD"] dirname = self.repo.get_base_path(base) path = os.path.abspath(os.path.join(dirname, 'testgit.marks')) if not os.path.exists(dirname): os.makedirs(dirname) print "feature relative-marks" if os.path.exists(os.path.join(dirname, 'git.marks')): print "feature import-marks=%s/git.marks" % self.repo.hash print "feature export-marks=%s/git.marks" % self.repo.hash sys.stdout.flush() args = [ "git", "--git-dir=" + self.repo.gitpath, "fast-export", "--export-marks=" + path ] if os.path.exists(path): args.append("--import-marks=" + path) args.extend(refs) p1 = subprocess.Popen(args, stdout=subprocess.PIPE) args = ["sed", "s_refs/heads/_" + self.repo.prefix + "_g"] check_call(args, stdin=p1.stdout)
def push(self, base): """Pushes from the non-local repo to base. """ path = os.path.join(self.repo.get_base_path(base), '.git') if not os.path.exists(path): die("could not find repo at %s", path) args = ["git", "--git-dir=" + path, "push", "--quiet", self.repo.gitpath, "--all"] child = check_call(args)
def export_repo(self, base, refs=None): """Exports a fast-export stream for the given directory. Simply delegates to git fast-epxort and pipes it through sed to make the refs show up under the prefix rather than the default refs/heads. This is to demonstrate how the export data can be stored under it's own ref (using the refspec capability). If None, refs defaults to ["HEAD"]. """ if not refs: refs = ["HEAD"] dirname = self.repo.get_base_path(base) path = os.path.abspath(os.path.join(dirname, 'testgit.marks')) if not os.path.exists(dirname): os.makedirs(dirname) print "feature relative-marks" if os.path.exists(os.path.join(dirname, 'git.marks')): print "feature import-marks=%s/git.marks" % self.repo.hash print "feature export-marks=%s/git.marks" % self.repo.hash sys.stdout.flush() args = ["git", "--git-dir=" + self.repo.gitpath, "fast-export", "--export-marks=" + path] if os.path.exists(path): args.append("--import-marks=" + path) args.extend(refs) p1 = subprocess.Popen(args, stdout=subprocess.PIPE) args = ["sed", "s_refs/heads/_" + self.repo.prefix + "_g"] check_call(args, stdin=p1.stdout)
def do_import(self, base): """Imports a fast-import stream to the given directory. Simply delegates to git fast-import. """ dirname = self.repo.get_base_path(base) if self.repo.local: gitdir = self.repo.gitpath else: gitdir = os.path.abspath(os.path.join(dirname, '.git')) path = os.path.abspath(os.path.join(dirname, 'git.marks')) if not os.path.exists(dirname): os.makedirs(dirname) refs_before = self.get_refs(gitdir) args = [ "git", "--git-dir=" + gitdir, "fast-import", "--quiet", "--export-marks=" + path ] if os.path.exists(path): args.append("--import-marks=" + path) check_call(args) refs_after = self.get_refs(gitdir) changed = {} for name, value in refs_after.iteritems(): if refs_before.get(name) == value: continue changed[name] = value return changed
def do_import(self, base): """Imports a fast-import stream to the given directory. Simply delegates to git fast-import. """ dirname = self.repo.get_base_path(base) if self.repo.local(): gitdir = self.repo.gitpath else: gitdir = os.path.abspath(os.path.join(dirname, '.git')) path = os.path.abspath(os.path.join(dirname, 'git.marks')) if not os.path.exists(dirname): os.makedirs(dirname) args = ["git", "--git-dir=" + gitdir, "fast-import", "--quiet", "--export-marks=" + path] if os.path.exists(path): args.append("--import-marks=" + path) check_call(args)
def push(self, base): """Pushes from the non-local repo to base. """ path = os.path.join(self.repo.get_base_path(base), '.git') if not os.path.exists(path): die("could not find repo at %s", path) args = [ "git", "--git-dir=" + path, "push", "--quiet", self.repo.gitpath, "--all" ] child = check_call(args)
def do_import(self, base): """Imports a fast-import stream to the given directory. Simply delegates to git fast-import. """ dirname = self.repo.get_base_path(base) if self.repo.local: gitdir = self.repo.gitpath else: gitdir = os.path.abspath(os.path.join(dirname, '.git')) path = os.path.abspath(os.path.join(dirname, 'git.marks')) if not os.path.exists(dirname): os.makedirs(dirname) refs_before = self.get_refs(gitdir) args = ["git", "--git-dir=" + gitdir, "fast-import", "--quiet", "--export-marks=" + path] if os.path.exists(path): args.append("--import-marks=" + path) check_call(args) refs_after = self.get_refs(gitdir) changed = {} for name, value in refs_after.iteritems(): if refs_before.get(name) == value: continue changed[name] = value return changed