Fix over-zealous deletions with certain checkout options by Caleb-T-Owens · Pull Request #7401 · libgit2/libgit2 · GitHub
Skip to content

Fix over-zealous deletions with certain checkout options - #7401

Open
Caleb-T-Owens wants to merge 2 commits into
libgit2:mainfrom
Caleb-T-Owens:caleb/exploring-checkout
Open

Caleb-T-Owens wants to merge 2 commits into
libgit2:mainfrom
Caleb-T-Owens:caleb/exploring-checkout

Conversation

@Caleb-T-Owens

Copy link
Copy Markdown
Contributor

At GitButler, we've run into an issue when doing a checkout_head with remove_untracked(true) and remove_ignored(false).

It seems like the checkout skips over these directories that contain no tracked files which results in their deletion, resulting in data loss.

This PR was a little exploration into the problem, but I'm always very nervous about making changes with C code, so please take this with a pinch of salt.

The solution implemented is to have an extra check that considers a folder for descent if it is not git ignored, is removable, but isn't empty.

Thanks for your time.

Certain force checkout scenarios are removing whole directories when
they should be removing just some of the contents of the directory.

A key example is when a directory contains both ignored and untracked
files. If an operation to checkout head with the options to remove
untracked is set, the whole directory will be removed, destorying the
ignored files.
This change affects checkouts that want to remove either untracked files
or ignored files, but not both with a particular checkout.

Previously, these directories were let to fall through, which resulted
in them getting dropped.

This change adds an extra condition for a folder to be considered for
checkout descent if it is not git ignored, is removable, but isn't
empty.

This branch has not been deployed

No deployments
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 checkout force deletes tracked directory containing untracked files

1 participant