mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Fix git.latest failure when rev is not the default branch
This commit is contained in:
parent
c3fdd1dcc4
commit
c081b2c62c
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user