-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Throw on non-zero exit code and on stderror output #9056
Conversation
There are some more situations where errors are handled, where IsGitErrorMessage() parses the output. Some situations like "describe" and in RevParse() (that should have --quiet --verify and check status anyway) are handled in this PR. diff --git a/GitCommands/Git/GitModule.cs b/GitCommands/Git/GitModule.cs
index 6aace..9124d 100644
--- a/GitCommands/Git/GitModule.cs
+++ b/GitCommands/Git/GitModule.cs
@@ -2507,14 +2507,12 @@ public IReadOnlyList<GitItemStatus> GetTreeFiles(ObjectId commitId, bool full)
bool excludeAssumeUnchangedFiles = true, bool excludeSkipWorktreeFiles = true,
UntrackedFilesMode untrackedFiles = UntrackedFilesMode.Default)
{
- var output = _gitExecutable.GetOutput(
- GitCommandHelpers.GetAllChangedFilesCmd(excludeIgnoredFiles, untrackedFiles));
-
- List<GitItemStatus> result = _getAllChangedFilesOutputParser.Parse(output).ToList();
- if (IsGitErrorMessage(output))
+ var exec = _gitExecutable.Execute(GitCommandHelpers.GetAllChangedFilesCmd(excludeIgnoredFiles, untrackedFiles));
+ List<GitItemStatus> result = _getAllChangedFilesOutputParser.Parse(exec.StandardOutput).ToList();
+ if (!exec.ExitedSuccessfully)
{
// No simple way to pass the error message, create fake file
- result.Add(createErrorGitItemStatus(output));
+ result.Add(createErrorGitItemStatus(exec.StandardError));
}
if (!excludeAssumeUnchangedFiles || !excludeSkipWorktreeFiles) |
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.
👍 with few comments
a129bc6
to
71b890b
Compare
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.
+0
In general very much needed, good time to add this now.
Will use myself.
(only briely looked at the code now.)
Edit: Missing Working directory for exceptions
Also, the exception message do not have to be displayed in the log part, details is enough
(not checked if this PR really changed this)
I get an exception now when starting up, some dashboard repo does not exist I assume
GitCommands/Git/GitModule.cs
Outdated
"--pretty=format:\"%T\"", | ||
"--max-count=1" | ||
"--max-count=1", | ||
$"-- {stashName}^3" |
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.
-- separates paths, stashNane is a ref
The order is correct now though
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.
The commit message contains the git error:
Fixup git arguments for GetStashDiffFiles
fatal: ambiguous argument 'stash@{0}^3': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
sounds a bit confusing to me; but works well
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.
stashName is not a path, so it should not be separated with --
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.
Without "--", git outputs the above fatal error with non-zero exit code.
!string.IsNullOrEmpty(secondRevision) && | ||
!string.IsNullOrEmpty(firstRevision) && | ||
!secondRevision.IsArtificial() && | ||
!firstRevision.IsArtificial() | ||
? GitCommandCache | ||
: null; | ||
|
||
var patch = _gitExecutable.GetOutput( | ||
bool nonZeroGitExitCode = firstId == ObjectId.WorkTreeId && secondId is not null && !isTracked; |
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.
Should not be here but at the caller (may check arguments).
!isTracked cannot use git-diff (regardless of first/second commit).
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.
repro:
- create a new file (untracked)
- select
Working directory
, thenCtrl
+click
the checked out commit, which turns the added (exit code 0) into a removed file from this perspective (exit code 1)
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.
The caller should not request this information, it is meaningless.
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.
We need to have at least a comment explaining this. It is not obvious what this check is and why it is needed.
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.
Should not be here but at the caller (may check arguments).
!isTracked cannot use git-diff (regardless of first/second commit).
The caller should not request this information, it is meaningless.
Explain it in other words, please.
It is not obvious what this check is and why it is needed.
Would you better understand it with nonZeroGitExitCodeExpected
?
It is used once - in the next statement.
cannot reproduce |
71b890b
to
94f6c35
Compare
Failure in repo without tags (similar to git-describe). Edit: fixed negated check
|
I have experienced a few more situations where Git exists with non-zero. Edit: I also get warnings like |
Thank you. I have cherry-picked them to my work branch |
Yes, please, especially the exception text taken from |
One more push with a fix for git-diff with core.safecrlf |
Good catch! This might also be the cause why some of the ROT tests work unstable (and have been disabled). |
I could not reproduce these exceptions. Could you provide details for the first four |
Added two commits where error is OK (this was the remaining fatal: reference I saw too) The commit messages has descriptions |
Line patches exit with error and error text if patches cannot be applied |
git-mergetool can exit with error if user do not complete the merge diff --git a/GitCommands/Git/GitModule.cs b/GitCommands/Git/GitModule.cs
index e6ca8..6f2dd 100644
--- a/GitCommands/Git/GitModule.cs
+++ b/GitCommands/Git/GitModule.cs
@@ -880,7 +880,7 @@ public void RunMergeTool(string? fileName = "", string? customTool = null)
{ !string.IsNullOrWhiteSpace(fileName), "--" },
fileName.ToPosixPath().QuoteNE()
};
- using var process = _gitExecutable.Start(args, createWindow: true);
+ using var process = _gitExecutable.Start(args, createWindow: true, throwOnErrorOutput: false);
process.WaitForExit();
}
|
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.
👍
Hello @RussKie! Because you've told me to reset the custom auto-merge settings, I'll use the configured settings for this repository when I'm merging this pull request. |
I have few questions, disabling the auto-merge for now. |
- Ignore StandardError output - Use it only as exception text on non-zero exit code makes gitextensions#9056 less intercepting, fixes gitextensions#9462
- Ignore StandardError output - Use it only as exception text on non-zero exit code makes gitextensions#9056 less intercepting, fixes gitextensions#9462
- Ignore StandardError output - Use it only as exception text on non-zero exit code makes gitextensions#9056 less intercepting, fixes gitextensions#9462 Except for the actual changes in Executable.cs, this is just renaming the argument to match the changed functionality.
- Ignore StandardError output - Use it only as exception text on non-zero exit code makes gitextensions#9056 less intercepting, fixes gitextensions#9462 Except for the actual changes in Executable.cs, this is just renaming the argument to match the changed functionality.
Fixes #6527
Fixes #8263
Fixes #8632
Closes #8906 as obsolete
Closes #8961 as obsolete
Proposed changes
ExternalOperationException
if a started process exits with a non-0 exit code or if the process printed output toStandardError
Screenshots
Before
After
Test methodology
Test environment(s)
✒️ I contribute this code under The Developer Certificate of Origin.