def test_ls_tree_children_true(): tmp = maketemp() commands.init_bare(tmp) commands.fast_import( repo=tmp, commits=[ dict( message='one', committer='John Doe <*****@*****.**>', commit_time='1216235872 +0300', files=[ dict( path='quux/foo', content='FOO', ), dict( path='bar', content='BAR', mode='100755', ), ], ), ], ) g = commands.ls_tree(repo=tmp, path='quux', children=True) eq( g.next(), dict( type='blob', mode='100644', object='d96c7efbfec2814ae0301ad054dc8d9fc416c9b5', path='quux/foo', ), ) assert_raises(StopIteration, g.next)
def test_ls_tree_children_false(): tmp = maketemp() commands.init_bare(tmp) commands.fast_import( repo=tmp, commits=[ dict( message='one', committer='John Doe <*****@*****.**>', commit_time='1216235872 +0300', files=[ dict( path='quux/foo', content='FOO', ), dict( path='bar', content='BAR', mode='100755', ), ], ), ], ) g = commands.ls_tree(repo=tmp, path='quux', children=False) eq( g.next(), dict( mode='040000', type='tree', object='d513b699a47153aad2f0cb7ea2cb9fde8c177428', path='quux', ), ) assert_raises(StopIteration, g.next)
def test_for_each_ref_sort(): tmp = maketemp() commands.init_bare(tmp) commands.fast_import( repo=tmp, commits=[ dict( message='one', committer='John Doe <*****@*****.**>', commit_time='1216235872 +0300', files=[ dict( path='foo', content='FOO', ), ], ), ], ) commands.update_ref( repo=tmp, ref='refs/heads/quux', newvalue='HEAD', oldvalue=40*'0', ) got = commands.for_each_ref( repo=tmp, sort='-refname', ) got = iter(got) eq(got.next(), dict(refname='refs/heads/quux')) eq(got.next(), dict(refname='refs/heads/master')) assert_raises(StopIteration, got.next)
def test_ls_files(): tmp = maketemp() repo = os.path.join(tmp, 'repo') os.mkdir(repo) commands.init_bare(repo) index = os.path.join(tmp, 'index') commands.fast_import( repo=repo, commits=[ dict( message='one', committer='John Doe <*****@*****.**>', commit_time='1216235872 +0300', files=[ dict( path='quux/foo', content='FOO', ), dict( path='bar', content='BAR', mode='100755', ), ], ), ], ) commands.read_tree( repo=repo, treeish='HEAD', index=index, ) g = commands.ls_files( repo=repo, index=index, ) eq( g.next(), dict( mode='100755', object='add8373108657cb230a5379a6fcdaab73f330642', path='bar', ), ) eq( g.next(), dict( mode='100644', object='d96c7efbfec2814ae0301ad054dc8d9fc416c9b5', path='quux/foo', ), ) assert_raises(StopIteration, g.next)
def test_write_tree(): tmp = maketemp() repo = os.path.join(tmp, 'repo') os.mkdir(repo) commands.init_bare(repo) index = os.path.join(tmp, 'index') sha_foo = commands.write_object(repo=repo, content='FOO') sha_bar = commands.write_object(repo=repo, content='BAR') commands.update_index( repo=repo, index=index, files=[ dict( object=sha_foo, path='quux/foo', ), dict( object=sha_bar, path='bar', ), ], ) tree = commands.write_tree( repo=repo, index=index, ) eq(tree, 'e8abc9dd8c483a4e27598521674ae7a357d2c825') g = commands.ls_tree(repo=repo, treeish=tree) eq( g.next(), dict( mode='100644', type='blob', object='add8373108657cb230a5379a6fcdaab73f330642', path='bar', ), ) eq( g.next(), dict( mode='040000', type='tree', object='d513b699a47153aad2f0cb7ea2cb9fde8c177428', path='quux', ), ) assert_raises(StopIteration, g.next)
def test_update_ref_oldvalue_bad(): tmp = maketemp() commands.init_bare(tmp) commands.fast_import( repo=tmp, commits=[ dict( message='one', committer='John Doe <*****@*****.**>', commit_time='1216235872 +0300', files=[ dict( path='foo', content='FOO', ), ], ), ], ) head = commands.rev_parse(repo=tmp, rev='HEAD') eq(head, 'e1b2f3253b18e7bdbd38db0cf295e6b3b608bb27') e = assert_raises( # TODO better exception for this RuntimeError, commands.update_ref, repo=tmp, ref='HEAD', newvalue=head, oldvalue='deadbeefdeadbeefdeadbeefdeadbeefdeadbeef', ) eq(str(e), 'git update-ref failed') got = commands.rev_parse(repo=tmp, rev='HEAD') eq(got, head)
def test_rev_list_reverse(): tmp = maketemp() commands.init_bare(tmp) commands.fast_import( repo=tmp, commits=[ dict( message='one', committer='John Doe <*****@*****.**>', commit_time='1216235872 +0300', files=[ dict( path='foo', content='FOO', ), ], ), dict( message='two', committer='Jack Smith <*****@*****.**>', commit_time='1216235940 +0300', files=[ dict( path='foo', content='FOO', ), dict( path='bar', content='BAR', ), ], ), ], ) got = commands.rev_list( repo=tmp, reverse=True, ) got = iter(got) eq(got.next(), 'e1b2f3253b18e7bdbd38db0cf295e6b3b608bb27') eq(got.next(), '27f952fd48ce824454457b9f28bb97091bc5422e') assert_raises(StopIteration, got.next)
def test_symbolic_ref_bad_nonsymbolic(): tmp = maketemp() commands.init_bare(tmp) e = assert_raises( # TODO better exception for this RuntimeError, commands.get_symbolic_ref, repo=tmp, ref='refs/heads/master', ) eq(str(e), 'git symbolic-ref failed')
def test_get_object_size_bad_notfound(): tmp = maketemp() commands.init_bare(tmp) e = assert_raises( # TODO better exception for this RuntimeError, commands.get_object_size, repo=tmp, object='deadbeefdeadbeefdeadbeefdeadbeefdeadbeef', ) eq(str(e), 'git cat-file failed')
def test_open_write(): tmp = maketemp() commands.init_bare(tmp) with readonly.ReadOnlyGitFS( repo=tmp, rev='HEAD', ) as root: p = root.child('foo') e = assert_raises( IOError, p.open, 'w', ) eq(e.errno, errno.EROFS) eq(str(e), '[Errno %d] Read-only file system' % errno.EROFS)
def test_get_sha1_nonexistent(): tmp = maketemp() repo = os.path.join(tmp, 'repo') index = os.path.join(tmp, 'index') commands.init_bare(repo) root = indexfs.IndexFS( repo=repo, index=index, ) foo = root.child('foo') e = assert_raises( OSError, foo.git_get_sha1, ) eq(e.errno, errno.ENOENT) eq(str(e), '[Errno %d] No such file or directory' % errno.ENOENT)
def test_set_sha1_missing(): tmp = maketemp() repo = os.path.join(tmp, 'repo') index = os.path.join(tmp, 'index') commands.init_bare(repo) root = indexfs.IndexFS( repo=repo, index=index, ) bar = root.child('bar') # this succeeds but creates a broken index bar.git_set_sha1('deadbeefdeadbeefdeadbeefdeadbeefdeadbeef') got = bar.git_get_sha1() eq(got, 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef') e = assert_raises( # TODO this really should be more specific RuntimeError, bar.open, ) eq(str(e), 'git cat-file failed')
def test_read_tree_merge3(): tmp = maketemp() repo = os.path.join(tmp, 'repo') os.mkdir(repo) commands.init_bare(repo) commands.fast_import( repo=repo, commits=[ dict( message='one', committer='John Doe <*****@*****.**>', commit_time='1216235872 +0300', files=[ dict( path='foo', content='FOO', ), ], ), dict( message='two', committer='Jack Smith <*****@*****.**>', commit_time='1216235940 +0300', files=[ dict( path='foo', content='FOO', ), dict( path='bar', content='BAR', ), ], ), ], ) one = commands.rev_parse(repo=repo, rev='HEAD~1') commands.fast_import( repo=repo, ref='refs/heads/bar', commits=[ dict( parent=one, message='three', committer='John Doe <*****@*****.**>', commit_time='1216235942 +0300', files=[ dict( path='foo', content='FOO', ), dict( path='quux', content='QUUX', ), ], ), ], ) index = os.path.join(tmp, 'index') commands.read_tree( repo=repo, treeish='HEAD', index=index, ) commands.read_tree_merge3( repo=repo, index=index, ancestor=one, local='HEAD', remote='refs/heads/bar', trivial=True, ) g = commands.ls_files( repo=repo, index=index, ) eq( g.next(), dict( mode='100644', object='add8373108657cb230a5379a6fcdaab73f330642', path='bar', ), ) eq( g.next(), dict( mode='100644', object='d96c7efbfec2814ae0301ad054dc8d9fc416c9b5', path='foo', ), ) eq( g.next(), dict( mode='100644', object='b9d4f2faa83cc1ad83ef7493ad6cbf08b086e4c1', path='quux', ), ) assert_raises(StopIteration, g.next)
def test_for_each_ref_fields(): tmp = maketemp() commands.init_bare(tmp) commands.fast_import( repo=tmp, commits=[ dict( message='one', committer='John Doe <*****@*****.**>', commit_time='1216235872 +0300', files=[ dict( path='foo', content='FOO', ), ], ), dict( message='two', committer='Jack Smith <*****@*****.**>', commit_time='1216235940 +0300', files=[ dict( path='foo', content='FOO', ), dict( path='bar', content='BAR', ), ], ), ], ) commands.update_ref( repo=tmp, ref='refs/heads/quux', newvalue='HEAD~1', oldvalue=40*'0', ) got = commands.for_each_ref( repo=tmp, fields=['refname', 'objecttype', 'objectname'], ) got = iter(got) eq( got.next(), dict( refname='refs/heads/master', objecttype='commit', objectname='27f952fd48ce824454457b9f28bb97091bc5422e', ), ) eq( got.next(), dict( refname='refs/heads/quux', objecttype='commit', objectname='e1b2f3253b18e7bdbd38db0cf295e6b3b608bb27', ), ) assert_raises(StopIteration, got.next)