Merge pull request #30847 from terminalmage/bp-30844

Backport #30844 to 2015.8 branch
This commit is contained in:
Mike Place 2016-02-03 09:26:46 -07:00
commit 0338f445d9
2 changed files with 36 additions and 18 deletions

View File

@ -570,6 +570,8 @@ class GitPython(GitProvider):
# to the git config at once, go ahead and pass over it since
# this is the only write. This should place a lock down.
pass
else:
new = True
return new
def dir_list(self, tgt_env):
@ -942,6 +944,8 @@ class Pygit2(GitProvider):
# to the git config at once, go ahead and pass over it since
# this is the only write. This should place a lock down.
pass
else:
new = True
return new
def dir_list(self, tgt_env):
@ -1613,10 +1617,24 @@ class Dulwich(GitProvider): # pylint: disable=abstract-method
new = False
if not os.listdir(self.cachedir):
# Repo cachedir is empty, initialize a new repo there
self.repo = dulwich.repo.Repo.init(self.cachedir)
new = True
else:
# Repo cachedir exists, try to attach
try:
self.repo = dulwich.repo.Repo(self.cachedir)
except dulwich.repo.NotGitRepository:
log.error(_INVALID_REPO.format(self.cachedir, self.url))
return new
self.lockfile = os.path.join(self.repo.path, 'update.lk')
# Read in config file and look for the remote
try:
conf = self.get_conf()
conf.get(('remote', 'origin'), 'url')
except KeyError:
try:
self.repo = dulwich.repo.Repo.init(self.cachedir)
new = True
conf = self.get_conf()
conf.set('http', 'sslVerify', self.ssl_verify)
# Add remote manually, there is no function/object to do this
conf.set(
@ -1629,17 +1647,10 @@ class Dulwich(GitProvider): # pylint: disable=abstract-method
conf.write_to_path()
except os.error:
pass
else:
# Repo cachedir exists, try to attach
try:
self.repo = dulwich.repo.Repo(self.cachedir)
except dulwich.repo.NotGitRepository:
log.error(_INVALID_REPO.format(self.cachedir, self.url))
return new
self.lockfile = os.path.join(self.repo.path, 'update.lk')
# No way to interact with remotes, so just assume success
else:
new = True
except os.error:
pass
return new
def walk_tree(self, tree, path):
@ -1747,6 +1758,9 @@ class GitBase(object):
repo_obj.root = repo_obj.root.rstrip(os.path.sep)
# Sanity check and assign the credential parameter
repo_obj.verify_auth()
if self.opts['__role'] == 'minion' and repo_obj.new:
# Perform initial fetch
repo_obj.fetch()
self.remotes.append(repo_obj)
# Don't allow collisions in cachedir naming

View File

@ -93,7 +93,8 @@ class GitFSTest(integration.ModuleCase):
with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'],
'gitfs_remotes': ['file://' + self.tmp_repo_dir],
'sock_dir': self.master_opts['sock_dir']}):
'sock_dir': self.master_opts['sock_dir'],
'__role': self.master_opts['__role']}):
gitfs.update()
def tearDown(self):
@ -108,7 +109,8 @@ class GitFSTest(integration.ModuleCase):
def test_file_list(self):
with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'],
'gitfs_remotes': ['file://' + self.tmp_repo_dir],
'sock_dir': self.master_opts['sock_dir']}):
'sock_dir': self.master_opts['sock_dir'],
'__role': self.master_opts['__role']}):
ret = gitfs.file_list(LOAD)
self.assertIn('testfile', ret)
@ -116,7 +118,8 @@ class GitFSTest(integration.ModuleCase):
def test_dir_list(self):
with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'],
'gitfs_remotes': ['file://' + self.tmp_repo_dir],
'sock_dir': self.master_opts['sock_dir']}):
'sock_dir': self.master_opts['sock_dir'],
'__role': self.master_opts['__role']}):
ret = gitfs.dir_list(LOAD)
self.assertIn('grail', ret)
@ -124,7 +127,8 @@ class GitFSTest(integration.ModuleCase):
def test_envs(self):
with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'],
'gitfs_remotes': ['file://' + self.tmp_repo_dir],
'sock_dir': self.master_opts['sock_dir']}):
'sock_dir': self.master_opts['sock_dir'],
'__role': self.master_opts['__role']}):
ret = gitfs.envs()
self.assertIn('base', ret)