Merge pull request #27411 from terminalmage/issue27205

Fix invocation of git.config_get and git.config_set
This commit is contained in:
Mike Place 2015-09-28 16:53:01 -06:00
commit 284984e6ba
2 changed files with 75 additions and 40 deletions

View File

@ -80,11 +80,14 @@ def _config_getter(get_opt,
def _expand_path(cwd, user):
'''
Expand home directory
'''
try:
to_expand = '~' + user if user else '~'
except TypeError:
# Users should never be numeric but if we don't account for this then
# we're going to get a traceback
# we're going to get a traceback if someone passes this invalid input.
to_expand = '~' + str(user) if user else '~'
try:
return os.path.join(os.path.expanduser(to_expand), cwd)
@ -246,6 +249,9 @@ def _get_toplevel(path, user=None):
def _git_config(cwd, user):
'''
Helper to retrive git config options
'''
contextkey = 'git.config.' + cwd
if contextkey not in __context__:
git_dir = rev_parse(cwd,
@ -958,7 +964,6 @@ config_get_regex = config_get_regexp
def config_set(key,
value=None,
add=False,
multivar=None,
cwd=None,
user=None,
@ -1029,6 +1034,7 @@ def config_set(key,
salt myminion git.config_set user.email foo@bar.com global=True
'''
kwargs = salt.utils.clean_kwargs(**kwargs)
add_ = kwargs.pop('add', False)
global_ = kwargs.pop('global', False)
is_global = kwargs.pop('is_global', False)
if kwargs:
@ -1080,7 +1086,7 @@ def config_set(key,
if value is not None:
command = copy.copy(command_prefix)
if add:
if add_:
command.append('--add')
else:
command.append('--replace-all')
@ -1830,8 +1836,8 @@ def merge(cwd,
rev=None,
opts='',
user=None,
branch=None,
ignore_retcode=False):
ignore_retcode=False,
**kwargs):
'''
Interface to `git-merge(1)`_
@ -1883,14 +1889,19 @@ def merge(cwd,
# .. or merge another rev
salt myminion git.merge /path/to/repo rev=upstream/foo
'''
kwargs = salt.utils.clean_kwargs(**kwargs)
branch_ = kwargs.pop('branch', None)
if kwargs:
salt.utils.invalid_kwargs(kwargs)
cwd = _expand_path(cwd, user)
if branch:
if branch_:
salt.utils.warn_until(
'Nitrogen',
'The \'branch\' argument to git.merge has been deprecated, please '
'use \'rev\' instead.'
)
rev = branch
rev = branch_
command = ['git', 'merge']
command.extend(_format_opts(opts))
if rev:
@ -2201,7 +2212,7 @@ def push(cwd,
user=None,
identity=None,
ignore_retcode=False,
branch=None):
**kwargs):
'''
Interface to `git-push(1)`_
@ -2270,14 +2281,19 @@ def push(cwd,
# Delete remote branch 'upstream/temp'
salt myminion git.push /path/to/repo upstream :temp
'''
kwargs = salt.utils.clean_kwargs(**kwargs)
branch_ = kwargs.pop('branch', None)
if kwargs:
salt.utils.invalid_kwargs(kwargs)
cwd = _expand_path(cwd, user)
if branch:
if branch_:
salt.utils.warn_until(
'Nitrogen',
'The \'branch\' argument to git.push has been deprecated, please '
'use \'ref\' instead.'
)
ref = branch
ref = branch_
command = ['git', 'push']
command.extend(_format_opts(opts))
if not isinstance(remote, six.string_types):
@ -2393,7 +2409,8 @@ def remote_get(cwd,
cwd = _expand_path(cwd, user)
all_remotes = remotes(cwd,
user=user,
redact_auth=redact_auth)
redact_auth=redact_auth,
ignore_retcode=ignore_retcode)
if remote not in all_remotes:
raise CommandExecutionError(
'Remote \'{0}\' not present in git checkout located at {1}'
@ -2959,8 +2976,8 @@ def submodule(cwd,
opts='',
user=None,
identity=None,
init=False,
ignore_retcode=False):
ignore_retcode=False,
**kwargs):
'''
.. versionchanged:: 2015.8.0
Added the ``command`` argument to allow for operations other than
@ -3038,8 +3055,13 @@ def submodule(cwd,
# Unregister submodule (2015.8.0 and later)
salt myminion git.submodule /path/to/repo/sub/repo deinit
'''
kwargs = salt.utils.clean_kwargs(**kwargs)
init_ = kwargs.pop('init', False)
if kwargs:
salt.utils.invalid_kwargs(kwargs)
cwd = _expand_path(cwd, user)
if init:
if init_:
raise SaltInvocationError(
'The \'init\' argument is no longer supported. Either set '
'\'command\' to \'init\', or include \'--init\' in the \'opts\' '
@ -3178,14 +3200,14 @@ def version(versioninfo=False):
def worktree_add(cwd,
worktree_path,
branch=None,
ref=None,
reset_branch=None,
force=None,
detach=False,
opts='',
user=None,
ignore_retcode=False):
ignore_retcode=False,
**kwargs):
'''
.. versionadded:: 2015.8.0
@ -3254,8 +3276,13 @@ def worktree_add(cwd,
salt myminion git.worktree_add /path/to/repo/main ../hotfix ref=origin/master
salt myminion git.worktree_add /path/to/repo/main ../hotfix branch=hotfix21 ref=v2.1.9.3
'''
kwargs = salt.utils.clean_kwargs(**kwargs)
branch_ = kwargs.pop('branch', None)
if kwargs:
salt.utils.invalid_kwargs(kwargs)
cwd = _expand_path(cwd, user)
if branch and detach:
if branch_ and detach:
raise SaltInvocationError(
'Only one of \'branch\' and \'detach\' is allowed'
)
@ -3269,9 +3296,9 @@ def worktree_add(cwd,
)
command.append('--detach')
else:
if not branch:
branch = os.path.basename(worktree_path)
command.extend(['-B' if reset_branch else '-b', branch])
if not branch_:
branch_ = os.path.basename(worktree_path)
command.extend(['-B' if reset_branch else '-b', branch_])
if force:
command.append('--force')
command.extend(_format_opts(opts))

View File

@ -1584,10 +1584,11 @@ def config_unset(name,
all : False
If ``True``, unset all matches
repo : None
An optional location of a git repository for local operations
repo
Location of the git repository for which the config value should be
set. Required unless ``global`` is set to ``True``.
user : None
user
Optional name of a user as whom `git config` will be run
global : False
@ -1659,11 +1660,12 @@ def config_unset(name,
# Get matching keys/values
pre_matches = __salt__['git.config_get_regexp'](
cwd='global' if global_ else repo,
cwd=repo,
key=key,
value_regex=value_regex,
user=user,
ignore_retcode=True
ignore_retcode=True,
**{'global': global_}
)
if not pre_matches:
@ -1706,11 +1708,12 @@ def config_unset(name,
# Get all keys matching the key expression, so we can accurately report
# on changes made.
pre = __salt__['git.config_get_regexp'](
cwd='global' if global_ else repo,
cwd=repo,
key=key,
value_regex=None,
user=user,
ignore_retcode=True
ignore_retcode=True,
**{'global': global_}
)
failed = []
@ -1719,11 +1722,12 @@ def config_unset(name,
for key_name in pre_matches:
try:
__salt__['git.config_unset'](
cwd='global' if global_ else repo,
cwd=repo,
key=name,
value_regex=value_regex,
all=all_,
user=user
user=user,
**{'global': global_}
)
except CommandExecutionError as exc:
msg = 'Failed to unset \'{0}\''.format(key_name)
@ -1741,11 +1745,12 @@ def config_unset(name,
)
post = __salt__['git.config_get_regexp'](
cwd='global' if global_ else repo,
cwd=repo,
key=key,
value_regex=None,
user=user,
ignore_retcode=True
ignore_retcode=True,
**{'global': global_}
)
for key_name, values in six.iteritems(pre):
@ -1759,11 +1764,12 @@ def config_unset(name,
post_matches = post
else:
post_matches = __salt__['git.config_get_regexp'](
cwd='global' if global_ else repo,
cwd=repo,
key=key,
value_regex=value_regex,
user=user,
ignore_retcode=True
ignore_retcode=True,
**{'global': global_}
)
if post_matches:
@ -1809,10 +1815,11 @@ def config_set(name,
.. versionadded:: 2015.8.0
repo : None
An optional location of a git repository for local operations
repo
Location of the git repository for which the config value should be
set. Required unless ``global`` is set to ``True``.
user : None
user
Optional name of a user as whom `git config` will be run
global : False
@ -1920,11 +1927,11 @@ def config_set(name,
# Get current value
pre = __salt__['git.config_get'](
cwd='global' if global_ else repo,
cwd=repo,
key=name,
user=user,
ignore_retcode=True,
**{'all': True}
**{'all': True, 'global': global_}
)
if desired == pre:
@ -1948,11 +1955,12 @@ def config_set(name,
try:
# Set/update config value
post = __salt__['git.config_set'](
cwd='global' if global_ else repo,
cwd=repo,
key=name,
value=value,
multivar=multivar,
user=user
user=user,
**{'global': global_}
)
except CommandExecutionError as exc:
return _fail(