summaryrefslogtreecommitdiff
path: root/git/test/fixtures/diff_patch_unsafe_paths
diff options
context:
space:
mode:
authorVincent Driessen <me@nvie.com>2016-04-19 23:41:01 +0200
committerVincent Driessen <me@nvie.com>2016-04-19 23:46:54 +0200
commit7fbc182e6d4636f67f44e5893dee3dcedfa90e04 (patch)
tree2e761da1ed007fbbeb1668eaf97c4d09be1d6920 /git/test/fixtures/diff_patch_unsafe_paths
parent504870e633eeb5fc1bd7c33b8dde0eb62a5b2d12 (diff)
downloadgitpython-7fbc182e6d4636f67f44e5893dee3dcedfa90e04.tar.gz
Fix diff patch parser for paths with unsafe chars
This specifically covers the cases where unsafe chars occur in path names, and git-diff -p will escape those. From the git-diff-tree manpage: > 3. TAB, LF, double quote and backslash characters in pathnames are > represented as \t, \n, \" and \\, respectively. If there is need > for such substitution then the whole pathname is put in double > quotes. This patch checks whether or not this has happened and will unescape those paths accordingly. One thing to note here is that, depending on the position in the patch format, those paths may be prefixed with an a/ or b/. I've specifically made sure to never interpret a path that actually starts with a/ or b/ incorrectly. Example of that subtlety below. Here, the actual file path is "b/normal". On the diff file that gets encoded as "b/b/normal". diff --git a/b/normal b/b/normal new file mode 100644 index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94d8859a54 --- /dev/null +++ b/b/normal @@ -0,0 +1 @@ +dummy content Here, we prefer the "---" and "+++" lines' values. Note that these paths start with a/ or b/. The only exception is the value "/dev/null", which is handled as a special case. Suppose now the file gets moved "b/moved", the output of that diff would then be this: diff --git a/b/normal b/b/moved similarity index 100% rename from b/normal rename to b/moved We prefer the "rename" lines' values in this case (the "diff" line is always a last resort). Take note that those lines are not prefixed with a/ or b/, but the ones in the "diff" line are (just like the ones in "---" or "+++" lines).
Diffstat (limited to 'git/test/fixtures/diff_patch_unsafe_paths')
-rw-r--r--git/test/fixtures/diff_patch_unsafe_paths75
1 files changed, 75 insertions, 0 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\""