* Finally fix diff names #12771 attempted to fix diff by avoiding the git diff line as it is possible to have an ambiguous line here. #12254 attempted to fix diff by assuming that names would quoted if they needed to be and if one was quoted then both would be. Both of these were wrong. I have now discovered `--src-prefix` and `--dst-prefix` which means that we can set this in such a way to force the git diff to always be unambiguous. Therefore this PR rollsback most of the changes in #12771 and uses these options to fix this. Signed-off-by: Andrew Thornton <art27@cantab.net> * Update services/gitdiff/gitdiff.go * Update services/gitdiff/gitdiff.go * Update modules/repofiles/temp_repo.go * fix test Signed-off-by: Andrew Thornton <art27@cantab.net>
Showing the changes to services/gitdiff/gitdiff_test.go (1 of 3 files). Show all
Unified · Split
| @@ -90,9 +90,9 @@ func TestParsePatch_singlefile(t *testing.T) { · 89 unmodified lines | ||
| 90 | 90 | tests := []testcase{ |
| 91 | 91 | { |
| 92 | 92 | name: "readme.md2readme.md", |
| 93 | − gitdiff: `diff --git "a/README.md" "b/README.md" | |
| 94 | −--- a/README.md | |
| 95 | −+++ b/README.md | |
| 93 | + gitdiff: `diff --git "\\a/README.md" "\\b/README.md" | |
| 94 | +--- "\\a/README.md" | |
| 95 | ++++ "\\b/README.md" | |
| 96 | 96 | @@ -1,3 +1,6 @@ |
| 97 | 97 | # gitea-github-migrator |
| 98 | 98 | + |
| @@ -102,9 +102,10 @@ func TestParsePatch_singlefile(t *testing.T) { · 3 unmodified lines | ||
| 102 | 102 | + cut off |
| 103 | 103 | + cut off |
| 104 | 104 | `, |
| 105 | − addition: 4, | |
| 106 | − deletion: 1, | |
| 107 | − filename: "README.md", | |
| 105 | + addition: 4, | |
| 106 | + deletion: 1, | |
| 107 | + filename: "README.md", | |
| 108 | + oldFilename: "README.md", | |
| 108 | 109 | }, |
| 109 | 110 | { |
| 110 | 111 | name: "A \\ B", |
| @@ -119,16 +120,17 @@ func TestParsePatch_singlefile(t *testing.T) { · 8 unmodified lines | ||
| 119 | 120 | Docker Pulls |
| 120 | 121 | + cut off |
| 121 | 122 | + cut off`, |
| 122 | − addition: 4, | |
| 123 | − deletion: 1, | |
| 124 | − filename: "A \\ B", | |
| 123 | + addition: 4, | |
| 124 | + deletion: 1, | |
| 125 | + filename: "A \\ B", | |
| 126 | + oldFilename: "A \\ B", | |
| 125 | 127 | }, |
| 126 | 128 | { |
| 127 | 129 | name: "really weird filename", |
| 128 | − gitdiff: `diff --git a/a b/file b/a a/file b/a b/file b/a a/file | |
| 130 | + gitdiff: `diff --git "\\a/a b/file b/a a/file" "\\b/a b/file b/a a/file" | |
| 129 | 131 | index d2186f1..f5c8ed2 100644 |
| 130 | −--- a/a b/file b/a a/file | |
| 131 | −+++ b/a b/file b/a a/file | |
| 132 | +--- "\\a/a b/file b/a a/file" | |
| 133 | ++++ "\\b/a b/file b/a a/file" | |
| 132 | 134 | @@ -1,3 +1,2 @@ |
| 133 | 135 | Create a weird file. |
| 134 | 136 | |
| @@ -141,10 +143,10 @@ index d2186f1..f5c8ed2 100644 · 6 unmodified lines | ||
| 141 | 143 | }, |
| 142 | 144 | { |
| 143 | 145 | name: "delete file with blanks", |
| 144 | − gitdiff: `diff --git a/file with blanks b/file with blanks | |
| 146 | + gitdiff: `diff --git "\\a/file with blanks" "\\b/file with blanks" | |
| 145 | 147 | deleted file mode 100644 |
| 146 | 148 | index 898651a..0000000 |
| 147 | −--- a/file with blanks | |
| 149 | +--- "\\a/file with blanks" | |
| 148 | 150 | +++ /dev/null |
| 149 | 151 | @@ -1,5 +0,0 @@ |
| 150 | 152 | -a blank file |
| @@ -153,9 +155,10 @@ index 898651a..0000000 · 2 unmodified lines | ||
| 153 | 155 | - |
| 154 | 156 | -the 5th line is the last |
| 155 | 157 | `, |
| 156 | − addition: 0, | |
| 157 | − deletion: 5, | |
| 158 | − filename: "file with blanks", | |
| 158 | + addition: 0, | |
| 159 | + deletion: 5, | |
| 160 | + filename: "file with blanks", | |
| 161 | + oldFilename: "file with blanks", | |
| 159 | 162 | }, |
| 160 | 163 | { |
| 161 | 164 | name: "rename a—as", |
| @@ -171,7 +174,7 @@ rename to "a\342\200\224as" · 9 unmodified lines | ||
| 171 | 174 | }, |
| 172 | 175 | { |
| 173 | 176 | name: "rename with spaces", |
| 174 | − gitdiff: `diff --git a/a b/file b/a a/file b/a b/a a/file b/b file | |
| 177 | + gitdiff: `diff --git "\\a/a b/file b/a a/file" "\\b/a b/a a/file b/b file" | |
| 175 | 178 | similarity index 100% |
| 176 | 179 | rename from a b/file b/a a/file |
| 177 | 180 | rename to a b/a a/file b/b file |