Finally fix diff names (#13136)

* 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>

Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
zeripath 2020-10-14 05:49:33 +01:00 committed by GitHub
parent aa73b7b7e5
commit edfebe65b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 124 deletions

View file

@ -90,9 +90,9 @@ func TestParsePatch_singlefile(t *testing.T) {
tests := []testcase{
{
name: "readme.md2readme.md",
gitdiff: `diff --git "a/README.md" "b/README.md"
--- a/README.md
+++ b/README.md
gitdiff: `diff --git "\\a/README.md" "\\b/README.md"
--- "\\a/README.md"
+++ "\\b/README.md"
@@ -1,3 +1,6 @@
# gitea-github-migrator
+
@ -102,9 +102,10 @@ func TestParsePatch_singlefile(t *testing.T) {
+ cut off
+ cut off
`,
addition: 4,
deletion: 1,
filename: "README.md",
addition: 4,
deletion: 1,
filename: "README.md",
oldFilename: "README.md",
},
{
name: "A \\ B",
@ -119,16 +120,17 @@ func TestParsePatch_singlefile(t *testing.T) {
Docker Pulls
+ cut off
+ cut off`,
addition: 4,
deletion: 1,
filename: "A \\ B",
addition: 4,
deletion: 1,
filename: "A \\ B",
oldFilename: "A \\ B",
},
{
name: "really weird filename",
gitdiff: `diff --git a/a b/file b/a a/file b/a b/file b/a a/file
gitdiff: `diff --git "\\a/a b/file b/a a/file" "\\b/a b/file b/a a/file"
index d2186f1..f5c8ed2 100644
--- a/a b/file b/a a/file
+++ b/a b/file b/a a/file
--- "\\a/a b/file b/a a/file"
+++ "\\b/a b/file b/a a/file"
@@ -1,3 +1,2 @@
Create a weird file.
@ -141,10 +143,10 @@ index d2186f1..f5c8ed2 100644
},
{
name: "delete file with blanks",
gitdiff: `diff --git a/file with blanks b/file with blanks
gitdiff: `diff --git "\\a/file with blanks" "\\b/file with blanks"
deleted file mode 100644
index 898651a..0000000
--- a/file with blanks
--- "\\a/file with blanks"
+++ /dev/null
@@ -1,5 +0,0 @@
-a blank file
@ -153,9 +155,10 @@ index 898651a..0000000
-
-the 5th line is the last
`,
addition: 0,
deletion: 5,
filename: "file with blanks",
addition: 0,
deletion: 5,
filename: "file with blanks",
oldFilename: "file with blanks",
},
{
name: "rename a—as",
@ -171,7 +174,7 @@ rename to "a\342\200\224as"
},
{
name: "rename with spaces",
gitdiff: `diff --git a/a b/file b/a a/file b/a b/a a/file b/b file
gitdiff: `diff --git "\\a/a b/file b/a a/file" "\\b/a b/a a/file b/b file"
similarity index 100%
rename from a b/file b/a a/file
rename to a b/a a/file b/b file