summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/git/base.py10
-rw-r--r--lib/git/tree.py6
-rw-r--r--test/fixtures/for_each_ref_with_path_componentbin72 -> 84 bytes
-rw-r--r--test/git/test_head.py16
-rw-r--r--test/git/test_tag.py2
-rw-r--r--test/testlib/asserts.py4
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
--- a/test/fixtures/for_each_ref_with_path_component
+++ b/test/fixtures/for_each_ref_with_path_component
Binary files 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('<git.Head "%s">' % 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"""