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:
Thomas S Hatch 2014-11-18 17:14:43 -07:00
commit 873d1c1803
4 changed files with 83 additions and 1 deletions

View File

@ -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)

View 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)

View File

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
# Import Python Libs
from distutils.version import LooseVersion

View File

@ -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