- def update(self, forceVersion=False):
- 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
- repo = git.Repo(self.folder)
- origin = repo.remotes.origin
- origin.config_writer.set_value("url", self.url) # make sure we use the current URL
- else:
- # create a new one
- os.makedirs(self.folder)
- repo = git.Repo.init(self.folder)
- origin = repo.create_remote('origin', self.url)
- origin.fetch(progress=Git._ProgressPrinter()) # download new data
- print " "*80+"\r", # clean the line we are in
- # create/find correct branch
- if branchname in repo.heads:
- branch = repo.heads[branchname]
- else:
- branch = repo.create_head(branchname, self.commit)
- if isBranch: # track remote branch
- branch.set_tracking_branch(origin.refs[branchname])
- # update it to the latest remote commit
- branch.checkout()
- if forceVersion:
- repo.head.reset(self.commit, working_tree=True)
- else:
- repo.git.rebase(self.commit)
- # update submodules
- repo.git.submodule("update", "--init", "--recursive", "--rebase")
- # done
- print "...done",
- if repo.head.reference.commit != repo.commit(self.commit):
- print "(keeping local patches around)",
- print