summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-23 00:14:24 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-23 00:14:24 +0200
commit00499d994fea6fb55a33c788f069782f917dbdd4 (patch)
treef3de7739d34003a7356bd72769f212a47ebc8993 /test
parentb2a14e4b96a0ffc5353733b50266b477539ef899 (diff)
parentd1bd99c0a376dec63f0f050aeb0c40664260da16 (diff)
downloadgitpython-00499d994fea6fb55a33c788f069782f917dbdd4.tar.gz
Merge branch 'symbolic_ref' into improvements
* symbolic_ref: SymbolicReferences can now change they references safely as I think and well controlled, including test. Adjusted tests to deal with API changes Added SymbolicReference and HEAD type to better represent these special types of references and allow special handling
Diffstat (limited to 'test')
-rw-r--r--test/git/test_base.py46
-rw-r--r--test/git/test_commit.py2
-rw-r--r--test/git/test_head.py24
-rw-r--r--test/git/test_index.py4
-rw-r--r--test/git/test_refs.py110
-rw-r--r--test/git/test_repo.py10
-rw-r--r--test/git/test_tag.py33
7 files changed, 116 insertions, 113 deletions
diff --git a/test/git/test_base.py b/test/git/test_base.py
index 3472608e..1b78786a 100644
--- a/test/git/test_base.py
+++ b/test/git/test_base.py
@@ -66,50 +66,6 @@ class TestBase(TestBase):
assert len(s|s) == num_objs
assert num_index_objs == 2
-
- def test_tags(self):
- # tag refs can point to tag objects or to commits
- s = set()
- ref_count = 0
- for ref in chain(self.rorepo.tags, self.rorepo.heads):
- ref_count += 1
- assert isinstance(ref, refs.Reference)
- assert str(ref) == ref.name
- assert repr(ref)
- assert ref == ref
- assert not ref != ref
- s.add(ref)
- # END for each ref
- assert len(s) == ref_count
- assert len(s|s) == ref_count
-
- def test_heads(self):
- # see how it dynmically updates its object
- for head in self.rorepo.heads:
- head.name
- head.path
- prev_object = head.object
- cur_object = head.object
- assert prev_object == cur_object # represent the same git object
- assert prev_object is not cur_object # but are different instances
- # END for each head
-
- @with_rw_repo('0.1.6')
- def test_head_reset(self, rw_repo):
- cur_head = rw_repo.head
- new_head_commit = cur_head.commit.parents[0]
- reset_head = Head.reset(rw_repo, new_head_commit, index=True) # index only
- assert reset_head.commit == new_head_commit
-
- self.failUnlessRaises(ValueError, Head.reset, rw_repo, new_head_commit, index=False, working_tree=True)
- new_head_commit = new_head_commit.parents[0]
- reset_head = Head.reset(rw_repo, new_head_commit, index=True, working_tree=True) # index + wt
- assert reset_head.commit == new_head_commit
-
- # paths
- Head.reset(rw_repo, new_head_commit, paths = "lib")
-
-
def test_get_object_type_by_name(self):
for tname in base.Object.TYPES:
assert base.Object in get_object_type_by_name(tname).mro()
@@ -119,7 +75,7 @@ class TestBase(TestBase):
def test_object_resolution(self):
# objects must be resolved to shas so they compare equal
- assert self.rorepo.head.object == self.rorepo.active_branch.object
+ assert self.rorepo.head.reference.object == self.rorepo.active_branch.object
@with_bare_rw_repo
def test_with_bare_rw_repo(self, bare_rw_repo):
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index 1a74593d..c4ed4b72 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -64,7 +64,7 @@ class TestCommit(TestBase):
assert_equal(sha1, commit.id)
def test_count(self):
- assert self.rorepo.tag('0.1.5').commit.count( ) == 141
+ assert self.rorepo.tag('refs/tags/0.1.5').commit.count( ) == 141
def test_list(self):
assert isinstance(Commit.list_items(self.rorepo, '0.1.5', max_count=5)['5117c9c8a4d3af19a9958677e45cda9269de1541'], Commit)
diff --git a/test/git/test_head.py b/test/git/test_head.py
deleted file mode 100644
index 9b18ad7c..00000000
--- a/test/git/test_head.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# test_head.py
-# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
-#
-# This module is part of GitPython and is released under
-# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-
-from test.testlib import *
-from git import *
-
-class TestHead(TestBase):
-
- def test_base(self):
- for head in self.rorepo.heads:
- assert head.name
- assert "refs/heads" in head.path
- # END for each head
-
- @patch_object(Git, '_call_process')
- def test_ref_with_path_component(self, git):
- git.return_value = fixture('for_each_ref_with_path_component')
- head = self.rorepo.heads[0]
-
- assert_equal('refactoring/feature1', head.name)
- assert_true(git.called)
diff --git a/test/git/test_index.py b/test/git/test_index.py
index 257acf10..7bc2ad7e 100644
--- a/test/git/test_index.py
+++ b/test/git/test_index.py
@@ -116,8 +116,8 @@ class TestTree(TestBase):
# test diff
# resetting the head will leave the index in a different state, and the
# diff will yield a few changes
- cur_head_commit = rw_repo.head.commit
- ref = rw_repo.head.reset(rw_repo, 'HEAD~6', index=True, working_tree=False)
+ cur_head_commit = rw_repo.head.reference.commit
+ ref = rw_repo.head.reset('HEAD~6', index=True, working_tree=False)
# diff against same index is 0
diff = index.diff()
diff --git a/test/git/test_refs.py b/test/git/test_refs.py
new file mode 100644
index 00000000..1562310a
--- /dev/null
+++ b/test/git/test_refs.py
@@ -0,0 +1,110 @@
+# test_refs.py
+# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
+#
+# This module is part of GitPython and is released under
+# the BSD License: http://www.opensource.org/licenses/bsd-license.php
+
+from mock import *
+from test.testlib import *
+from git import *
+import git.refs as refs
+from git.objects.tag import TagObject
+from itertools import chain
+
+class TestRefs(TestBase):
+
+ def test_tag_base(self):
+ tag_object_refs = list()
+ for tag in self.rorepo.tags:
+ assert "refs/tags" in tag.path
+ assert tag.name
+ assert isinstance( tag.commit, Commit )
+ if tag.tag is not None:
+ tag_object_refs.append( tag )
+ tagobj = tag.tag
+ assert isinstance( tagobj, TagObject )
+ assert tagobj.tag == tag.name
+ assert isinstance( tagobj.tagger, Actor )
+ assert isinstance( tagobj.tagged_date, int )
+ assert tagobj.message
+ # END if we have a tag object
+ # END for tag in repo-tags
+ assert tag_object_refs
+ assert isinstance(self.rorepo.tags['0.1.5'], TagReference)
+
+ @patch_object(Git, '_call_process')
+ def test_ref_with_path_component(self, git):
+ git.return_value = fixture('for_each_ref_with_path_component')
+ head = self.rorepo.heads[0]
+
+ assert_equal('refactoring/feature1', head.name)
+ assert_true(git.called)
+
+
+ def test_tags(self):
+ # tag refs can point to tag objects or to commits
+ s = set()
+ ref_count = 0
+ for ref in chain(self.rorepo.tags, self.rorepo.heads):
+ ref_count += 1
+ assert isinstance(ref, refs.Reference)
+ assert str(ref) == ref.name
+ assert repr(ref)
+ assert ref == ref
+ assert not ref != ref
+ s.add(ref)
+ # END for each ref
+ assert len(s) == ref_count
+ assert len(s|s) == ref_count
+
+ def test_heads(self):
+ for head in self.rorepo.heads:
+ assert head.name
+ assert head.path
+ assert "refs/heads" in head.path
+ prev_object = head.object
+ cur_object = head.object
+ assert prev_object == cur_object # represent the same git object
+ assert prev_object is not cur_object # but are different instances
+ # END for each head
+
+ @with_rw_repo('0.1.6')
+ def test_head_reset(self, rw_repo):
+ cur_head = rw_repo.head
+ new_head_commit = cur_head.ref.commit.parents[0]
+ cur_head.reset(new_head_commit, index=True) # index only
+ assert cur_head.reference.commit == new_head_commit
+
+ self.failUnlessRaises(ValueError, cur_head.reset, new_head_commit, index=False, working_tree=True)
+ new_head_commit = new_head_commit.parents[0]
+ cur_head.reset(new_head_commit, index=True, working_tree=True) # index + wt
+ assert cur_head.reference.commit == new_head_commit
+
+ # paths
+ cur_head.reset(new_head_commit, paths = "lib")
+
+
+ # now that we have a write write repo, change the HEAD reference - its
+ # like git-reset --soft
+ heads = rw_repo.heads
+ assert heads
+ for head in heads:
+ cur_head.reference = head
+ assert cur_head.reference == head
+ assert cur_head.commit == head.commit
+ assert not cur_head.is_detached
+ # END for each head
+
+ # detach
+ cur_head.reference = heads[0].commit
+ assert cur_head.commit == heads[0].commit
+ assert cur_head.is_detached
+ self.failUnlessRaises(TypeError, getattr, cur_head, "reference")
+
+ some_tag = rw_repo.tags[0]
+ cur_head.reference = some_tag
+ assert cur_head.is_detached
+ assert cur_head.commit == some_tag.commit
+
+ # type check
+ self.failUnlessRaises(ValueError, setattr, cur_head, "reference", "that")
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 02eea7de..b02610f4 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -168,17 +168,11 @@ class TestRepo(TestBase):
self.rorepo._bare = True
assert self.rorepo.is_dirty == False
- @patch_object(Git, '_call_process')
- def test_active_branch(self, git):
- git.return_value = 'refs/heads/major-refactoring'
- assert_equal(self.rorepo.active_branch.name, 'major-refactoring')
- assert_equal(git.call_args, (('symbolic_ref', 'HEAD'), {}))
-
def test_head(self):
- assert self.rorepo.head.object == self.rorepo.active_branch.object
+ assert self.rorepo.head.reference.object == self.rorepo.active_branch.object
def test_tag(self):
- assert self.rorepo.tag('0.1.5').commit
+ assert self.rorepo.tag('refs/tags/0.1.5').commit
def test_archive(self):
tmpfile = os.tmpfile()
diff --git a/test/git/test_tag.py b/test/git/test_tag.py
deleted file mode 100644
index 97e0acd1..00000000
--- a/test/git/test_tag.py
+++ /dev/null
@@ -1,33 +0,0 @@
-# test_tag.py
-# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
-#
-# This module is part of GitPython and is released under
-# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-
-from mock import *
-from test.testlib import *
-from git import *
-from git.objects.tag import TagObject
-
-class TestTag(TestBase):
-
- def test_tag_base(self):
- tag_object_refs = list()
- for tag in self.rorepo.tags:
- assert "refs/tags" in tag.path
- assert tag.name
- assert isinstance( tag.commit, Commit )
- if tag.tag is not None:
- tag_object_refs.append( tag )
- tagobj = tag.tag
- assert isinstance( tagobj, TagObject )
- assert tagobj.tag == tag.name
- assert isinstance( tagobj.tagger, Actor )
- assert isinstance( tagobj.tagged_date, int )
- assert tagobj.message
- # END if we have a tag object
- # END for tag in repo-tags
- assert tag_object_refs
- assert isinstance(self.rorepo.tags['0.1.5'], TagReference)
-
-