import sys
from binascii import hexlify, unhexlify
from subprocess import check_call
-import struct, os, time
+from functools import partial
+import struct, os
import pytest
from wvpytest import *
def test_encode():
s = b'hello world'
- looseb = b''.join(git._encode_looseobj(b'blob', s))
- looset = b''.join(git._encode_looseobj(b'tree', s))
- loosec = b''.join(git._encode_looseobj(b'commit', s))
packb = b''.join(git._encode_packobj(b'blob', s))
packt = b''.join(git._encode_packobj(b'tree', s))
packc = b''.join(git._encode_packobj(b'commit', s))
packlb = b''.join(git._encode_packobj(b'blob', s * 200))
- WVPASSEQ(git._decode_looseobj(looseb), (b'blob', s))
- WVPASSEQ(git._decode_looseobj(looset), (b'tree', s))
- WVPASSEQ(git._decode_looseobj(loosec), (b'commit', s))
WVPASSEQ(git._decode_packobj(packb), (b'blob', s))
WVPASSEQ(git._decode_packobj(packt), (b'tree', s))
WVPASSEQ(git._decode_packobj(packc), (b'commit', s))
WVPASSEQ(git._decode_packobj(packlb), (b'blob', s * 200))
- for i in range(10):
- WVPASS(git._encode_looseobj(b'blob', s, compression_level=i))
def encode_pobj(n):
return b''.join(git._encode_packobj(b'blob', s, compression_level=n))
WVEXCEPT(ValueError, encode_pobj, -1)
environ[b'GIT_AUTHOR_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
environ[b'GIT_COMMITTER_EMAIL'] = environ[b'GIT_AUTHOR_EMAIL']
try:
- readpipe([b'git', b'init', workdir])
environ[b'GIT_DIR'] = environ[b'BUP_DIR'] = repodir
+ readpipe([b'git', b'init', workdir])
+ exc(b'git', b'symbolic-ref', b'HEAD', b'refs/heads/main')
git.check_repo_or_die(repodir)
os.chdir(workdir)
with open('foo', 'w') as f:
readpipe([b'git', b'commit', b'-am', b'Do something',
b'--author', b'Someone <someone@somewhere>',
b'--date', b'Sat Oct 3 19:48:49 2009 -0400'])
- commit = readpipe([b'git', b'show-ref', b'-s', b'master']).strip()
+ commit = readpipe([b'git', b'show-ref', b'-s', b'main']).strip()
parents = showval(commit, b'%P')
tree = showval(commit, b'%T')
cname = showval(commit, b'%cn')
f.write(b'baz\n')
readpipe([b'git', b'add', '.'])
readpipe([b'git', b'commit', b'-am', b'Do something else'])
- child = readpipe([b'git', b'show-ref', b'-s', b'master']).strip()
+ child = readpipe([b'git', b'show-ref', b'-s', b'main']).strip()
parents = showval(child, b'%P')
commit_items = git.get_commit_items(child, git.cp())
WVPASSEQ(commit_items.parents, [commit])
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'))