mirror of
https://github.com/valitydev/salt.git
synced 2024-11-06 08:35:21 +00:00
Merge pull request #18221 from multani/fix/git-config-set-shell-escape
Fix Git's config set with values containing white spaces.
This commit is contained in:
commit
873d1c1803
@ -842,7 +842,7 @@ def config_set(cwd=None, setting_name=None, setting_value=None, user=None, is_gl
|
||||
|
||||
_check_git()
|
||||
|
||||
return _git_run('git config {0} {1} {2}'.format(scope, setting_name, setting_value),
|
||||
return _git_run('git config {0} {1} "{2}"'.format(scope, setting_name, setting_value),
|
||||
cwd=cwd, runas=user)
|
||||
|
||||
|
||||
|
49
tests/integration/modules/git.py
Normal file
49
tests/integration/modules/git.py
Normal file
@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
# Import salt libs
|
||||
import integration
|
||||
|
||||
|
||||
class GitModuleTest(integration.ModuleCase):
|
||||
@classmethod
|
||||
def setUpClass(self):
|
||||
from salt.utils import which
|
||||
git = which('git')
|
||||
if not git:
|
||||
self.skipTest('The git binary is not available')
|
||||
|
||||
|
||||
def setUp(self):
|
||||
self.repos = tempfile.mkdtemp(dir=integration.TMP)
|
||||
self.addCleanup(shutil.rmtree, self.repos, ignore_errors=True)
|
||||
subprocess.check_call(['git', 'init', '--quiet', self.repos])
|
||||
|
||||
|
||||
def test_config_set_value_has_space_characters(self):
|
||||
'''
|
||||
git.config_set
|
||||
'''
|
||||
config_key = "user.name"
|
||||
config_value = "foo bar"
|
||||
|
||||
ret = self.run_function(
|
||||
'git.config_set',
|
||||
cwd=self.repos,
|
||||
setting_name=config_key,
|
||||
setting_value=config_value,
|
||||
)
|
||||
self.assertEqual("", ret)
|
||||
|
||||
output = subprocess.check_output(
|
||||
['git', 'config', '--local', config_key],
|
||||
cwd=self.repos)
|
||||
|
||||
self.assertEqual(config_value + "\n", output)
|
@ -1,5 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Python Libs
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
|
@ -8,6 +8,8 @@ Tests for the Git state
|
||||
import os
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
@ -186,6 +188,35 @@ class GitTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
||||
finally:
|
||||
shutil.rmtree(name, ignore_errors=True)
|
||||
|
||||
def test_config_set_value_with_space_character(self):
|
||||
'''
|
||||
git.config
|
||||
'''
|
||||
from salt.utils import which
|
||||
git = which('git')
|
||||
if not git:
|
||||
self.skipTest('The git binary is not available')
|
||||
|
||||
name = tempfile.mkdtemp(dir=integration.TMP)
|
||||
self.addCleanup(shutil.rmtree, name, ignore_errors=True)
|
||||
subprocess.check_call(['git', 'init', '--quiet', name])
|
||||
|
||||
config_key = 'user.name'
|
||||
config_value = 'foo bar'
|
||||
|
||||
ret = self.run_state(
|
||||
'git.config',
|
||||
name=config_key,
|
||||
value=config_value,
|
||||
repo=name,
|
||||
is_global=False)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
output = subprocess.check_output(
|
||||
['git', 'config', '--local', config_key],
|
||||
cwd=name)
|
||||
self.assertEqual(config_value + "\n", output)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
Loading…
Reference in New Issue
Block a user