Skip to content

Commit 3467de7

Browse files
authored
Merge pull request #11113 from Byron/fix
Reconcile stacks for the `gitbutler/workspace`, not for the HEAD workspace.
2 parents 76ce664 + 2869d69 commit 3467de7

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

crates/but-api/src/commands/stack.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ pub fn create_reference(
8181
.transpose()?;
8282

8383
let mut guard = ctx.project().exclusive_worktree_access();
84-
let (repo, mut meta, graph) = ctx.graph_and_meta_mut_and_repo(guard.write_permission())?;
84+
let (repo, mut meta, graph) =
85+
ctx.graph_and_meta_mut_and_repo_from_head(guard.write_permission())?;
8586
let graph = but_workspace::branch::create_reference(
8687
new_ref.clone(),
8788
anchor,
@@ -112,7 +113,8 @@ pub fn create_branch(
112113
if ctx.app_settings().feature_flags.ws3 {
113114
use but_workspace::branch::create_reference::Position::Above;
114115
let mut guard = project.exclusive_worktree_access();
115-
let (repo, mut meta, graph) = ctx.graph_and_meta_mut_and_repo(guard.write_permission())?;
116+
let (repo, mut meta, graph) =
117+
ctx.graph_and_meta_mut_and_repo_from_head(guard.write_permission())?;
116118
let ws = graph.to_workspace()?;
117119
let stack = ws.try_find_stack_by_id(stack_id)?;
118120
let new_ref = Category::LocalBranch
@@ -176,7 +178,8 @@ pub fn remove_branch(
176178
let ctx = CommandContext::open(&project, AppSettings::load_from_default_path_creating()?)?;
177179
let mut guard = project.exclusive_worktree_access();
178180
if ctx.app_settings().feature_flags.ws3 {
179-
let (repo, mut meta, graph) = ctx.graph_and_meta_mut_and_repo(guard.write_permission())?;
181+
let (repo, mut meta, graph) =
182+
ctx.graph_and_meta_mut_and_repo_from_head(guard.write_permission())?;
180183
let ws = graph.to_workspace()?;
181184
let ref_name = Category::LocalBranch
182185
.to_full_name(branch_name.as_str())

crates/but-api/src/commands/virtual_branches.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ pub fn create_virtual_branch(
4545
let ws3_enabled = ctx.app_settings().feature_flags.ws3;
4646
let stack_entry = if ws3_enabled {
4747
let mut guard = project.exclusive_worktree_access();
48-
let (repo, mut meta, graph) = ctx.graph_and_meta_mut_and_repo(guard.write_permission())?;
48+
let (repo, mut meta, graph) =
49+
ctx.graph_and_meta_mut_and_repo_from_head(guard.write_permission())?;
4950
let ws = graph.to_workspace()?;
5051
let new_ref = Category::LocalBranch
5152
.to_full_name(

crates/gitbutler-branch-actions/src/branch_manager/branch_creation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl BranchManager<'_> {
155155
// Assume that this is always about 'apply' and hijack the entire method.
156156
// That way we'd learn what's missing.
157157
if self.ctx.app_settings().feature_flags.apply3 {
158-
let (repo, mut meta, graph) = self.ctx.graph_and_meta_mut_and_repo(perm)?;
158+
let (repo, mut meta, graph) = self.ctx.graph_and_meta_mut_and_repo_from_head(perm)?;
159159
let ws = graph.to_workspace()?;
160160
let target = target.to_string();
161161
let branch_to_apply = target.as_str().try_into()?;

crates/gitbutler-command-context/src/lib.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl CommandContext {
142142
/// for until the end of the operation for the protection to be effective.
143143
///
144144
/// Use [`Self::graph_and_meta()`] if control over the repository configuration is needed.
145-
pub fn graph_and_meta_mut_and_repo(
145+
pub fn graph_and_meta_mut_and_repo_from_head(
146146
&self,
147147
_write: &mut WorktreeWritePermission,
148148
) -> Result<(
@@ -156,6 +156,35 @@ impl CommandContext {
156156
Ok((repo, VirtualBranchesTomlMetadataMut(meta), graph))
157157
}
158158

159+
/// Open the repository with standard options and create a new Graph traversal from the given `ref_name`,
160+
/// along with a new metadata instance, and the graph itself.
161+
///
162+
/// The write-permission is required to obtain a mutable metadata instance. Note that it must be held
163+
/// for until the end of the operation for the protection to be effective.
164+
///
165+
/// Use [`Self::graph_and_meta()`] if control over the repository configuration is needed.
166+
pub fn graph_and_meta_mut_and_repo_from_reference(
167+
&self,
168+
ref_name: &gix::refs::FullNameRef,
169+
_write: &mut WorktreeWritePermission,
170+
) -> Result<(
171+
gix::Repository,
172+
VirtualBranchesTomlMetadataMut,
173+
but_graph::Graph,
174+
)> {
175+
let repo = self.gix_repo()?;
176+
let meta = self.meta_inner()?;
177+
let mut reference = repo.find_reference(ref_name)?;
178+
let commit_id = reference.peel_to_commit()?.id();
179+
let graph = but_graph::Graph::from_commit_traversal(
180+
commit_id,
181+
reference.name().to_owned(),
182+
&meta,
183+
meta.graph_options(),
184+
)?;
185+
Ok((repo, VirtualBranchesTomlMetadataMut(meta), graph))
186+
}
187+
159188
/// Return a newly opened `gitoxide` repository, with all configuration available
160189
/// to correctly figure out author and committer names (i.e. with most global configuration loaded),
161190
/// *and* which will perform diffs quickly thanks to an adequate object cache.

crates/gitbutler-tauri/src/projects.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,14 @@ pub fn set_project_active(
105105
fn reconcile_in_workspace_state_of_vb_toml(ctx: &mut CommandContext) -> Option<()> {
106106
let mut guard = ctx.project().exclusive_worktree_access();
107107
let perm = guard.write_permission();
108-
let (_repo, mut meta, graph) = ctx.graph_and_meta_mut_and_repo(perm).ok()?;
108+
let (_repo, mut meta, graph) = ctx
109+
.graph_and_meta_mut_and_repo_from_reference(
110+
"refs/heads/gitbutler/workspace"
111+
.try_into()
112+
.expect("statically known to be valid"),
113+
perm,
114+
)
115+
.ok()?;
109116
let ws = graph.to_workspace().ok()?;
110117

111118
let mut seen = BTreeSet::new();

0 commit comments

Comments
 (0)