Merge pull request #45443 from rallytime/bp-45399-2016.11.9

Back-port #45399 to 2016.11.9
This commit is contained in:
Nicole Thomas 2018-01-17 09:53:57 -05:00 committed by GitHub
commit 4e0a0eec1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View file

@ -802,6 +802,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
@ -1679,7 +1686,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

@ -401,6 +401,39 @@ class GitTest(integration.ModuleCase, integration.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