summaryrefslogtreecommitdiff
path: root/git/config.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-04-22 08:51:29 +0200
committerSebastian Thiel <byronimo@gmail.com>2015-04-22 08:56:18 +0200
commitb9a2ea80aa9970bbd625da4c986d29a36c405629 (patch)
tree6028c31e0722e76d9a4623cc6a305776860fb5af /git/config.py
parente39c8b07d1c98ddf267fbc69649ecbbe043de0fd (diff)
downloadgitpython-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/config.py')
-rw-r--r--git/config.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/git/config.py b/git/config.py
index 38dd1b44..a6a25c7b 100644
--- a/git/config.py
+++ b/git/config.py
@@ -81,6 +81,7 @@ def set_dirty_and_flush_changes(non_const_func):
def flush_changes(self, *args, **kwargs):
rval = non_const_func(self, *args, **kwargs)
+ self._dirty = True
self.write()
return rval
# END wrapper method
@@ -190,6 +191,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
self._file_or_files = file_or_files
self._read_only = read_only
+ self._dirty = False
self._is_initialized = False
self._merge_includes = merge_includes
self._lock = None
@@ -304,7 +306,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
if mo:
# We might just have handled the last line, which could contain a quotation we want to remove
optname, vi, optval = mo.group('option', 'vi', 'value')
- if vi in ('=', ':') and ';' in optval:
+ if vi in ('=', ':') and ';' in optval and not optval.strip().startswith('"'):
pos = optval.find(';')
if pos != -1 and optval[pos - 1].isspace():
optval = optval[:pos]
@@ -433,6 +435,8 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
:raise IOError: if this is a read-only writer instance or if we could not obtain
a file lock"""
self._assure_writable("write")
+ if not self._dirty:
+ return
if isinstance(self._file_or_files, (list, tuple)):
raise AssertionError("Cannot write back if there is not exactly a single file to write to, have %i files"