Skip to content

Proof of concept fix for git diff parsing failure on warn [Issue #574] #585

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

Closed
wants to merge 2 commits into from

Conversation

aalong-tr
Copy link

@aalong-tr aalong-tr commented Jun 14, 2022

Your checklist for this pull request

🚨Please review the guidelines for contributing to this repository.

  • Ensure all commits include DCO sign-off.
  • Ensure that your contributions pass unit testing.
  • Ensure that your contributions contain documentation if applicable.

Description

SSH warnings and other unexpected output from git diff can create cryptic errors, as the diff parser assumes that the first line of a diff will always provide a file name for consideration. To mitigate this, ignore lines with unexpected formatting until the first line with a file header is reached.

Given that the problem code is deep in the internals of diff.rb, I have taken a somewhat aggressive white-box testing approach to my accompanying unit test, which I acknowledge may prove brittle if the internals of the class change. I am open to alternative strategies as per the maintainers' recommendations.

Prospective fix for Issue #574

Signed-off-by: Drew Long <drew@taskrabbit.com>
@aalong-tr aalong-tr force-pushed the graceful-diff-warnings branch from d340c84 to b7da9ab Compare June 14, 2022 15:38
@jcouball
Copy link
Member

While this might do for a temporary fix, I don't like this solution because while it filters most things out, it could still result in a false positive.

The real problem here is this line:

git_cmd = "#{Git::Base.config.binary_path} #{global_opts} #{cmd} #{opts} #{command_opts[:redirect]} 2>&1"

Which forces STDERR to be captured along with STDOUT. This causes problems in a numerous places.

Needless to say, fixing this would take a lot more effort than your quick hack.

Let me consider this a bit more. As always, I am open to additional feedback.

@aalong-tr
Copy link
Author

Thank you for following up! I had figured that stderr was getting conflated with the rest of the output but hadn't found where the command was actually run, and wasn't certain to what extent the library relies on stderr in other scenarios.

I definitely agree that my solution is crude, and risks silently swallowing other types of problems; but at minimum, process_full_diff should probably offer a more graceful failure mode, as the current exception for unexpected output is very difficult to reason about.

Thanks again, both for the extra context and for your contributions to open source.

@jcouball
Copy link
Member

jcouball commented Mar 8, 2023

@aalong-tr I am closing this in favor of #617 which will fix the underlying problem reported in #574. Happy to have your feedback there if you would like.

@jcouball jcouball closed this Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants