-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: RunCommand() should not throw when exit is checked #11871
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: RunCommand() should not throw when exit is checked #11871
Conversation
Some methods intend to check the Git output, but the command always throws at exit. throwOnErrorExit need to be configurable for these methods. This occurs for instance when checking the characters in a branch name and staging files.
src/app/GitCommands/Git/GitModule.cs
Outdated
GitArgumentBuilder args = new("check-ref-format") | ||
{ | ||
"--branch", | ||
branchName.QuoteNE() | ||
}; | ||
return _gitExecutable.RunCommand(args); | ||
return _gitExecutable.RunCommand(args, throwOnErrorExit: false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change this call to the standard execute that return result to get rid of the printout too.
src/app/GitCommands/Git/GitModule.cs
Outdated
@@ -1779,7 +1779,8 @@ public bool StageFile(string file) | |||
{ | |||
"--add", | |||
file.ToPosixPath().Quote() | |||
}); | |||
}, | |||
throwOnErrorExit: false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the result of StageFile
is never evaluated, rather remove the return value and throw.
If there are known uncritical exit codes, please handle them explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, changes requires changes of the plugin interface though.
Some methods intend to check the Git output, but the command always throws at exit. throwOnErrorExit need to be configurable for these methods. This occurs for instance when checking the characters in a branch name and staging files. Avoid echoing the branchname when creating a branch (as output in RunCommand() is written to the console).
Fixes #11869
Proposed changes
Some methods intend to check the Git output, but the command always throws at exit.
throwOnErrorExit need to be configurable for these methods.
Quotes were additionally quouted too (done in QuoteNE())
This occurs for instance when checking the characters in a branch name and staging files.
Note that the command still echoes the branchname to the console.
While Git allows quotes in branch names, Windows does not (this is a file) allow quotes in the name.
Note: There are a few calls of RunCommand() that could be supressed in addition to those thatactually check the output, but I left it at the checked calls.
This cannot be be too commonly occurring as the throwOnErrorExit checks were added in 4.1 or 4.0.
Screenshots
Before
NBug
After
Test methodology
Manual
Merge strategy
I agree that the maintainer squash merge this PR (if the commit message is clear).
✒️ I contribute this code under The Developer Certificate of Origin.