support to update a repository
We sometime want to update a repository without fetching an actual refspec. A typical example is to fetch tags, since I did not manage to pass -t to git.fetch(), I am using instead the GitPython repo.update() calls which binds to `git remote update`. reset() add a clearing cache to make sure PyGit does not fail whenever the remote repository has been updated. Instead of duplicating code between reset() and update(), I have moved the recache command to update() and make reset() to call this new update(). Change-Id: I0d989dfc1f31ede6c79ccdd1d5b3968978a418ab Reviewed-on: https://review.openstack.org/19927 Reviewed-by: James E. Blair <corvus@inaugust.com> Reviewed-by: Clark Boylan <clark.boylan@gmail.com> Approved: James E. Blair <corvus@inaugust.com> Tested-by: Jenkins
This commit is contained in:
parent
fb682ccf2c
commit
d71e297421
|
@ -43,15 +43,8 @@ class Repo(object):
|
|||
|
||||
def reset(self):
|
||||
self.log.debug("Resetting repository %s" % self.local_path)
|
||||
self.update()
|
||||
origin = self.repo.remotes.origin
|
||||
origin.update()
|
||||
# If the remote repository is repacked, the repo object's
|
||||
# cache may be out of date. Specifically, it caches whether
|
||||
# to check the loose or packed DB for a given SHA. Further,
|
||||
# if there was no pack or lose directory to start with, the
|
||||
# repo object may not even have a database for it. Avoid
|
||||
# these problems by recreating the repo object.
|
||||
self.repo = git.Repo(self.local_path)
|
||||
for ref in origin.refs:
|
||||
if ref.remote_head == 'HEAD':
|
||||
continue
|
||||
|
@ -108,6 +101,18 @@ class Repo(object):
|
|||
self.remote_url))
|
||||
self.repo.remotes.origin.push('%s:%s' % (local, remote))
|
||||
|
||||
def update(self):
|
||||
self.log.debug("Updating repository %s" % self.local_path)
|
||||
origin = self.repo.remotes.origin
|
||||
origin.update()
|
||||
# If the remote repository is repacked, the repo object's
|
||||
# cache may be out of date. Specifically, it caches whether
|
||||
# to check the loose or packed DB for a given SHA. Further,
|
||||
# if there was no pack or lose directory to start with, the
|
||||
# repo object may not even have a database for it. Avoid
|
||||
# these problems by recreating the repo object.
|
||||
self.repo = git.Repo(self.local_path)
|
||||
|
||||
|
||||
class Merger(object):
|
||||
log = logging.getLogger("zuul.Merger")
|
||||
|
|
Loading…
Reference in New Issue