- class _ProgressPrinter(git.remote.RemoteProgress):
- def update(self, op_code, cur_count, max_count=None, message=''):
- print self._cur_line+(" "*30)+"\r",
+ def update(self, mode = MODE_REBASE):
+ isBranch = (self.commit.startswith('origin/'))
+ if isBranch:
+ branchname = self.commit[len('origin/'):]
+ else:
+ branchname = "tag"
+ # get us a git repository, and the "origin" remote
+ if os.path.exists(self.folder):
+ # load existing repo
+ os.chdir(self.folder)
+ git.remote("set-url", "origin", self.url) # make sure we use the current URL
+ else:
+ # create a new one
+ os.makedirs(self.folder)
+ os.chdir(self.folder)
+ git.init()
+ git.remote("add", "origin", self.url)
+ git.fetch("origin")
+ if mode == MODE_FETCH:
+ return
+ # create/find correct branch
+ if not git.branch("--list", branchname): # the branch does not yet exit
+ git.branch(branchname, self.commit)
+ if isBranch: # make sure we track the correct remote branch
+ git.branch("-u", self.commit, branchname)
+ # update it to the latest remote commit
+ git.checkout(branchname, get_stderr=True)
+ if mode == MODE_RESET:
+ git.reset("--hard", self.commit)
+ else:
+ git.rebase(self.commit)
+ # update submodules
+ git.submodule("update", "--init", "--recursive", "--rebase")
+ # done
+ print("...done", end=' ')
+ if git.rev_parse("HEAD") != git.rev_parse(self.commit):
+ print("(keeping local patches around)", end=' ')
+ print()