From 9a119924bd314934158515a1a5f5877be63f6f91 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 20:21:22 +0200 Subject: fixed issue in Ref.name implementation which would not handle components properly --- lib/git/base.py | 10 ++++++++-- lib/git/tree.py | 6 +++--- test/fixtures/for_each_ref_with_path_component | Bin 72 -> 84 bytes test/git/test_head.py | 16 +++++----------- test/git/test_tag.py | 2 +- test/testlib/asserts.py | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/git/base.py b/lib/git/base.py index f3510558..b7976dab 100644 --- a/lib/git/base.py +++ b/lib/git/base.py @@ -222,9 +222,15 @@ class Ref(object): def name(self): """ Returns - Name of this reference + (shortest) Name of this reference - it may contain path components """ - return os.path.basename(self.path) + # first two path tokens are can be removed as they are + # refs/heads or refs/tags or refs/remotes + tokens = self.path.split('/') + if len(tokens) < 3: + return self.path # could be refs/HEAD + + return '/'.join(tokens[2:]) @classmethod def find_all(cls, repo, common_path = "refs", **kwargs): diff --git a/lib/git/tree.py b/lib/git/tree.py index db4a3e22..597668ae 100644 --- a/lib/git/tree.py +++ b/lib/git/tree.py @@ -47,11 +47,11 @@ class Tree(base.IndexObject): return None if typ == "tree": - return Tree(repo, id=id, mode=mode, path=path) + return Tree(repo, id, mode, path) elif typ == "blob": - return blob.Blob(repo, id=id, mode=mode, path=path) + return blob.Blob(repo, id, mode, path) elif typ == "commit": - return None + return None else: raise(TypeError, "Invalid type: %s" % typ) diff --git a/test/fixtures/for_each_ref_with_path_component b/test/fixtures/for_each_ref_with_path_component index 717c4203..e723b4ae 100644 Binary files a/test/fixtures/for_each_ref_with_path_component and b/test/fixtures/for_each_ref_with_path_component differ diff --git a/test/git/test_head.py b/test/git/test_head.py index 8338552f..b8380838 100644 --- a/test/git/test_head.py +++ b/test/git/test_head.py @@ -11,16 +11,11 @@ class TestHead(object): def setup(self): self.repo = Repo(GIT_REPO) - @patch_object(Git, '_call_process') - def test_repr(self, git): - git.return_value = fixture('for_each_ref') - - head = self.repo.heads[0] - - assert_equal('' % head.name, repr(head)) - - assert_true(git.called) - assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) + def test_base(self): + for head in self.repo.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): @@ -29,4 +24,3 @@ class TestHead(object): assert_equal('refactoring/feature1', head.name) assert_true(git.called) - assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) diff --git a/test/git/test_tag.py b/test/git/test_tag.py index 52f7898c..fe3f78cc 100644 --- a/test/git/test_tag.py +++ b/test/git/test_tag.py @@ -18,7 +18,7 @@ class TestTag(object): tag_object_refs = list() for tag in self.repo.tags: assert "refs/tags" in tag.path - assert "/" not in tag.name + assert tag.name assert isinstance( tag.commit, Commit ) if tag.tag is not None: tag_object_refs.append( tag ) diff --git a/test/testlib/asserts.py b/test/testlib/asserts.py index 8f2acdc9..345f74ec 100644 --- a/test/testlib/asserts.py +++ b/test/testlib/asserts.py @@ -23,11 +23,11 @@ def assert_not_instance_of(expected, actual, msg=None): def assert_none(actual, msg=None): """verify that item is None""" - assert_equal(None, actual, msg) + assert actual is None, msg def assert_not_none(actual, msg=None): """verify that item is None""" - assert_not_equal(None, actual, msg) + assert actual is not None, msg def assert_match(pattern, string, msg=None): """verify that the pattern matches the string""" -- cgit v1.2.1