Pārlūkot izejas kodu

Update diff header index line

The documentation
https://git-scm.com/docs/diff-format#_generating_patches_with_p indicates that "The
index line includes the SHA-1 checksum before and after the change. The <mode>
is included if the file mode does not change; otherwise, separate lines
indicate the old and the new mode."

Update gen_diff_header to match the documentation and CGit behavior.
Boris Feld 6 gadi atpakaļ
vecāks
revīzija
064ef73158
3 mainītis faili ar 7 papildinājumiem un 7 dzēšanām
  1. 1 1
      dulwich/patch.py
  2. 4 4
      dulwich/tests/test_patch.py
  3. 2 2
      dulwich/tests/test_porcelain.py

+ 1 - 1
dulwich/patch.py

@@ -247,7 +247,7 @@ def gen_diff_header(paths, modes, shas):
         else:
             yield ("deleted file mode %o\n" % old_mode).encode('ascii')
     yield b"index " + shortid(old_sha) + b".." + shortid(new_sha)
-    if new_mode is not None:
+    if new_mode is not None and old_mode is not None:
         yield (" %o" % new_mode).encode('ascii')
     yield b"\n"
 

+ 4 - 4
dulwich/tests/test_patch.py

@@ -278,7 +278,7 @@ class DiffTests(TestCase):
         self.assertEqual([
              b'diff --git a/bar.txt b/bar.txt',
              b'new file mode 644',
-             b'index 0000000..a116b51 644',
+             b'index 0000000..a116b51',
              b'--- /dev/null',
              b'+++ b/bar.txt',
              b'@@ -0,0 +1,2 @@',
@@ -324,7 +324,7 @@ class DiffTests(TestCase):
         self.assertEqual([
             b'diff --git a/added.txt b/added.txt',
             b'new file mode 644',
-            b'index 0000000..76d4bb8 644',
+            b'index 0000000..76d4bb8',
             b'--- /dev/null',
             b'+++ b/added.txt',
             b'@@ -0,0 +1 @@',
@@ -396,7 +396,7 @@ class DiffTests(TestCase):
         self.assertEqual([
              b'diff --git a/bar.txt b/bar.txt',
              b'new file mode 644',
-             b'index 0000000..a116b51 644',
+             b'index 0000000..a116b51',
              b'--- /dev/null',
              b'+++ b/bar.txt',
              b'@@ -0,0 +1,2 @@',
@@ -494,7 +494,7 @@ class DiffTests(TestCase):
         self.assertEqual([
             b'diff --git a/bar.png b/bar.png',
             b'new file mode 644',
-            b'index 0000000..06364b7 644',
+            b'index 0000000..06364b7',
             b'Binary files /dev/null and b/bar.png differ'
             ], f.getvalue().splitlines())
 

+ 2 - 2
dulwich/tests/test_porcelain.py

@@ -574,7 +574,7 @@ Test message.
 
 diff --git a/somename b/somename
 new file mode 100644
-index 0000000..ea5c7bf 100644
+index 0000000..ea5c7bf
 --- /dev/null
 +++ b/somename
 @@ -0,0 +1 @@
@@ -611,7 +611,7 @@ Test message.
 
 diff --git a/somename b/somename
 new file mode 100644
-index 0000000..ea5c7bf 100644
+index 0000000..ea5c7bf
 --- /dev/null
 +++ b/somename
 @@ -0,0 +1 @@