Skip to content

Honor rebase.autoStash when pulling with rebase - #3021

Open
ChrisJr404 wants to merge 1 commit into
gitui-org:masterfrom
ChrisJr404:feat/pull-rebase-autostash
Open

Honor rebase.autoStash when pulling with rebase#3021
ChrisJr404 wants to merge 1 commit into
gitui-org:masterfrom
ChrisJr404:feat/pull-rebase-autostash

Conversation

@ChrisJr404

Copy link
Copy Markdown

Makes pull-with-rebase honor the rebase.autoStash git config so a dirty working tree no longer blocks the pull, closing #3018.

libgit2 doesn't do autostash for rebase itself, so merge_upstream_rebase failed 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.autoStash is 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:

  • if the rebase conflicts (conflict_free_rebase aborts 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.
  • if the pop itself conflicts, git2 leaves the stash entry in place (it only drops on a clean apply), so the user still has their changes recoverable — same as git.

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.autoStash on, 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 --check clean, cargo clippy -p asyncgit clean.

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.
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.

1 participant