Browse Source

Add porcelain 'list-tags'.

Ryan Faulkner 11 years ago
parent
commit
03578f1dcf
3 changed files with 29 additions and 0 deletions
  1. 2 0
      NEWS
  2. 13 0
      dulwich/porcelain.py
  3. 14 0
      dulwich/tests/test_porcelain.py

+ 2 - 0
NEWS

@@ -2,6 +2,8 @@
 
  IMPROVEMENTS
 
+ * Add porcelain 'list_tags'. (Ryan Faulkner)
+
  * Add porcelain 'push'. (Ryan Faulkner)
 
  * Add porcelain 'pull'. (Ryan Faulkner)

+ 13 - 0
dulwich/porcelain.py

@@ -46,6 +46,7 @@ Currently implemented:
  * commit-tree
  * diff-tree
  * init
+ * list-tags
  * pull
  * push
  * remove
@@ -374,6 +375,18 @@ def tag(repo, tag, author, message):
     r.refs['refs/tags/' + tag] = tag_obj.id
 
 
+def list_tags(repo, outstream=sys.stdout):
+    """List all tags.
+
+    :param repo: Path to repository
+    :param outstream: Stream to write tags to
+    """
+    r = open_repo(repo)
+    tags = list(r.refs.as_dict("refs/tags"))
+    tags.sort()
+    return tags
+
+
 def reset(repo, mode, committish="HEAD"):
     """Reset current HEAD to the specified state.
 

+ 14 - 0
dulwich/tests/test_porcelain.py

@@ -346,6 +346,20 @@ class TagTests(PorcelainTestCase):
         self.assertEquals(tags.keys()[0], tag)
 
 
+class ListTagsTests(PorcelainTestCase):
+
+    def test_empty(self):
+        tags = porcelain.list_tags(self.repo.path)
+        self.assertEquals([], tags)
+
+    def test_simple(self):
+        self.repo.refs["refs/tags/foo"] = "aa" * 20
+        self.repo.refs["refs/tags/bar/bla"] = "bb" * 20
+        tags = porcelain.list_tags(self.repo.path)
+
+        self.assertEquals(["bar/bla", "foo"], tags)
+
+
 class ResetTests(PorcelainTestCase):
 
     def test_hard_head(self):