Handle patches with more than one commit line.
authorJelmer Vernooij <jelmer@samba.org>
Tue, 5 Oct 2010 21:02:47 +0000 (23:02 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 5 Oct 2010 21:02:47 +0000 (23:02 +0200)
dulwich/patch.py
dulwich/tests/test_patch.py

index 2c253df..2f60cbf 100644 (file)
@@ -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:
index 18d2444..421d701 100644 (file)
@@ -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)