Skip to content

Handle dirty working tree when checking out clones#5218

Merged
premun merged 3 commits intodotnet:mainfrom
premun:prvysoky/cleans
Aug 28, 2025
Merged

Handle dirty working tree when checking out clones#5218
premun merged 3 commits intodotnet:mainfrom
premun:prvysoky/cleans

Conversation

@premun
Copy link
Copy Markdown
Member

@premun premun commented Aug 28, 2025

Resolves the following frequent exception:

Failed to check out 3ac608c737eabed78486ee3fe598e76a889b6015 in /mnt/datadir/tmp/E1F74BB5AEE5F69C
Exit code: 1
Std err:
error: Your local changes to the following files would be overwritten by checkout:
src/Microsoft.CodeAnalysis.NetAnalyzers/README.md
Please commit your changes or stash them before you switch branches.
Aborting

We do clean after the checkout but if the repo had all the right refs already and was dirty, it does not work

Copilot AI review requested due to automatic review settings August 28, 2025 13:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a common git checkout failure that occurs when local changes in cloned repositories would be overwritten by checking out to a different commit. The solution implements error handling to clean the working directory when such conflicts arise.

Key changes:

  • Adds error handling around git checkout operations to detect overwrite conflicts
  • Implements automatic repository cleaning using git clean -fdqx when checkout fails due to dirty working tree
  • Wraps the checkout logic in try-catch to gracefully handle and resolve the documented exception

@premun premun merged commit 0ddf52e into dotnet:main Aug 28, 2025
5 of 9 checks passed
@premun premun deleted the prvysoky/cleans branch August 28, 2025 14:36
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.

3 participants