Skip to content

Commit 207cdc2

Browse files
committed
Actually use the top stacked branch for stack head
1 parent d972147 commit 207cdc2

File tree

39 files changed

+213
-122
lines changed

39 files changed

+213
-122
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/but-cli/src/command/diff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn locks(current_dir: &Path) -> anyhow::Result<()> {
4343
let worktree_changes = but_core::diff::worktree_changes(&repo)?;
4444
let input_stacks = but_hunk_dependency::workspace_stacks_to_input_stacks(
4545
&repo,
46-
&but_workspace::stacks(&project.gb_dir())?,
46+
&but_workspace::stacks(&project.gb_dir(), &repo)?,
4747
but_workspace::common_merge_base_with_target_branch(&project.gb_dir())?,
4848
)?;
4949
let ranges = but_hunk_dependency::WorkspaceRanges::try_from_stacks(input_stacks)?;

crates/but-cli/src/command/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ pub mod stacks {
116116

117117
pub fn list(current_dir: &Path) -> anyhow::Result<()> {
118118
let project = project_from_path(current_dir)?;
119-
debug_print(but_workspace::stacks(&project.gb_dir()))
119+
let ctx = CommandContext::open(&project, AppSettings::default())?;
120+
let repo = ctx.gix_repository()?;
121+
debug_print(but_workspace::stacks(&project.gb_dir(), &repo))
120122
}
121123

122124
pub fn branches(id: &str, current_dir: &Path) -> anyhow::Result<()> {

crates/but-hunk-dependency/src/ui.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn hunk_dependencies_for_workspace_changes_by_worktree_dir(
1414
) -> anyhow::Result<HunkDependencies> {
1515
let repo = gix::open(worktree_dir).map_err(anyhow::Error::from)?;
1616
let worktree_changes = but_core::diff::worktree_changes(&repo)?;
17-
let stacks = but_workspace::stacks(gitbutler_dir)?;
17+
let stacks = but_workspace::stacks(gitbutler_dir, &repo)?;
1818
let common_merge_base = gitbutler_stack::VirtualBranchesHandle::new(gitbutler_dir)
1919
.get_default_target()?
2020
.sha;

crates/but-hunk-dependency/tests/hunk_dependency/ui.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ mod util {
241241

242242
fn test_ctx_at(script_name: &str, name: &str) -> anyhow::Result<TestContext> {
243243
let ctx = gitbutler_testsupport::read_only::fixture(script_name, name)?;
244-
let stacks = but_workspace::stacks(&ctx.project().gb_dir())?;
244+
let stacks = but_workspace::stacks(&ctx.project().gb_dir(), &ctx.gix_repository()?)?;
245245

246246
Ok(TestContext {
247247
repo: gix::open_opts(&ctx.project().path, gix::open::Options::isolated())?,

crates/but-hunk-dependency/tests/hunk_dependency/workspace_dependencies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ mod util {
901901

902902
fn test_ctx_at(script_name: &str, name: &str) -> anyhow::Result<TestContext> {
903903
let ctx = gitbutler_testsupport::read_only::fixture(script_name, name)?;
904-
let stacks = but_workspace::stacks(&ctx.project().gb_dir())?;
904+
let stacks = but_workspace::stacks(&ctx.project().gb_dir(), &ctx.gix_repository()?)?;
905905
let handle = VirtualBranchesHandle::new(ctx.project().gb_dir());
906906

907907
Ok(TestContext {

crates/but-workspace/src/commit_engine/reference_frame.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ impl ReferenceFrame {
5656
.context("Didn't find stack - was it deleted just now?")?;
5757
Ok(ReferenceFrame {
5858
workspace_tip: Some(head_id.detach()),
59-
branch_tip: Some(stack.head()?.to_gix()),
59+
branch_tip: Some(stack.head(repo)?.to_gix()),
6060
})
6161
}
6262
InferenceMode::CommitIdInStack(commit_id) => {
6363
for stack in vb.branches.values() {
64-
let stack_tip = stack.head()?.to_gix();
64+
let stack_tip = stack.head(repo)?.to_gix();
6565
if stack_tip
6666
.attach(repo)
6767
.ancestors()

crates/but-workspace/src/commit_engine/refs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn rewrite(
3434
continue; // Dont rewrite refs for other stacks
3535
}
3636
}
37-
if stack.head()? == old_git2 {
37+
if stack.head(repo)? == old_git2 {
3838
stack.set_head(new.to_git2());
3939
stack.tree = new
4040
.attach(repo)

crates/but-workspace/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl StackEntry {
127127
/// If the GitButler state file in the provided path is missing or invalid, an error is returned.
128128
///
129129
/// - `gb_dir`: The path to the GitButler state for the project. Normally this is `.git/gitbutler` in the project's repository.
130-
pub fn stacks(gb_dir: &Path) -> Result<Vec<StackEntry>> {
130+
pub fn stacks(gb_dir: &Path, repo: &gix::Repository) -> Result<Vec<StackEntry>> {
131131
let state = state_handle(gb_dir);
132132

133133
state
@@ -138,7 +138,7 @@ pub fn stacks(gb_dir: &Path) -> Result<Vec<StackEntry>> {
138138
Ok(StackEntry {
139139
id: stack.id,
140140
branch_names: stack.heads().into_iter().map(Into::into).collect(),
141-
tip: stack.head().map(|h| h.to_gix())?,
141+
tip: stack.head(repo).map(|h| h.to_gix())?,
142142
})
143143
})
144144
.collect()

crates/but-workspace/tests/workspace/commit_engine/refs_update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ mod utils {
11031103
for stack in vbranches.branches.values() {
11041104
repo.reference(
11051105
format!("refs/heads/{}", stack.name),
1106-
stack.head()?.to_gix(),
1106+
stack.head(repo)?.to_gix(),
11071107
PreviousValue::Any,
11081108
"create stack head for visualization",
11091109
)?;

0 commit comments

Comments
 (0)