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
Member

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.

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
@codecov-io
Copy link

codecov-io 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.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 14, 2019
Copy link
Contributor

@zeripath zeripath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 14, 2019
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels 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
@lafriks
Copy link
Member

lafriks commented Mar 14, 2019

Can you please backport this to 1.7 release branch

@mrsdizzie
Copy link
Member Author

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

@techknowlogick
Copy link
Member

@mrsdizzie yup, that’s exactly it

@lafriks
Copy link
Member

lafriks 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
…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
@techknowlogick techknowlogick added the backport/done All backports for this PR have been created label Mar 14, 2019
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants