raise GitError('%r returned %d' % (cmd, proc.returncode))
return result
-def git_config_get(option, repo_dir=None, opttype=None):
+def git_config_get(option, repo_dir=None, opttype=None, cfg_file=None):
+ assert not (repo_dir and cfg_file), "repo_dir and cfg_file cannot both be used"
cmd = [b'git', b'config', b'--null']
+ if cfg_file:
+ cmd.extend([b'--file', cfg_file])
if opttype == 'int':
cmd.extend([b'--int'])
elif opttype == 'bool':
import sys
from binascii import hexlify, unhexlify
from subprocess import check_call
+from functools import partial
import struct, os, time
import pytest
continue
# check that we don't have it open anymore
WVPASSEQ(False, b'deleted' in fn)
+
+def test_config():
+ cfg_file = os.path.join(os.path.dirname(__file__), 'sample.conf')
+ no_such_file = os.path.join(os.path.dirname(__file__), 'nosuch.conf')
+ git_config_get = partial(git.git_config_get, cfg_file=cfg_file)
+ WVPASSEQ(git_config_get(b'bup.foo'), b'bar')
+ WVPASSEQ(git_config_get(b'bup.bup'), b'is great')
+ WVPASSEQ(git_config_get(b'bup.end'), b'end')
+ WVPASSEQ(git_config_get(b'bup.comments'), None)
+ WVPASSEQ(git_config_get(b'bup.;comments'), None)
+ WVPASSEQ(git_config_get(b'bup.and'), None)
+ WVPASSEQ(git_config_get(b'bup.#and'), None)
+
+ WVPASSEQ(git.git_config_get(b'bup.foo', cfg_file=no_such_file), None)
+
+ WVEXCEPT(git.GitError, git_config_get, b'bup.isbad', opttype='bool')
+ WVEXCEPT(git.GitError, git_config_get, b'bup.isbad', opttype='int')
+ WVPASSEQ(git_config_get(b'bup.isbad'), b'ok')
+ WVPASSEQ(True, git_config_get(b'bup.istrue1', opttype='bool'))
+ WVPASSEQ(True, git_config_get(b'bup.istrue2', opttype='bool'))
+ WVPASSEQ(True, git_config_get(b'bup.istrue3', opttype='bool'))
+ WVPASSEQ(False, git_config_get(b'bup.isfalse1', opttype='bool'))
+ WVPASSEQ(False, git_config_get(b'bup.isfalse2', opttype='bool'))
+ WVPASSEQ(None, git_config_get(b'bup.nosuchkey', opttype='bool'))
+ WVPASSEQ(1, git_config_get(b'bup.istrue1', opttype='int'))
+ WVPASSEQ(2, git_config_get(b'bup.istrue2', opttype='int'))
+ WVPASSEQ(0, git_config_get(b'bup.isfalse2', opttype='int'))
+ WVPASSEQ(0x777, git_config_get(b'bup.hex', opttype='int'))