diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-04-22 08:51:29 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-04-22 08:56:18 +0200 |
commit | b9a2ea80aa9970bbd625da4c986d29a36c405629 (patch) | |
tree | 6028c31e0722e76d9a4623cc6a305776860fb5af /git/test/test_config.py | |
parent | e39c8b07d1c98ddf267fbc69649ecbbe043de0fd (diff) | |
download | gitpython-b9a2ea80aa9970bbd625da4c986d29a36c405629.tar.gz |
fix(config): selective cfg write;fix cfg parser
* config parser now handles quoted values correctly. This doesn't hamper
multi-line support.
* added regression test to travis to assure we will be warned if we
rewrite and break the user's .gitconfig file
* only rewrite configuration files if we actually called a mutating
method on the writer. Previously it would always rewrite it.
Fixes #285
Diffstat (limited to 'git/test/test_config.py')
-rw-r--r-- | git/test/test_config.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/git/test/test_config.py b/git/test/test_config.py index fc2b87b6..7758a094 100644 --- a/git/test/test_config.py +++ b/git/test/test_config.py @@ -18,7 +18,6 @@ from git.compat import ( ) import io import os -from copy import copy from git.config import cp @@ -30,21 +29,18 @@ class TestBase(TestCase): sio.name = file_path return sio - def _parsers_equal_or_raise(self, lhs, rhs): - pass - def test_read_write(self): # writer must create the exact same file as the one read before for filename in ("git_config", "git_config_global"): file_obj = self._to_memcache(fixture_path(filename)) - file_obj_orig = copy(file_obj) w_config = GitConfigParser(file_obj, read_only=False) w_config.read() # enforce reading assert w_config._sections w_config.write() # enforce writing # we stripped lines when reading, so the results differ - assert file_obj.getvalue() and file_obj.getvalue() != file_obj_orig.getvalue() + assert file_obj.getvalue() + self.assertEqual(file_obj.getvalue(), self._to_memcache(fixture_path(filename)).getvalue()) # creating an additional config writer must fail due to exclusive access self.failUnlessRaises(IOError, GitConfigParser, file_obj, read_only=False) @@ -207,3 +203,10 @@ class TestBase(TestCase): assert not cw.has_section('core') assert len(cw.items(nn)) == 4 cw.release() + + def test_complex_aliases(self): + file_obj = self._to_memcache(fixture_path('.gitconfig')) + w_config = GitConfigParser(file_obj, read_only=False) + self.assertEqual(w_config.get('alias', 'rbi'), '"!g() { git rebase -i origin/${1:-master} ; } ; g"') + w_config.release() + self.assertEqual(file_obj.getvalue(), self._to_memcache(fixture_path('.gitconfig')).getvalue()) |