Skip to content

Commit e13b207

Browse files
committed
make git.config_get behave more like dict.get
previously, calling git.config_get with an invalid key would throw a CommandFailed exception. This commit modifies config_get so that it will return a configurable default value (None by default) if it cannot look up the requested configuration key. Change-Id: I07b8b684b7d3cf3c4c50a00328e533e69c91822c
1 parent f19034b commit e13b207

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

rdopkg/utils/cmd.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,16 @@ def get_file_content(self, rev, path):
301301
obj = '%s:%s' % (rev, path)
302302
return self('show', obj, log_cmd=False)
303303

304-
def config_get(self, param):
305-
return self("config", "--get", param)
304+
def config_get(self, param, default=None):
305+
'''Return the value of a git configuration option. This will
306+
return the value of the default parameter (which defaults to
307+
None) if the given option does not exist.'''
308+
309+
try:
310+
return self("config", "--get", param,
311+
log_fail=False, log_cmd=False)
312+
except exception.CommandFailed:
313+
return default
306314

307315
def config_set(self, param, value, is_global=False):
308316
params = [param, value]

0 commit comments

Comments
 (0)