summaryrefslogtreecommitdiff
path: root/git/config.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-01-19 16:57:11 +0100
committerSebastian Thiel <byronimo@gmail.com>2015-01-19 16:57:11 +0100
commit20863cfe4a1b0c5bea18677470a969073570e41c (patch)
tree3e64226fb902a4558ba1765f7f4fa6d4cc8a2524 /git/config.py
parenta223c7b7730c53c3fa1e4c019bd3daefbb8fd74b (diff)
downloadgitpython-20863cfe4a1b0c5bea18677470a969073570e41c.tar.gz
Implemented Submodule.rename()
A test verifies it's truly working. Related to #238
Diffstat (limited to 'git/config.py')
-rw-r--r--git/config.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/git/config.py b/git/config.py
index 4c4cb491..f41a86e6 100644
--- a/git/config.py
+++ b/git/config.py
@@ -478,8 +478,6 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
if self.read_only:
raise IOError("Cannot execute non-constant method %s.%s" % (self, method_name))
- @needs_values
- @set_dirty_and_flush_changes
def add_section(self, section):
"""Assures added options will stay in order"""
return super(GitConfigParser, self).add_section(section)
@@ -546,3 +544,23 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
if not self.has_section(section):
self.add_section(section)
self.set(section, option, str(value))
+
+ def rename_section(self, section, new_name):
+ """rename the given section to new_name
+ :raise ValueError: if section doesn't exit
+ :raise ValueError: if a section with new_name does already exist
+ :return: this instance
+ """
+ if not self.has_section(section):
+ raise ValueError("Source section '%s' doesn't exist" % section)
+ if self.has_section(new_name):
+ raise ValueError("Destination section '%s' already exists" % new_name)
+
+ super(GitConfigParser, self).add_section(new_name)
+ for k, v in self.items(section):
+ self.set(new_name, k, str(v))
+ # end for each value to copy
+
+ # This call writes back the changes, which is why we don't have the respective decorator
+ self.remove_section(section)
+ return self