Skip to content

Conversation

@workbysaran
Copy link
Contributor

Resolved / Related Issues
Fixed an issue where switching git branches during an active merge conflict caused a crash due to attempting to stash unmerged changes.

Closes #16934

Steps used to test these changes

  1. Create a merge conflict in a git repository
  2. Attempt to switch branches while the merge conflict is active
  3. Verify the new dialog appears with options to "Abort merge and switch" or "Stay and resolve conflicts"
  4. Test both options work correctly
  5. Verify normal branch switching and still works as expected

IsExecutingGitAction = false;
return false;
case GitCheckoutOptions.AbortMerge:
repository.Reset(ResetMode.Hard);
Copy link

Choose a reason for hiding this comment

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

Bug: repository.Reset() is called with only ResetMode.Hard, but the LibGit2Sharp API requires a Commit object as the second parameter.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The repository.Reset() method is called with only one parameter (ResetMode.Hard) at src/Files.App/Utils/Git/GitHelpers.cs:210. The LibGit2Sharp API signature for Repository.Reset() requires two parameters: ResetMode and a Commit object. This will result in a runtime exception (e.g., ArgumentException) and application crash when the 'Abort merge and switch' feature is used.

💡 Suggested Fix

Provide the required Commit object to repository.Reset(). For example, use repository.Reset(ResetMode.Hard, repository.Head.Tip); to reset to the current head.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/Files.App/Utils/Git/GitHelpers.cs#L210

Potential issue: The `repository.Reset()` method is called with only one parameter
(`ResetMode.Hard`) at `src/Files.App/Utils/Git/GitHelpers.cs:210`. The `LibGit2Sharp`
API signature for `Repository.Reset()` requires two parameters: `ResetMode` and a
`Commit` object. This will result in a runtime exception (e.g., `ArgumentException`) and
application crash when the 'Abort merge and switch' feature is used.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 2874030

@yaira2 yaira2 added the ready for review Pull requests that are ready for review label Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Pull requests that are ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Files crashes when switching git branch during a merge conflict

2 participants