diff options
Diffstat (limited to 'git/test')
-rw-r--r-- | git/test/fixtures/diff_patch_unsafe_paths | 75 | ||||
-rw-r--r-- | git/test/test_diff.py | 29 |
2 files changed, 102 insertions, 2 deletions
diff --git a/git/test/fixtures/diff_patch_unsafe_paths b/git/test/fixtures/diff_patch_unsafe_paths new file mode 100644 index 00000000..14375f79 --- /dev/null +++ b/git/test/fixtures/diff_patch_unsafe_paths @@ -0,0 +1,75 @@ +diff --git a/path/ starting with a space b/path/ starting with a space +new file mode 100644 +index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94d8859a54 +--- /dev/null ++++ b/path/ starting with a space +@@ -0,0 +1 @@ ++dummy content +diff --git "a/path/\"with-quotes\"" "b/path/\"with-quotes\"" +new file mode 100644 +index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94d8859a54 +--- /dev/null ++++ "b/path/\"with-quotes\"" +@@ -0,0 +1 @@ ++dummy content +diff --git a/path/'with-single-quotes' b/path/'with-single-quotes' +new file mode 100644 +index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94d8859a54 +--- /dev/null ++++ b/path/'with-single-quotes' +@@ -0,0 +1 @@ ++dummy content +diff --git a/path/ending in a space b/path/ending in a space +new file mode 100644 +index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94d8859a54 +--- /dev/null ++++ b/path/ending in a space +@@ -0,0 +1 @@ ++dummy content +diff --git "a/path/with\ttab" "b/path/with\ttab" +new file mode 100644 +index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94d8859a54 +--- /dev/null ++++ "b/path/with\ttab" +@@ -0,0 +1 @@ ++dummy content +diff --git "a/path/with\nnewline" "b/path/with\nnewline" +new file mode 100644 +index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94d8859a54 +--- /dev/null ++++ "b/path/with\nnewline" +@@ -0,0 +1 @@ ++dummy content +diff --git a/path/with spaces b/path/with spaces +new file mode 100644 +index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94d8859a54 +--- /dev/null ++++ b/path/with spaces +@@ -0,0 +1 @@ ++dummy content +diff --git a/path/with-question-mark? b/path/with-question-mark? +new file mode 100644 +index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94d8859a54 +--- /dev/null ++++ b/path/with-question-mark? +@@ -0,0 +1 @@ ++dummy content +diff --git "a/path/¯\\_(ツ)_|¯" "b/path/¯\\_(ツ)_|¯" +new file mode 100644 +index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94d8859a54 +--- /dev/null ++++ "b/path/¯\\_(ツ)_|¯" +@@ -0,0 +1 @@ ++dummy content +diff --git a/a/with spaces b/b/with some spaces +similarity index 100% +rename from a/with spaces +rename to b/with some spaces +diff --git a/a/ending in a space b/b/ending with space +similarity index 100% +rename from a/ending in a space +rename to b/ending with space +diff --git "a/a/\"with-quotes\"" "b/b/\"with even more quotes\"" +similarity index 100% +rename from "a/\"with-quotes\"" +rename to "b/\"with even more quotes\"" diff --git a/git/test/test_diff.py b/git/test/test_diff.py index 0c670f0b..858b3994 100644 --- a/git/test/test_diff.py +++ b/git/test/test_diff.py @@ -1,4 +1,4 @@ -#-*-coding:utf-8-*- +# coding: utf-8 # test_diff.py # Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors # @@ -145,12 +145,37 @@ class TestDiff(TestBase): assert diff_index[0].new_file assert diff_index[0].diff == fixture('diff_initial') + def test_diff_unsafe_paths(self): + output = StringProcessAdapter(fixture('diff_patch_unsafe_paths')) + res = Diff._index_from_patch_format(None, output.stdout) + + # The "Additions" + self.assertEqual(res[0].b_path, u'path/ starting with a space') + self.assertEqual(res[1].b_path, u'path/"with-quotes"') + self.assertEqual(res[2].b_path, u"path/'with-single-quotes'") + self.assertEqual(res[3].b_path, u'path/ending in a space ') + self.assertEqual(res[4].b_path, u'path/with\ttab') + self.assertEqual(res[5].b_path, u'path/with\nnewline') + self.assertEqual(res[6].b_path, u'path/with spaces') + self.assertEqual(res[7].b_path, u'path/with-question-mark?') + self.assertEqual(res[8].b_path, u'path/¯\\_(ツ)_|¯') + + # The "Moves" + # NOTE: The path prefixes a/ and b/ here are legit! We're actually + # verifying that it's not "a/a/" that shows up, see the fixture data. + self.assertEqual(res[9].a_path, u'a/with spaces') # NOTE: path a/ here legit! + self.assertEqual(res[9].b_path, u'b/with some spaces') # NOTE: path b/ here legit! + self.assertEqual(res[10].a_path, u'a/ending in a space ') + self.assertEqual(res[10].b_path, u'b/ending with space ') + self.assertEqual(res[11].a_path, u'a/"with-quotes"') + self.assertEqual(res[11].b_path, u'b/"with even more quotes"') + def test_diff_patch_format(self): # test all of the 'old' format diffs for completness - it should at least # be able to deal with it fixtures = ("diff_2", "diff_2f", "diff_f", "diff_i", "diff_mode_only", "diff_new_mode", "diff_numstat", "diff_p", "diff_rename", - "diff_tree_numstat_root") + "diff_tree_numstat_root", "diff_patch_unsafe_paths") for fixture_name in fixtures: diff_proc = StringProcessAdapter(fixture(fixture_name)) |