Fix git.latest failure when rev is not the default branch

This commit is contained in:
Erik Johnson 2018-01-11 15:26:35 -06:00 committed by rallytime
parent c3fdd1dcc4
commit c081b2c62c
No known key found for this signature in database
GPG Key ID: E8F1A4B90D0DEA19
2 changed files with 41 additions and 1 deletions

View File

@ -786,6 +786,13 @@ def latest(name,
)
remote_loc = None
if depth is not None and remote_rev_type != 'branch':
return _fail(
ret,
'When \'depth\' is used, \'rev\' must be set to the name of a '
'branch on the remote repository'
)
if remote_rev is None and not bare:
if rev != 'HEAD':
# A specific rev is desired, but that rev doesn't exist on the
@ -1663,7 +1670,7 @@ def latest(name,
if remote != 'origin':
clone_opts.extend(['--origin', remote])
if depth is not None:
clone_opts.extend(['--depth', str(depth)])
clone_opts.extend(['--depth', str(depth), '--branch', rev])
# We're cloning a fresh repo, there is no local branch or revision
local_branch = local_rev = None

View File

@ -446,6 +446,39 @@ class GitTest(ModuleCase, SaltReturnAssertsMixin):
if exc.errno != errno.ENOENT:
raise exc
def test_latest_depth(self):
'''
Test running git.latest state using the "depth" argument to limit the
history. See #45394.
'''
name = os.path.join(integration.TMP, 'salt_repo')
try:
ret = self.run_state(
'git.latest',
name='https://{0}/saltstack/salt-test-repo.git'.format(self.__domain),
rev='HEAD',
target=name,
depth=1
)
# HEAD is not a branch, this should fail
self.assertSaltFalseReturn(ret)
self.assertIn(
'must be set to the name of a branch',
ret[next(iter(ret))]['comment']
)
ret = self.run_state(
'git.latest',
name='https://{0}/saltstack/salt-test-repo.git'.format(self.__domain),
rev='non-default-branch',
target=name,
depth=1
)
self.assertSaltTrueReturn(ret)
self.assertTrue(os.path.isdir(os.path.join(name, '.git')))
finally:
shutil.rmtree(name, ignore_errors=True)
def test_present(self):
'''
git.present