Skip to content

Fix: Git warning messages incorrectly shown with error styling#309944

Open
Nedunchezhiyan-M wants to merge 2 commits intomicrosoft:mainfrom
Nedunchezhiyan-M:fix/git-warning-message-severity
Open

Fix: Git warning messages incorrectly shown with error styling#309944
Nedunchezhiyan-M wants to merge 2 commits intomicrosoft:mainfrom
Nedunchezhiyan-M:fix/git-warning-message-severity

Conversation

@Nedunchezhiyan-M
Copy link
Copy Markdown

Fixes #280834

What changed

When git or SSH outputs a line prefixed with warning: (e.g. Warning: Permanently added 'gitlab.com' to the list of known hosts), VS Code was displaying the notification with error-level styling (red icon, modal). This is misleading — the message is informational and a normal part of SSH's first-time host-key acceptance flow.

Root cause: The default branch of the gitErrorCode switch in CommandCenter never inspected the raw message text, so all unrecognized errors fell through as type = 'error'.

Fix: In the default case, test the raw stderr/stdout for a leading warning: prefix (case-insensitive, multiline). When matched:

  • Set type = 'warning' → yellow warning icon instead of red error icon
  • Set options.modal = false → non-blocking, consistent with how Conflict and CherryPickConflict are shown
  • Strip the warning: prefix from hintLines (mirrors existing error: stripping) so the notification reads Git: Permanently added ... rather than Git: Warning: Permanently added ...

All existing known GitErrorCode cases are unaffected.

How to test

  1. Remove a known host entry or use a fresh SSH key:
    ssh-keygen -R gitlab.com
  2. In VS Code, run Git: Push to a GitLab repo via SSH
  3. Before: red modal error notification
    After: yellow non-modal warning notification reading Git: Permanently added 'gitlab.com' to the list of known hosts
  4. Verify actual git errors (authentication failure, push rejected, etc.) still show as red errors

Notes

A previous attempt was opened and closed by its author who thought the issue was already addressed elsewhere — it was not. This PR implements the same intent but also strips the warning: prefix from the displayed text.

Nedunchezhiyan-M and others added 2 commits April 15, 2026 00:33
When git or SSH outputs lines prefixed with "warning:" (e.g.
"Warning: Permanently added 'gitlab.com' to the list of known hosts"),
VS Code was showing the notification with error-level styling (red icon)
because the default case in the command error handler never inspected the
message severity.

Check for a leading "warning:" prefix (case-insensitive) in the raw
stderr/stdout before showing the notification. When detected, use warning
styling and make the notification non-modal, matching the treatment of
known warning-level git error codes such as Conflict and StashConflict.
Also strip the "warning: " prefix from the displayed hint text so it is
not doubled up ("Git: Warning: ...").

Fixes microsoft#280834
@vs-code-engineering
Copy link
Copy Markdown
Contributor

vs-code-engineering bot commented Apr 14, 2026

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • extensions/git/src/commands.ts

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.

Git Warning Message Incorrectly Styled as Error

2 participants