Skip to content

Rebuild workspace commit when upstream target is already up-to-date#13761

Open
mtsgrd wants to merge 1 commit into
masterfrom
stale-workspace-commit
Open

Rebuild workspace commit when upstream target is already up-to-date#13761
mtsgrd wants to merge 1 commit into
masterfrom
stale-workspace-commit

Conversation

@mtsgrd
Copy link
Copy Markdown
Contributor

@mtsgrd mtsgrd commented May 12, 2026

When default_target.sha in TOML already matches origin/master (e.g.
after bootstrap_default_target_if_missing writes the remote tip
directly), integrate_upstream returned UpToDate and skipped
rebuilding the workspace commit. This left the workspace commit
parented on an older base while the UI showed commits behind.

Now we always rebuild the workspace commit in the UpToDate path so
the worktree reflects the current target even when the metadata was
already advanced.

@github-actions github-actions Bot added the rust Pull requests that update Rust code label May 12, 2026
When `default_target.sha` in TOML already matches origin/master (e.g.
after `bootstrap_default_target_if_missing` writes the remote tip
directly), `integrate_upstream` returned `UpToDate` and skipped
rebuilding the workspace commit. This left the workspace commit
parented on an older base while the UI showed commits behind.

Now we always rebuild the workspace commit in the `UpToDate` path so
the worktree reflects the current target even when the metadata was
already advanced.
@mtsgrd mtsgrd force-pushed the stale-workspace-commit branch from 2cc8ce1 to 01270f2 Compare May 12, 2026 10:10
@mtsgrd mtsgrd marked this pull request as ready for review May 12, 2026 10:18
Copilot AI review requested due to automatic review settings May 12, 2026 10:18
@mtsgrd
Copy link
Copy Markdown
Contributor Author

mtsgrd commented May 12, 2026

@Caleb-T-Owens could you take a quick look?

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 workspace desynchronization bug where integrate_upstream returned “up-to-date” and skipped rebuilding the GitButler workspace commit, leaving it parented on an older base even when default_target.sha had already been advanced to the remote tip.

Changes:

  • Rebuild the workspace commit even when upstream integration reports “up-to-date”.
  • Add a regression test covering the stale-workspace-commit scenario.
  • Add a new but-workspace scenario fixture for a merge-commit-head case.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
crates/gitbutler-branch-actions/src/upstream_integration.rs Rebuilds the workspace commit on the “up-to-date” integration path.
crates/gitbutler-branch-actions/tests/branch-actions/virtual_branches/apply_virtual_branch.rs Adds a regression test reproducing the stale workspace commit base issue.
crates/but-workspace/tests/fixtures/scenario/merge-commit-head-already-integrated.sh Adds a new repository-shape fixture for workspace/upstream integration testing.

crate::integration::update_workspace_commit_with_vb_state(
&virtual_branches_state,
ctx,
false,
// `bootstrap_default_target_if_missing` advanced `default_target.sha`
// without rebuilding the workspace commit). Rebuild it so the
// worktree reflects the current target.
let virtual_branches_state = VirtualBranchesHandle::new(ctx.project_data_dir());
Comment on lines +1059 to +1063
let base_after = gitbutler_branch_actions::base::get_base_branch_data(ctx).unwrap();
assert_eq!(
base_after.behind, 0,
"workspace should be rebuilt on current target"
);
Comment on lines +1 to +6
#!/usr/bin/env bash

source "${BASH_SOURCE[0]%/*}/shared.sh"

git init --initial-branch=master
echo "Branch whose head is a merge commit that merged master into feature - already integrated upstream" >.git/description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants