- with no_lingering_errors():
- with test_tempdir(b'bup-tgit-') as tmpdir:
- orig_cwd = os.getcwd()
- workdir = tmpdir + b'/work'
- repodir = workdir + b'/.git'
- orig_author_name = environ.get(b'GIT_AUTHOR_NAME')
- orig_author_email = environ.get(b'GIT_AUTHOR_EMAIL')
- orig_committer_name = environ.get(b'GIT_COMMITTER_NAME')
- orig_committer_email = environ.get(b'GIT_COMMITTER_EMAIL')
- environ[b'GIT_AUTHOR_NAME'] = b'bup test'
- environ[b'GIT_COMMITTER_NAME'] = environ[b'GIT_AUTHOR_NAME']
- 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
- git.check_repo_or_die(repodir)
- os.chdir(workdir)
- with open('foo', 'w') as f:
- print('bar', file=f)
- readpipe([b'git', b'add', b'.'])
- 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()
- parents = showval(commit, b'%P')
- tree = showval(commit, b'%T')
- cname = showval(commit, b'%cn')
- cmail = showval(commit, b'%ce')
- cdate = showval(commit, b'%ct')
- coffs = showval(commit, b'%ci')
- coffs = coffs[-5:]
- coff = (int(coffs[-4:-2]) * 60 * 60) + (int(coffs[-2:]) * 60)
- if bytes_from_byte(coffs[-5]) == b'-':
- 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, b'Someone')
- WVPASSEQ(commit_items.author_mail, b'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, b'Do something\n')
- with open(b'bar', 'wb') as f:
- 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()
- parents = showval(child, b'%P')
- commit_items = git.get_commit_items(child, git.cp())
- WVPASSEQ(commit_items.parents, [commit])
- finally:
- os.chdir(orig_cwd)
- restore_env_var(b'GIT_AUTHOR_NAME', orig_author_name)
- restore_env_var(b'GIT_AUTHOR_EMAIL', orig_author_email)
- restore_env_var(b'GIT_COMMITTER_NAME', orig_committer_name)
- restore_env_var(b'GIT_COMMITTER_EMAIL', orig_committer_email)
-
-
-@wvtest
-def test_new_commit():
- with no_lingering_errors():
- with test_tempdir(b'bup-tgit-') as tmpdir:
- environ[b'BUP_DIR'] = bupdir = tmpdir + b'/bup'
- git.init_repo(bupdir)
- git.verbose = 1
-
- w = git.PackWriter()
- tree = os.urandom(20)
- parent = os.urandom(20)
- author_name = b'Author'
- author_mail = b'author@somewhere'
- adate_sec = 1439657836
- cdate_sec = adate_sec + 1
- committer_name = b'Committer'
- committer_mail = b'committer@somewhere'
- adate_tz_sec = cdate_tz_sec = None
- commit = w.new_commit(tree, parent,
- b'%s <%s>' % (author_name, author_mail),
- adate_sec, adate_tz_sec,
- b'%s <%s>' % (committer_name, committer_mail),
- cdate_sec, cdate_tz_sec,
- b'There is a small mailbox here')
- adate_tz_sec = -60 * 60
- cdate_tz_sec = 120 * 60
- commit_off = w.new_commit(tree, parent,
- b'%s <%s>' % (author_name, author_mail),
- adate_sec, adate_tz_sec,
- b'%s <%s>' % (committer_name, committer_mail),
- cdate_sec, cdate_tz_sec,
- b'There is a small mailbox here')
- w.close()
-
- commit_items = git.get_commit_items(hexlify(commit), git.cp())
- local_author_offset = localtime(adate_sec).tm_gmtoff
- local_committer_offset = localtime(cdate_sec).tm_gmtoff
- WVPASSEQ(tree, unhexlify(commit_items.tree))
- WVPASSEQ(1, len(commit_items.parents))
- WVPASSEQ(parent, unhexlify(commit_items.parents[0]))
- WVPASSEQ(author_name, commit_items.author_name)
- WVPASSEQ(author_mail, commit_items.author_mail)
- WVPASSEQ(adate_sec, commit_items.author_sec)
- WVPASSEQ(local_author_offset, commit_items.author_offset)
- WVPASSEQ(committer_name, commit_items.committer_name)
- WVPASSEQ(committer_mail, commit_items.committer_mail)
- WVPASSEQ(cdate_sec, commit_items.committer_sec)
- WVPASSEQ(local_committer_offset, commit_items.committer_offset)
-
- commit_items = git.get_commit_items(hexlify(commit_off), git.cp())
- WVPASSEQ(tree, unhexlify(commit_items.tree))
- WVPASSEQ(1, len(commit_items.parents))
- WVPASSEQ(parent, unhexlify(commit_items.parents[0]))
- WVPASSEQ(author_name, commit_items.author_name)
- WVPASSEQ(author_mail, commit_items.author_mail)
- WVPASSEQ(adate_sec, commit_items.author_sec)
- WVPASSEQ(adate_tz_sec, commit_items.author_offset)
- WVPASSEQ(committer_name, commit_items.committer_name)
- WVPASSEQ(committer_mail, commit_items.committer_mail)
- WVPASSEQ(cdate_sec, commit_items.committer_sec)
- WVPASSEQ(cdate_tz_sec, commit_items.committer_offset)
-
-
-@wvtest
-def test_list_refs():
- with no_lingering_errors():
- with test_tempdir(b'bup-tgit-') as tmpdir:
- environ[b'BUP_DIR'] = bupdir = tmpdir + b'/bup'
- src = tmpdir + b'/src'
- mkdirp(src)
- with open(src + b'/1', 'wb+') as f:
- f.write(b'something\n')
- with open(src + b'/2', 'wb+') as f:
- f.write(b'something else\n')
- git.init_repo(bupdir)
- emptyset = frozenset()
- WVPASSEQ(frozenset(git.list_refs()), emptyset)
- WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset)
- WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), emptyset)
- exc(bup_exe, b'index', src)
- exc(bup_exe, b'save', b'-n', b'src', b'--strip', src)
- src_hash = exo(b'git', b'--git-dir', bupdir,
- b'rev-parse', b'src').strip().split(b'\n')
- assert(len(src_hash) == 1)
- src_hash = unhexlify(src_hash[0])
- tree_hash = unhexlify(exo(b'git', b'--git-dir', bupdir,
- b'rev-parse',
- b'src:').strip().split(b'\n')[0])
- blob_hash = unhexlify(exo(b'git', b'--git-dir', bupdir,
- b'rev-parse',
- b'src:1').strip().split(b'\n')[0])
- WVPASSEQ(frozenset(git.list_refs()),
- frozenset([(b'refs/heads/src', src_hash)]))
- WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset)
- WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)),
- frozenset([(b'refs/heads/src', src_hash)]))
- exc(b'git', b'--git-dir', bupdir, b'tag', b'commit-tag', b'src')
- WVPASSEQ(frozenset(git.list_refs()),
- frozenset([(b'refs/heads/src', src_hash),
- (b'refs/tags/commit-tag', src_hash)]))
- WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)),
- frozenset([(b'refs/tags/commit-tag', src_hash)]))
- WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)),
- frozenset([(b'refs/heads/src', src_hash)]))
- exc(b'git', b'--git-dir', bupdir, b'tag', b'tree-tag', b'src:')
- exc(b'git', b'--git-dir', bupdir, b'tag', b'blob-tag', b'src:1')
- os.unlink(bupdir + b'/refs/heads/src')
- expected_tags = frozenset([(b'refs/tags/commit-tag', src_hash),
- (b'refs/tags/tree-tag', tree_hash),
- (b'refs/tags/blob-tag', blob_hash)])
- WVPASSEQ(frozenset(git.list_refs()), expected_tags)
- WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([]))
- WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), expected_tags)
-
-
-@wvtest
-def test__git_date_str():
- with no_lingering_errors():
- WVPASSEQ(b'0 +0000', git._git_date_str(0, 0))
- WVPASSEQ(b'0 -0130', git._git_date_str(0, -90 * 60))
- WVPASSEQ(b'0 +0130', git._git_date_str(0, 90 * 60))
-
-
-@wvtest
-def test_cat_pipe():
- with no_lingering_errors():
- with test_tempdir(b'bup-tgit-') as tmpdir:
- environ[b'BUP_DIR'] = bupdir = tmpdir + b'/bup'
- src = tmpdir + b'/src'
- mkdirp(src)
- with open(src + b'/1', 'wb+') as f:
- f.write(b'something\n')
- with open(src + b'/2', 'wb+') as f:
- f.write(b'something else\n')
- git.init_repo(bupdir)
- exc(bup_exe, b'index', src)
- oidx = exo(bup_exe, b'save', b'-cn', b'src', b'--strip',
- src).strip()
- typ = exo(b'git', b'--git-dir', bupdir,
- b'cat-file', b'-t', b'src').strip()
- size = int(exo(b'git', b'--git-dir', bupdir,
- b'cat-file', b'-s', b'src'))
- it = git.cp().get(b'src')
- get_info = next(it)
- for buf in next(it):
- pass
- WVPASSEQ((oidx, typ, size), get_info)
+ orig_cwd = os.getcwd()
+ workdir = tmpdir + b'/work'
+ repodir = workdir + b'/.git'
+ orig_author_name = environ.get(b'GIT_AUTHOR_NAME')
+ orig_author_email = environ.get(b'GIT_AUTHOR_EMAIL')
+ orig_committer_name = environ.get(b'GIT_COMMITTER_NAME')
+ orig_committer_email = environ.get(b'GIT_COMMITTER_EMAIL')
+ environ[b'GIT_AUTHOR_NAME'] = b'bup test'
+ environ[b'GIT_COMMITTER_NAME'] = environ[b'GIT_AUTHOR_NAME']
+ 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
+ git.check_repo_or_die(repodir)
+ os.chdir(workdir)
+ with open('foo', 'w') as f:
+ print('bar', file=f)
+ readpipe([b'git', b'add', b'.'])
+ 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()
+ parents = showval(commit, b'%P')
+ tree = showval(commit, b'%T')
+ cname = showval(commit, b'%cn')
+ cmail = showval(commit, b'%ce')
+ cdate = showval(commit, b'%ct')
+ coffs = showval(commit, b'%ci')
+ coffs = coffs[-5:]
+ coff = (int(coffs[-4:-2]) * 60 * 60) + (int(coffs[-2:]) * 60)
+ if bytes_from_byte(coffs[-5]) == b'-':
+ 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, b'Someone')
+ WVPASSEQ(commit_items.author_mail, b'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, b'Do something\n')
+ with open(b'bar', 'wb') as f:
+ 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()
+ parents = showval(child, b'%P')
+ commit_items = git.get_commit_items(child, git.cp())
+ WVPASSEQ(commit_items.parents, [commit])
+ finally:
+ os.chdir(orig_cwd)
+ restore_env_var(b'GIT_AUTHOR_NAME', orig_author_name)
+ restore_env_var(b'GIT_AUTHOR_EMAIL', orig_author_email)
+ restore_env_var(b'GIT_COMMITTER_NAME', orig_committer_name)
+ restore_env_var(b'GIT_COMMITTER_EMAIL', orig_committer_email)
+
+
+def test_new_commit(tmpdir):
+ environ[b'BUP_DIR'] = bupdir = tmpdir + b'/bup'
+ git.init_repo(bupdir)
+ git.verbose = 1
+
+ w = git.PackWriter()
+ tree = os.urandom(20)
+ parent = os.urandom(20)
+ author_name = b'Author'
+ author_mail = b'author@somewhere'
+ adate_sec = 1439657836
+ cdate_sec = adate_sec + 1
+ committer_name = b'Committer'
+ committer_mail = b'committer@somewhere'
+ adate_tz_sec = cdate_tz_sec = None
+ commit = w.new_commit(tree, parent,
+ b'%s <%s>' % (author_name, author_mail),
+ adate_sec, adate_tz_sec,
+ b'%s <%s>' % (committer_name, committer_mail),
+ cdate_sec, cdate_tz_sec,
+ b'There is a small mailbox here')
+ adate_tz_sec = -60 * 60
+ cdate_tz_sec = 120 * 60
+ commit_off = w.new_commit(tree, parent,
+ b'%s <%s>' % (author_name, author_mail),
+ adate_sec, adate_tz_sec,
+ b'%s <%s>' % (committer_name, committer_mail),
+ cdate_sec, cdate_tz_sec,
+ b'There is a small mailbox here')
+ w.close()
+
+ commit_items = git.get_commit_items(hexlify(commit), git.cp())
+ local_author_offset = localtime(adate_sec).tm_gmtoff
+ local_committer_offset = localtime(cdate_sec).tm_gmtoff
+ WVPASSEQ(tree, unhexlify(commit_items.tree))
+ WVPASSEQ(1, len(commit_items.parents))
+ WVPASSEQ(parent, unhexlify(commit_items.parents[0]))
+ WVPASSEQ(author_name, commit_items.author_name)
+ WVPASSEQ(author_mail, commit_items.author_mail)
+ WVPASSEQ(adate_sec, commit_items.author_sec)
+ WVPASSEQ(local_author_offset, commit_items.author_offset)
+ WVPASSEQ(committer_name, commit_items.committer_name)
+ WVPASSEQ(committer_mail, commit_items.committer_mail)
+ WVPASSEQ(cdate_sec, commit_items.committer_sec)
+ WVPASSEQ(local_committer_offset, commit_items.committer_offset)
+
+ commit_items = git.get_commit_items(hexlify(commit_off), git.cp())
+ WVPASSEQ(tree, unhexlify(commit_items.tree))
+ WVPASSEQ(1, len(commit_items.parents))
+ WVPASSEQ(parent, unhexlify(commit_items.parents[0]))
+ WVPASSEQ(author_name, commit_items.author_name)
+ WVPASSEQ(author_mail, commit_items.author_mail)
+ WVPASSEQ(adate_sec, commit_items.author_sec)
+ WVPASSEQ(adate_tz_sec, commit_items.author_offset)
+ WVPASSEQ(committer_name, commit_items.committer_name)
+ WVPASSEQ(committer_mail, commit_items.committer_mail)
+ WVPASSEQ(cdate_sec, commit_items.committer_sec)
+ WVPASSEQ(cdate_tz_sec, commit_items.committer_offset)
+
+
+def test_list_refs(tmpdir):
+ environ[b'BUP_DIR'] = bupdir = tmpdir + b'/bup'
+ src = tmpdir + b'/src'
+ mkdirp(src)
+ with open(src + b'/1', 'wb+') as f:
+ f.write(b'something\n')
+ with open(src + b'/2', 'wb+') as f:
+ f.write(b'something else\n')
+ git.init_repo(bupdir)
+ emptyset = frozenset()
+ WVPASSEQ(frozenset(git.list_refs()), emptyset)
+ WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset)
+ WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), emptyset)
+ exc(bup_exe, b'index', src)
+ exc(bup_exe, b'save', b'-n', b'src', b'--strip', src)
+ src_hash = exo(b'git', b'--git-dir', bupdir,
+ b'rev-parse', b'src').strip().split(b'\n')
+ assert(len(src_hash) == 1)
+ src_hash = unhexlify(src_hash[0])
+ tree_hash = unhexlify(exo(b'git', b'--git-dir', bupdir,
+ b'rev-parse',
+ b'src:').strip().split(b'\n')[0])
+ blob_hash = unhexlify(exo(b'git', b'--git-dir', bupdir,
+ b'rev-parse',
+ b'src:1').strip().split(b'\n')[0])
+ WVPASSEQ(frozenset(git.list_refs()),
+ frozenset([(b'refs/heads/src', src_hash)]))
+ WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), emptyset)
+ WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)),
+ frozenset([(b'refs/heads/src', src_hash)]))
+ exc(b'git', b'--git-dir', bupdir, b'tag', b'commit-tag', b'src')
+ WVPASSEQ(frozenset(git.list_refs()),
+ frozenset([(b'refs/heads/src', src_hash),
+ (b'refs/tags/commit-tag', src_hash)]))
+ WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)),
+ frozenset([(b'refs/tags/commit-tag', src_hash)]))
+ WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)),
+ frozenset([(b'refs/heads/src', src_hash)]))
+ exc(b'git', b'--git-dir', bupdir, b'tag', b'tree-tag', b'src:')
+ exc(b'git', b'--git-dir', bupdir, b'tag', b'blob-tag', b'src:1')
+ os.unlink(bupdir + b'/refs/heads/src')
+ expected_tags = frozenset([(b'refs/tags/commit-tag', src_hash),
+ (b'refs/tags/tree-tag', tree_hash),
+ (b'refs/tags/blob-tag', blob_hash)])
+ WVPASSEQ(frozenset(git.list_refs()), expected_tags)
+ WVPASSEQ(frozenset(git.list_refs(limit_to_heads=True)), frozenset([]))
+ WVPASSEQ(frozenset(git.list_refs(limit_to_tags=True)), expected_tags)
+
+
+def test_git_date_str():
+ WVPASSEQ(b'0 +0000', git._git_date_str(0, 0))
+ WVPASSEQ(b'0 -0130', git._git_date_str(0, -90 * 60))
+ WVPASSEQ(b'0 +0130', git._git_date_str(0, 90 * 60))
+
+
+def test_cat_pipe(tmpdir):
+ environ[b'BUP_DIR'] = bupdir = tmpdir + b'/bup'
+ src = tmpdir + b'/src'
+ mkdirp(src)
+ with open(src + b'/1', 'wb+') as f:
+ f.write(b'something\n')
+ with open(src + b'/2', 'wb+') as f:
+ f.write(b'something else\n')
+ git.init_repo(bupdir)
+ exc(bup_exe, b'index', src)
+ oidx = exo(bup_exe, b'save', b'-cn', b'src', b'--strip',
+ src).strip()
+ typ = exo(b'git', b'--git-dir', bupdir,
+ b'cat-file', b'-t', b'src').strip()
+ size = int(exo(b'git', b'--git-dir', bupdir,
+ b'cat-file', b'-s', b'src'))
+ it = git.cp().get(b'src')
+ get_info = next(it)
+ for buf in next(it):
+ pass
+ WVPASSEQ((oidx, typ, size), get_info)