Bläddra i källkod

Handle patches with more than one commit line.

Jelmer Vernooij 14 år sedan
förälder
incheckning
470bf78cd0
2 ändrade filer med 33 tillägg och 6 borttagningar
  1. 11 5
      dulwich/patch.py
  2. 22 1
      dulwich/tests/test_patch.py

+ 11 - 5
dulwich/patch.py

@@ -154,15 +154,21 @@ def git_am_patch_split(f):
     c = Commit()
     c.author = msg["from"]
     c.committer = msg["from"]
-    if msg["subject"].startswith("[PATCH"):
-        close = msg["subject"].index("] ")
-        subject = msg["subject"][close+2:]
-    else:
+    try:
+        patch_tag_start = msg["subject"].index("[PATCH")
+    except ValueError:
         subject = msg["subject"]
-    c.message = subject
+    else:
+        close = msg["subject"].index("] ", patch_tag_start)
+        subject = msg["subject"][close+2:]
+    c.message = subject.replace("\n", "") + "\n"
+    first = True
     for l in f:
         if l == "---\n":
             break
+        if first:
+            c.message += "\n"
+            first = False
         c.message += l
     diff = ""
     for l in f:

+ 22 - 1
dulwich/tests/test_patch.py

@@ -83,10 +83,31 @@ Subject: [PATCH 1/2] Remove executable bit from prey.ico (triggers a lintian war
         self.assertEquals("Jelmer Vernooij <jelmer@samba.org>", c.committer)
         self.assertEquals("Jelmer Vernooij <jelmer@samba.org>", c.author)
         self.assertEquals("Remove executable bit from prey.ico "
-            "(triggers a lintian warning).", c.message)
+            "(triggers a lintian warning).\n", c.message)
         self.assertEquals(""" pixmaps/prey.ico |  Bin 9662 -> 9662 bytes
  1 files changed, 0 insertions(+), 0 deletions(-)
  mode change 100755 => 100644 pixmaps/prey.ico
 
 """, diff)
         self.assertEquals("1.7.0.4", version)
+
+    def test_extract_spaces(self):
+        text = """From ff643aae102d8870cac88e8f007e70f58f3a7363 Mon Sep 17 00:00:00 2001
+From: Jelmer Vernooij <jelmer@samba.org>
+Date: Thu, 15 Apr 2010 15:40:28 +0200
+Subject:  [Dulwich-users] [PATCH] Added unit tests for
+ dulwich.object_store.tree_lookup_path.
+
+* dulwich/tests/test_object_store.py
+  (TreeLookupPathTests): This test case contains a few tests that ensure the
+   tree_lookup_path function works as expected.
+---
+ pixmaps/prey.ico |  Bin 9662 -> 9662 bytes
+ 1 files changed, 0 insertions(+), 0 deletions(-)
+ mode change 100755 => 100644 pixmaps/prey.ico
+
+-- 
+1.7.0.4
+"""
+        c, diff, version = git_am_patch_split(StringIO(text))
+        self.assertEquals('Added unit tests for dulwich.object_store.tree_lookup_path.\n\n* dulwich/tests/test_object_store.py\n  (TreeLookupPathTests): This test case contains a few tests that ensure the\n   tree_lookup_path function works as expected.\n', c.message)