Honor rebase.autoStash when pulling with rebase - #3021
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
libgit2 doesn't autostash for rebase, so a pull-rebase failed whenever the working tree had uncommitted changes. When rebase.autoStash is set, stash tracked changes before the rebase and pop them afterwards. If the rebase aborts we still restore the tree; if the pop conflicts the stash is kept, matching git.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes pull-with-rebase honor the
rebase.autoStashgit config so a dirty working tree no longer blocks the pull, closing #3018.libgit2 doesn't do autostash for rebase itself, so
merge_upstream_rebasefailed outright when there were uncommitted changes to tracked files. The old manual workaround was stash -> pull -> pop by hand (or dropping to a terminal).When
rebase.autoStashis true, I stash the tracked changes before running the rebase and pop them back afterwards. Untracked files are left alone, which is what git's autostash does. If the config is false or unset, or the tree is clean, nothing changes from before.A couple of the fiddly cases, since this touches user data:
conflict_free_rebaseaborts it and puts HEAD back), the stash is still popped so the working tree is restored to how it started, then the rebase error is surfaced.I kept the scope to the config since that's what most people hit; happy to wire up an explicit toggle in the pull popup too if you'd prefer that as a follow-up.
Tests (in
merge_rebase.rs):test_autostash_restores_dirty_tree— clone one ahead / one behind upstream,rebase.autoStashon, uncommitted edit on a tracked file; after the pull the upstream commit is rebased in, the tree is clean, the dirty edit is back, and no stash entry lingers.test_autostash_noop_on_clean_tree— same config but a clean tree; pull rebases normally and creates no stash.cargo test -p asyncgit --lib-> 179 passed.cargo fmt --checkclean,cargo clippy -p asyncgitclean.