def test_send_pack_without_changes(self): local = open_repo('a.git') self.addCleanup(tear_down_repo, local) target = open_repo('a.git') self.addCleanup(tear_down_repo, target) self.send_and_verify(b"master", local, target)
def test_tree_not_tree(self): r = self._repo = open_repo("a.git") warnings.simplefilter("ignore", DeprecationWarning) try: self.assertRaises(errors.NotTreeError, r.tree, r.head()) finally: warnings.resetwarnings()
def test_linear_history(self): r = self._repo = open_repo("a.git") warnings.simplefilter("ignore", DeprecationWarning) self.addCleanup(warnings.resetwarnings) history = r.revision_history(r.head()) shas = [c.sha().hexdigest() for c in history] self.assertEqual(shas, [r.head(), "2a72d929692c41d8554c07f6301757ba18a65d91"])
def test_get_refs(self): local = open_repo('refs.git') self.addCleanup(tear_down_repo, local) client = LocalGitClient() refs = client.get_refs(local.path) self.assertDictEqual(local.refs.as_dict(), refs)
def test_get_blob_notblob(self): r = self._repo = open_repo('a.git') warnings.simplefilter("ignore", DeprecationWarning) try: self.assertRaises(errors.NotBlobError, r.get_blob, r.head()) finally: warnings.resetwarnings()
def test_fetch_empty(self): c = LocalGitClient() s = open_repo('a.git') self.addCleanup(tear_down_repo, s) out = BytesIO() walker = {} ret = c.fetch_pack(s.path, lambda heads: [], graph_walker=walker, pack_data=out.write) self.assertEqual( { b'HEAD': b'a90fa2d900a17e99b433217e988c4eb4a2e9a097', b'refs/heads/master': b'a90fa2d900a17e99b433217e988c4eb4a2e9a097', b'refs/tags/mytag': b'28237f4dc30d0d462658d6b937b08a0f0b6ef55a', b'refs/tags/mytag-packed': b'b0931cadc54336e78a1d980420e3268903b57a50' }, ret.refs) self.assertEqual({b'HEAD': b'refs/heads/master'}, ret.symrefs) self.assertEqual( b"PACK\x00\x00\x00\x02\x00\x00\x00\x00\x02\x9d\x08" b"\x82;\xd8\xa8\xea\xb5\x10\xadj\xc7\\\x82<\xfd>\xd3\x1e", out.getvalue())
def test_tag_not_tag(self): r = self._repo = open_repo('a.git') warnings.simplefilter("ignore", DeprecationWarning) try: self.assertRaises(errors.NotTagError, r.tag, r.head()) finally: warnings.resetwarnings()
def test_fetch_pack_none(self): c = LocalGitClient() s = open_repo('a.git') self.addCleanup(tear_down_repo, s) out = BytesIO() walker = MemoryRepo().get_graph_walker() ret = c.fetch_pack( s.path, lambda heads: [b"a90fa2d900a17e99b433217e988c4eb4a2e9a097"], graph_walker=walker, pack_data=out.write) self.assertEqual({b'HEAD': b'refs/heads/master'}, ret.symrefs) self.assertEqual( { b'HEAD': b'a90fa2d900a17e99b433217e988c4eb4a2e9a097', b'refs/heads/master': b'a90fa2d900a17e99b433217e988c4eb4a2e9a097', b'refs/tags/mytag': b'28237f4dc30d0d462658d6b937b08a0f0b6ef55a', b'refs/tags/mytag-packed': b'b0931cadc54336e78a1d980420e3268903b57a50' }, ret.refs) # Hardcoding is not ideal, but we'll fix that some other day.. self.assertTrue( out.getvalue().startswith(b'PACK\x00\x00\x00\x02\x00\x00\x00\x07'))
def test_commit_not_commit(self): r = self._repo = open_repo("a.git") warnings.simplefilter("ignore", DeprecationWarning) try: self.assertRaises(errors.NotCommitError, r.commit, "4f2e6529203aa6d44b5af6e3292c837ceda003f9") finally: warnings.resetwarnings()
def test_commit(self): r = self._repo = open_repo('a.git') warnings.simplefilter("ignore", DeprecationWarning) try: obj = r.commit(r.head()) finally: warnings.resetwarnings() self.assertEqual(obj.type_name, 'commit')
def test_get_description(self): r = self._repo = open_repo('a.git') f = open(os.path.join(r.path, 'description'), 'w') try: f.write("Some description") finally: f.close() self.assertEquals("Some description", r.get_description())
def test_get_description(self): r = self._repo = open_repo("a.git") f = open(os.path.join(r.path, "description"), "w") try: f.write("Some description") finally: f.close() self.assertEqual("Some description", r.get_description())
def test_linear_history(self): r = self._repo = open_repo('a.git') warnings.simplefilter("ignore", DeprecationWarning) self.addCleanup(warnings.resetwarnings) history = r.revision_history(r.head()) shas = [c.sha().hexdigest() for c in history] self.assertEqual( shas, [r.head(), '2a72d929692c41d8554c07f6301757ba18a65d91'])
def test_merge_history(self): r = self._repo = open_repo('simple_merge.git') shas = [e.commit.id for e in r.get_walker()] self.assertEqual(shas, ['5dac377bdded4c9aeb8dff595f0faeebcc8498cc', 'ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd', '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6', '60dacdc733de308bb77bb76ce0fb0f9b44c9769e', '0d89f20333fbb1d2f3a94da77f4981373d8f4310'])
def test_out_of_order_merge(self): """Test that revision history is ordered by date, not parent order.""" r = self._repo = open_repo('ooo_merge.git') shas = [e.commit.id for e in r.get_walker()] self.assertEqual(shas, ['7601d7f6231db6a57f7bbb79ee52e4d462fd44d1', 'f507291b64138b875c28e03469025b1ea20bc614', 'fb5b0425c7ce46959bec94d54b9a157645e114f5', 'f9e39b120c68182a4ba35349f832d0e4e61f485c'])
def test_tree(self): r = self._repo = open_repo('a.git') commit = r[r.head()] warnings.simplefilter("ignore", DeprecationWarning) self.addCleanup(warnings.resetwarnings) tree = r.tree(commit.tree) self.assertEqual(tree.type_name, 'tree') self.assertEqual(tree.sha().hexdigest(), commit.tree)
def test_get_walker(self): r = self._repo = open_repo('a.git') # include defaults to [r.head()] self.assertEqual([e.commit.id for e in r.get_walker()], [r.head(), '2a72d929692c41d8554c07f6301757ba18a65d91']) self.assertEqual( [e.commit.id for e in r.get_walker(['2a72d929692c41d8554c07f6301757ba18a65d91'])], ['2a72d929692c41d8554c07f6301757ba18a65d91'])
def test_send_pack_with_changes(self): local = open_repo('a.git') self.addCleanup(tear_down_repo, local) target_path = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, target_path) with Repo.init_bare(target_path) as target: self.send_and_verify(b"master", local, target)
def test_get_refs(self): r = self._repo = open_repo('a.git') self.assertEqual({ 'HEAD': 'a90fa2d900a17e99b433217e988c4eb4a2e9a097', 'refs/heads/master': 'a90fa2d900a17e99b433217e988c4eb4a2e9a097', 'refs/tags/mytag': '28237f4dc30d0d462658d6b937b08a0f0b6ef55a', 'refs/tags/mytag-packed': 'b0931cadc54336e78a1d980420e3268903b57a50', }, r.get_refs())
def test_out_of_order_merge(self): """Test that revision history is ordered by date, not parent order.""" r = self._repo = open_repo('ooo_merge.git') history = r.revision_history(r.head()) shas = [c.sha().hexdigest() for c in history] self.assertEqual(shas, ['7601d7f6231db6a57f7bbb79ee52e4d462fd44d1', 'f507291b64138b875c28e03469025b1ea20bc614', 'fb5b0425c7ce46959bec94d54b9a157645e114f5', 'f9e39b120c68182a4ba35349f832d0e4e61f485c'])
def test_fetch_empty(self): c = LocalGitClient() s = open_repo('a.git') out = BytesIO() walker = {} c.fetch_pack(s.path, lambda heads: [], graph_walker=walker, pack_data=out.write) self.assertEqual("PACK\x00\x00\x00\x02\x00\x00\x00\x00\x02\x9d\x08" "\x82;\xd8\xa8\xea\xb5\x10\xadj\xc7\\\x82<\xfd>\xd3\x1e", out.getvalue())
def test_merge_history(self): r = self._repo = open_repo('simple_merge.git') history = r.revision_history(r.head()) shas = [c.sha().hexdigest() for c in history] self.assertEqual(shas, ['5dac377bdded4c9aeb8dff595f0faeebcc8498cc', 'ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd', '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6', '60dacdc733de308bb77bb76ce0fb0f9b44c9769e', '0d89f20333fbb1d2f3a94da77f4981373d8f4310'])
def test_fetch_empty(self): c = LocalGitClient() s = open_repo('a.git') out = BytesIO() walker = {} c.fetch_pack(s.path, lambda heads: [], graph_walker=walker, pack_data=out.write) self.assertEquals("PACK\x00\x00\x00\x02\x00\x00\x00\x00\x02\x9d\x08" "\x82;\xd8\xa8\xea\xb5\x10\xadj\xc7\\\x82<\xfd>\xd3\x1e", out.getvalue())
def test_get_blob(self): r = self._repo = open_repo('a.git') commit = r[r.head()] tree = r[commit.tree] blob_sha = tree.items()[0][2] warnings.simplefilter("ignore", DeprecationWarning) self.addCleanup(warnings.resetwarnings) blob = r.get_blob(blob_sha) self.assertEqual(blob.type_name, 'blob') self.assertEqual(blob.sha().hexdigest(), blob_sha)
def test_tree(self): r = self._repo = open_repo("a.git") commit = r[r.head()] warnings.simplefilter("ignore", DeprecationWarning) try: tree = r.tree(commit.tree) finally: warnings.resetwarnings() self.assertEqual(tree.type_name, "tree") self.assertEqual(tree.sha().hexdigest(), commit.tree)
def test_fetch_pack_none(self): c = LocalGitClient() s = open_repo('a.git') out = BytesIO() walker = MemoryRepo().get_graph_walker() c.fetch_pack(s.path, lambda heads: ["a90fa2d900a17e99b433217e988c4eb4a2e9a097"], graph_walker=walker, pack_data=out.write) # Hardcoding is not ideal, but we'll fix that some other day.. self.assertTrue(out.getvalue().startswith('PACK\x00\x00\x00\x02\x00\x00\x00\x07'))
def test_out_of_order_merge(self): """Test that revision history is ordered by date, not parent order.""" r = self._repo = open_repo('ooo_merge.git') shas = [e.commit.id for e in r.get_walker()] self.assertEqual(shas, [ '7601d7f6231db6a57f7bbb79ee52e4d462fd44d1', 'f507291b64138b875c28e03469025b1ea20bc614', 'fb5b0425c7ce46959bec94d54b9a157645e114f5', 'f9e39b120c68182a4ba35349f832d0e4e61f485c' ])
def test_merge_history(self): r = self._repo = open_repo('simple_merge.git') shas = [e.commit.id for e in r.get_walker()] self.assertEqual(shas, [ '5dac377bdded4c9aeb8dff595f0faeebcc8498cc', 'ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd', '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6', '60dacdc733de308bb77bb76ce0fb0f9b44c9769e', '0d89f20333fbb1d2f3a94da77f4981373d8f4310' ])
def test_delitem(self): r = self._repo = open_repo('a.git') del r['refs/heads/master'] self.assertRaises(KeyError, lambda: r['refs/heads/master']) del r['HEAD'] self.assertRaises(KeyError, lambda: r['HEAD']) self.assertRaises(ValueError, r.__delitem__, 'notrefs/foo')
def test_delitem(self): r = self._repo = open_repo("a.git") del r["refs/heads/master"] self.assertRaises(KeyError, lambda: r["refs/heads/master"]) del r["HEAD"] self.assertRaises(KeyError, lambda: r["HEAD"]) self.assertRaises(ValueError, r.__delitem__, "notrefs/foo")
def test_get_walker(self): r = self._repo = open_repo('a.git') # include defaults to [r.head()] self.assertEqual( [e.commit.id for e in r.get_walker()], [r.head(), '2a72d929692c41d8554c07f6301757ba18a65d91']) self.assertEqual([ e.commit.id for e in r.get_walker(['2a72d929692c41d8554c07f6301757ba18a65d91']) ], ['2a72d929692c41d8554c07f6301757ba18a65d91'])
def test_fetch_pack_none(self): c = LocalGitClient() s = open_repo('a.git') out = StringIO() walker = MemoryRepo().get_graph_walker() c.fetch_pack(s.path, lambda heads: ["a90fa2d900a17e99b433217e988c4eb4a2e9a097"], graph_walker=walker, pack_data=out.write) # Hardcoding is not ideal, but we'll fix that some other day.. self.assertEquals(out.getvalue(), 'PACK\x00\x00\x00\x02\x00\x00\x00\x07\x90\x0cx\x9c\xa5\xccM\n\xc20\x10@\xe1}N1\xfb\x82$v\xe2$ \xa2[/\xe0z\xd2\x19\xb1\x85\xa4\xd0\x8e\x14o\xef\xcf\x15|\xcbo\xf1lQ\x05\x92\xcc\x9e\x842\xc5\x1c\xf5\x1eB\x8f\x181\x97$>\x85\x9c\x14\xd3\x10b\x7f@\xc7O{\xcc\x0b\\\xb9\xea\n7]\xad\xbc\xe08m\x9dh\x19\xb9\x9d\xa7\xafo?\xde5\xb5\x13\x84@H\x14\xfd>C\xe7?\xb9a\xaeu4\xd3\x7f\x1e\xee"\x02\x0c\xdc\x04\x8a{\x03\x1a4:\\\x9a\x0ex\x9c\xa5\xccM\n\xc3 \x10@\xe1\xbd\xa7p\x1f(j\x1cG\xa1\x94v\xdb\x0bt=:#M II,\xa1\xb7\xef\xcf\x15\xfa\x96\xdf\xe2\xb5UD\xd7\xca\x1e\xd9C\xf4@\xb1\x06\xc0\xe0\x93\x15+\x9c\x13J_%P\x04#X\xd5\x83V\x99\x9bv\x84\x8e\x93K!\xb9\xe2-G\x00_\x0c\xd6\xd0\x1b\x8b\x80\x99l\xa4\x00\x9c\xac\xa2g\xbb/\xab\xbe\xd2$\x9b\xbe\xc9\xd6\xf2K\x1f\xc7\xbdc\xc9\x03\xcd\xe7\xf1\xeb\xfb\x8f\x0f\xb3\xb4\x93\xb6\x16="\x18\x8f\xba3\x9fTY\xa6ihM\xfey\xa8\x0b\xb3.\xea\rM\xb6F\x9c\xaa\x03x\x9c340031QHd\xf0\xfb\xcc\xbd\xffQ\x8a\xe1\xb29\x16\n\x97\x975\xdf\x0f\xb9\xd6\xf1\xe9\x8d!D2\x89\xc1_/US\xc1j\xd9\x15\xef\xa8o\x8f5u\x9ak\xde.`\xfe\t\x00\x97P\x18#7x\x9cK\xcb\xccIUH\xe4\x02\x00\n#\x02,7x\x9cK\xcb\xccIUH\xe2\x02\x00\n%\x02-\xa7\x05x\x9c340031QHd\xf0\xfb\xcc\xbd\xffQ\x8a\xe1\xb29\x16\n\x97\x975\xdf\x0f\xb9\xd6\xf1\xe9\x8d!D2\x89\xc1_/US\xc1j\xd9\x15\xef\xa8o\x8f5u\x9ak\xde.`\xfe\t\x95LfX4\xed\xc2\xeeD\xc1\x8eS\xbbU3%?g\x1ff\x14?\xb3\x80\x15\x00\xec0#h7x\x9cK\xcb\xccIUH\xe6\x02\x00\n\'\x02.\x8d7\x98\xae\xef7L\x95\x18\x94\x80X\xf1Q\xfb\xdc\xd9\xcf\xe7\xc3')
def test_get_refs(self): r = self._repo = open_repo("a.git") self.assertEqual( { "HEAD": "a90fa2d900a17e99b433217e988c4eb4a2e9a097", "refs/heads/master": "a90fa2d900a17e99b433217e988c4eb4a2e9a097", "refs/tags/mytag": "28237f4dc30d0d462658d6b937b08a0f0b6ef55a", "refs/tags/mytag-packed": "b0931cadc54336e78a1d980420e3268903b57a50", }, r.get_refs(), )
def test_tag(self): r = self._repo = open_repo('a.git') tag_sha = '28237f4dc30d0d462658d6b937b08a0f0b6ef55a' warnings.simplefilter("ignore", DeprecationWarning) self.addCleanup(warnings.resetwarnings) tag = r.tag(tag_sha) self.assertEqual(tag.type_name, 'tag') self.assertEqual(tag.sha().hexdigest(), tag_sha) obj_class, obj_sha = tag.object self.assertEqual(obj_class, objects.Commit) self.assertEqual(obj_sha, r.head())
def test_get_peeled(self): # unpacked ref r = self._repo = open_repo('a.git') tag_sha = '28237f4dc30d0d462658d6b937b08a0f0b6ef55a' self.assertNotEqual(r[tag_sha].sha().hexdigest(), r.head()) self.assertEqual(r.get_peeled('refs/tags/mytag'), r.head()) # packed ref with cached peeled value packed_tag_sha = 'b0931cadc54336e78a1d980420e3268903b57a50' parent_sha = r[r.head()].parents[0] self.assertNotEqual(r[packed_tag_sha].sha().hexdigest(), parent_sha) self.assertEqual(r.get_peeled('refs/tags/mytag-packed'), parent_sha)
def test_clone_empty(self): """Test clone() doesn't crash if HEAD points to a non-existing ref. This simulates cloning server-side bare repository either when it is still empty or if user renames master branch and pushes private repo to the server. Non-bare repo HEAD always points to an existing ref. """ r = self._repo = open_repo('empty.git') tmp_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, tmp_dir) r.clone(tmp_dir, mkdir=False, bare=True)
def test_get_blob(self): r = self._repo = open_repo("a.git") commit = r[r.head()] tree = r[commit.tree] blob_sha = tree.entries()[0][2] warnings.simplefilter("ignore", DeprecationWarning) try: blob = r.get_blob(blob_sha) finally: warnings.resetwarnings() self.assertEqual(blob.type_name, "blob") self.assertEqual(blob.sha().hexdigest(), blob_sha)
def test_common_revisions(self): """ This test demonstrates that ``find_common_revisions()`` actually returns common heads, not revisions; dulwich already uses ``find_common_revisions()`` in such a manner (see ``Repo.fetch_objects()``). """ expected_shas = set(['60dacdc733de308bb77bb76ce0fb0f9b44c9769e']) # Source for objects. r_base = open_repo('simple_merge.git') # Re-create each-side of the merge in simple_merge.git. # # Since the trees and blobs are missing, the repository created is # corrupted, but we're only checking for commits for the purpose of this # test, so it's immaterial. r1_dir = tempfile.mkdtemp() r1_commits = [ 'ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd', # HEAD '60dacdc733de308bb77bb76ce0fb0f9b44c9769e', '0d89f20333fbb1d2f3a94da77f4981373d8f4310' ] r2_dir = tempfile.mkdtemp() r2_commits = [ '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6', # HEAD '60dacdc733de308bb77bb76ce0fb0f9b44c9769e', '0d89f20333fbb1d2f3a94da77f4981373d8f4310' ] try: r1 = Repo.init_bare(r1_dir) map(lambda c: r1.object_store.add_object(r_base.get_object(c)), \ r1_commits) r1.refs['HEAD'] = r1_commits[0] r2 = Repo.init_bare(r2_dir) map(lambda c: r2.object_store.add_object(r_base.get_object(c)), \ r2_commits) r2.refs['HEAD'] = r2_commits[0] # Finally, the 'real' testing! shas = r2.object_store.find_common_revisions(r1.get_graph_walker()) self.assertEqual(set(shas), expected_shas) shas = r1.object_store.find_common_revisions(r2.get_graph_walker()) self.assertEqual(set(shas), expected_shas) finally: shutil.rmtree(r1_dir) shutil.rmtree(r2_dir)
def test_get_refs(self): r = self._repo = open_repo('a.git') self.assertEqual( { 'HEAD': 'a90fa2d900a17e99b433217e988c4eb4a2e9a097', 'refs/heads/master': 'a90fa2d900a17e99b433217e988c4eb4a2e9a097', 'refs/tags/mytag': '28237f4dc30d0d462658d6b937b08a0f0b6ef55a', 'refs/tags/mytag-packed': 'b0931cadc54336e78a1d980420e3268903b57a50', }, r.get_refs())
def test_getitem_unicode(self): r = self._repo = open_repo('a.git') test_keys = [ ('refs/heads/master', True), ('a90fa2d900a17e99b433217e988c4eb4a2e9a097', True), ('11' * 19 + '--', False), ] for k, contained in test_keys: self.assertEqual(k in r, contained) for k, _ in test_keys: self.assertRaisesRegexp(TypeError, "'name' must be bytestring, not unicode", r.__getitem__, unicode(k))
def test_clone(self): r = self._repo = open_repo('a.git') tmp_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, tmp_dir) t = r.clone(tmp_dir, mkdir=False) self.assertEqual( { 'HEAD': 'a90fa2d900a17e99b433217e988c4eb4a2e9a097', 'refs/remotes/origin/master': 'a90fa2d900a17e99b433217e988c4eb4a2e9a097', 'refs/heads/master': 'a90fa2d900a17e99b433217e988c4eb4a2e9a097', 'refs/tags/mytag': '28237f4dc30d0d462658d6b937b08a0f0b6ef55a', 'refs/tags/mytag-packed': 'b0931cadc54336e78a1d980420e3268903b57a50', }, t.refs.as_dict()) shas = [e.commit.id for e in r.get_walker()] self.assertEqual( shas, [t.head(), '2a72d929692c41d8554c07f6301757ba18a65d91'])
def test_commit(self): r = self._repo = open_repo('a.git') warnings.simplefilter("ignore", DeprecationWarning) self.addCleanup(warnings.resetwarnings) obj = r.commit(r.head()) self.assertEqual(obj.type_name, 'commit')
def test_get_config_stack(self): r = self._repo = open_repo('ooo_merge.git') self.assertIsInstance(r.get_config_stack(), Config)
def test_get_tags_empty(self): r = self._repo = open_repo('ooo_merge.git') self.assertEqual({}, r.refs.as_dict('refs/tags'))
def test_tag_not_tag(self): r = self._repo = open_repo('a.git') warnings.simplefilter("ignore", DeprecationWarning) self.addCleanup(warnings.resetwarnings) self.assertRaises(errors.NotTagError, r.tag, r.head())
def test_revision_history_missing_commit(self): r = self._repo = open_repo('simple_merge.git') warnings.simplefilter("ignore", DeprecationWarning) self.addCleanup(warnings.resetwarnings) self.assertRaises(errors.MissingCommitError, r.revision_history, missing_sha)
def test_get_peeled_not_tag(self): r = self._repo = open_repo('a.git') self.assertEqual(r.get_peeled('HEAD'), r.head())
def test_get_blob_notblob(self): r = self._repo = open_repo('a.git') warnings.simplefilter("ignore", DeprecationWarning) self.addCleanup(warnings.resetwarnings) self.assertRaises(errors.NotBlobError, r.get_blob, r.head())
def test_commit_not_commit(self): r = self._repo = open_repo('a.git') warnings.simplefilter("ignore", DeprecationWarning) self.addCleanup(warnings.resetwarnings) self.assertRaises(errors.NotCommitError, r.commit, '4f2e6529203aa6d44b5af6e3292c837ceda003f9')