Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ParsePatch function to work with quoted diff --git strings #6323

Merged
merged 3 commits into from Mar 14, 2019

Conversation

@mrsdizzie
Copy link
Contributor

commented Mar 14, 2019

This fixes the ParsePatch function to work when a diff puts the a/ b/ filenames inside double quotes. See #6309 for more details.

Added some new tests for this function as well.

mrsdizzie added some commits Mar 14, 2019

Fix ParsePatch to work properly with quoted diff --git string
Currently ParsePatch fails when a diff contains a quoted diff line like:

diff --git "a/file" "b/file"

This patch makes it properly parse the line when that happens.

Fixes #6309
@codecov-io

This comment has been minimized.

Copy link

commented Mar 14, 2019

Codecov Report

Merging #6323 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6323      +/-   ##
==========================================
+ Coverage    38.8%   38.83%   +0.03%     
==========================================
  Files         359      359              
  Lines       51175    51182       +7     
==========================================
+ Hits        19857    19877      +20     
+ Misses      28447    28435      -12     
+ Partials     2871     2870       -1
Impacted Files Coverage Δ
models/git_diff.go 68.99% <100%> (+2.9%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7542bf...5b7961d. Read the comment docs.

@zeripath
Copy link
Contributor

left a comment

I wonder if there's a way of testing the whole pipeline through an integration test. But this is not necessarily required for this case. I just worry that dumping the diffs in rather than generating the diffs means that we can't add more pathological cases.

(If you follow the example in https://github.com/go-gitea/gitea/blob/master/integrations/git_test.go or https://github.com/go-gitea/gitea/blob/master/integrations/ssh_key_test.go you should be able to create story like tests.)

if hasQuote {
// When /a and /b are surrounded by double quotes, we want to first
// make sure we keep everything the quotes and then strip out the leading /a /b
a = strings.Replace(line[beg:middle], "\"a/", "\"", -1)

This comment has been minimized.

Copy link
@zeripath

zeripath Mar 14, 2019

Contributor

Why don't we just unquote then remove the first two runes. Using replace here is just complicating things.

Consider the, admittedly unusual case, of a file called: /a/a/a/a which is git mv and editted to /b/b/b/b. Your replace will just remove the entire names. (Yes you could change the replace to only replace one time but removing the first two characters is your aim.)

This comment has been minimized.

Copy link
@mrsdizzie

mrsdizzie Mar 14, 2019

Author Contributor

Ah yea that makes more sense/less complicated thx. Slipped my mind to change the string after unquoting. I've changed it to just remove the first 2 characters afterwards as you've suggested thx!

I agree entire integration tests are a good goal but I don't want to complicate or hold up what is otherwise just a couple line bug fix + adding a unit test here.

I'll look into understanding the integration testing more and perhaps help with something in a separate request if I can.

@GiteaBot GiteaBot added lgtm/need 1 and removed lgtm/need 2 labels Mar 14, 2019

@GiteaBot GiteaBot added lgtm/done and removed lgtm/need 1 labels Mar 14, 2019

@lafriks lafriks added the kind/bug label Mar 14, 2019

@lafriks lafriks added this to the 1.8.0 milestone Mar 14, 2019

@lafriks lafriks merged commit 7780ea8 into go-gitea:master Mar 14, 2019

2 checks passed

approvals/lgtm this commit looks good
continuous-integration/drone/pr the build was successful
Details
@lafriks

This comment has been minimized.

Copy link
Member

commented Mar 14, 2019

Can you please backport this to 1.7 release branch

@mrsdizzie

This comment has been minimized.

Copy link
Contributor Author

commented Mar 14, 2019

Sure, how do you backport it? Just create a pull request against release/1.7?

@techknowlogick

This comment has been minimized.

Copy link
Member

commented Mar 14, 2019

@mrsdizzie yup, that’s exactly it

@lafriks

This comment has been minimized.

Copy link
Member

commented Mar 14, 2019

Create new branch from release/v1.7 branch and cherry-pick commit 7780ea8 and submit PR to release/v1.7 branch

mrsdizzie added a commit to mrsdizzie/gitea that referenced this pull request Mar 14, 2019

Fix ParsePatch function to work with quoted diff --git strings (go-gi…
…tea#6323)

* Fix ParsePatch to work properly with quoted diff --git string

Currently ParsePatch fails when a diff contains a quoted diff line like:

diff --git "a/file" "b/file"

This patch makes it properly parse the line when that happens.

Fixes go-gitea#6309

* Add test for regular case while here

* Simplify string modification

zeripath added a commit that referenced this pull request Mar 14, 2019

Mikescher added a commit to Mikescher/gitea that referenced this pull request Mar 20, 2019

Fix ParsePatch function to work with quoted diff --git strings (go-gi…
…tea#6323)

* Fix ParsePatch to work properly with quoted diff --git string

Currently ParsePatch fails when a diff contains a quoted diff line like:

diff --git "a/file" "b/file"

This patch makes it properly parse the line when that happens.

Fixes go-gitea#6309

* Add test for regular case while here

* Simplify string modification
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
6 participants
You can’t perform that action at this time.