from bup.helpers import *
from wvtest import *
+bup_tmp = os.path.realpath('../../../t/tmp')
+mkdirp(bup_tmp)
@wvtest
def testmangle():
@wvtest
def testpacks():
- subprocess.call(['rm','-rf', 'pybuptest.tmp'])
- git.init_repo('pybuptest.tmp')
+ initial_failures = wvfailure_count()
+ tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tgit-')
+ os.environ['BUP_MAIN_EXE'] = bupmain = '../../../bup'
+ os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup"
+ git.init_repo(bupdir)
git.verbose = 1
w = git.PackWriter()
w.new_blob(os.urandom(100))
w.new_blob(os.urandom(100))
w.abort()
-
+
w = git.PackWriter()
hashes = []
nobj = 1000
WVFAIL(r.find_offset('\0'*20))
- r = git.PackIdxList('pybuptest.tmp/objects/pack')
+ r = git.PackIdxList(bupdir + '/objects/pack')
WVPASS(r.exists(hashes[5]))
WVPASS(r.exists(hashes[6]))
WVFAIL(r.exists('\0'*20))
-
+ if wvfailure_count() == initial_failures:
+ subprocess.call(['rm', '-rf', tmpdir])
@wvtest
def test_pack_name_lookup():
+ initial_failures = wvfailure_count()
+ tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tgit-')
os.environ['BUP_MAIN_EXE'] = bupmain = '../../../bup'
- os.environ['BUP_DIR'] = bupdir = 'pybuptest.tmp'
- subprocess.call(['rm','-rf', bupdir])
+ os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup"
git.init_repo(bupdir)
git.verbose = 1
packdir = git.repo('objects/pack')
for e,idxname in enumerate(idxnames):
for i in range(e*2, (e+1)*2):
WVPASSEQ(r.exists(hashes[i], want_source=True), idxname)
+ if wvfailure_count() == initial_failures:
+ subprocess.call(['rm', '-rf', tmpdir])
@wvtest
def test_long_index():
+ initial_failures = wvfailure_count()
+ tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tgit-')
+ os.environ['BUP_MAIN_EXE'] = bupmain = '../../../bup'
+ os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup"
+ git.init_repo(bupdir)
w = git.PackWriter()
obj_bin = struct.pack('!IIIII',
0x00112233, 0x44556677, 0x88990011, 0x22334455, 0x66778899)
WVPASSEQ(i.find_offset(obj_bin), 0xfffffffff)
WVPASSEQ(i.find_offset(obj2_bin), 0xffffffffff)
WVPASSEQ(i.find_offset(obj3_bin), 0xff)
- os.remove(name)
+ if wvfailure_count() == initial_failures:
+ os.remove(name)
+ subprocess.call(['rm', '-rf', tmpdir])
+
+@wvtest
+def test_check_repo_or_die():
+ initial_failures = wvfailure_count()
+ orig_cwd = os.getcwd()
+ tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tgit-')
+ os.environ['BUP_DIR'] = bupdir = tmpdir + "/bup"
+ try:
+ os.chdir(tmpdir)
+ git.init_repo(bupdir)
+ git.check_repo_or_die()
+ WVPASS('check_repo_or_die') # if we reach this point the call above passed
+
+ os.rename(bupdir + '/objects/pack', bupdir + '/objects/pack.tmp')
+ open(bupdir + '/objects/pack', 'w').close()
+ try:
+ git.check_repo_or_die()
+ except SystemExit, e:
+ WVPASSEQ(e.code, 14)
+ else:
+ WVFAIL()
+ os.unlink(bupdir + '/objects/pack')
+ os.rename(bupdir + '/objects/pack.tmp', bupdir + '/objects/pack')
+
+ try:
+ git.check_repo_or_die('nonexistantbup.tmp')
+ except SystemExit, e:
+ WVPASSEQ(e.code, 15)
+ else:
+ WVFAIL()
+ finally:
+ os.chdir(orig_cwd)
+ if wvfailure_count() == initial_failures:
+ subprocess.call(['rm', '-rf', tmpdir])
+
+
+@wvtest
+def test_commit_parsing():
+ def showval(commit, val):
+ return readpipe(['git', 'show', '-s',
+ '--pretty=format:%s' % val, commit]).strip()
+ initial_failures = wvfailure_count()
+ orig_cwd = os.getcwd()
+ tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tgit-')
+ workdir = tmpdir + "/work"
+ repodir = workdir + '/.git'
+ try:
+ readpipe(['git', 'init', workdir])
+ os.environ['GIT_DIR'] = os.environ['BUP_DIR'] = repodir
+ git.check_repo_or_die(repodir)
+ os.chdir(workdir)
+ with open('foo', 'w') as f:
+ print >> f, 'bar'
+ readpipe(['git', 'add', '.'])
+ readpipe(['git', 'commit', '-am', 'Do something',
+ '--author', 'Someone <someone@somewhere>',
+ '--date', 'Sat Oct 3 19:48:49 2009 -0400'])
+ commit = readpipe(['git', 'show-ref', '-s', 'master']).strip()
+ parents = showval(commit, '%P')
+ tree = showval(commit, '%T')
+ cname = showval(commit, '%cn')
+ cmail = showval(commit, '%ce')
+ cdate = showval(commit, '%ct')
+ coffs = showval(commit, '%ci')
+ coffs = coffs[-5:]
+ coff = (int(coffs[-4:-2]) * 60 * 60) + (int(coffs[-2:]) * 60)
+ if coffs[-5] == '-':
+ coff = - coff
+ commit_items = git.get_commit_items(commit, git.cp())
+ WVPASSEQ(commit_items.parents, [])
+ WVPASSEQ(commit_items.tree, tree)
+ WVPASSEQ(commit_items.author_name, 'Someone')
+ WVPASSEQ(commit_items.author_mail, 'someone@somewhere')
+ WVPASSEQ(commit_items.author_sec, 1254613729)
+ WVPASSEQ(commit_items.author_offset, -(4 * 60 * 60))
+ WVPASSEQ(commit_items.committer_name, cname)
+ WVPASSEQ(commit_items.committer_mail, cmail)
+ WVPASSEQ(commit_items.committer_sec, int(cdate))
+ WVPASSEQ(commit_items.committer_offset, coff)
+ WVPASSEQ(commit_items.message, 'Do something\n')
+ with open('bar', 'w') as f:
+ print >> f, 'baz'
+ readpipe(['git', 'add', '.'])
+ readpipe(['git', 'commit', '-am', 'Do something else'])
+ child = readpipe(['git', 'show-ref', '-s', 'master']).strip()
+ parents = showval(child, '%P')
+ commit_items = git.get_commit_items(child, git.cp())
+ WVPASSEQ(commit_items.parents, [commit])
+ finally:
+ os.chdir(orig_cwd)
+ if wvfailure_count() == initial_failures:
+ subprocess.call(['rm', '-rf', tmpdir])