Skip to content

Commit 62f98d6

Browse files
authored
Merge pull request #10559 from Byron/fix
Fix branch listing to show all local branches
2 parents 1dc94a0 + ff3033c commit 62f98d6

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

crates/but-testing/src/args.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ pub enum Subcommands {
154154
/// A resolvable reference name.
155155
ref_name: String,
156156
},
157+
/// List all available branches for which details can be obtained.
158+
BranchList,
157159
/// Returns everything we know about the given ref, or `HEAD`.
158160
RefInfo {
159161
/// Perform all possible computations.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub fn parse_diff_spec(arg: &Option<String>) -> Result<Option<Vec<DiffSpec>>, an
108108
mod commit;
109109
use crate::command::discard_change::IndicesOrHeaders;
110110
pub use commit::commit;
111+
use gitbutler_branch_actions::BranchListingFilter;
111112
use gitbutler_command_context::CommandContext;
112113

113114
pub mod diff;
@@ -727,3 +728,16 @@ fn path_to_rela_path(path: &Path) -> anyhow::Result<BString> {
727728
.into_owned();
728729
Ok(rela_path)
729730
}
731+
732+
pub fn branch_list(project: Option<Project>) -> anyhow::Result<()> {
733+
let project = project.context("legacy code needs project")?;
734+
let ctx = CommandContext::open(&project, AppSettings::default())?;
735+
debug_print(gitbutler_branch_actions::list_branches(
736+
&ctx,
737+
Some(BranchListingFilter {
738+
local: None,
739+
applied: None,
740+
}),
741+
None,
742+
)?)
743+
}

crates/but-testing/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ async fn main() -> Result<()> {
133133
args::Subcommands::Stacks { workspace_only } => {
134134
command::stacks::list(&args.current_dir, args.json, args.v3, *workspace_only)
135135
}
136+
args::Subcommands::BranchList => {
137+
let (_repo, project) = repo_and_maybe_project(&args, RepositoryOpenMode::Merge)?;
138+
command::branch_list(project)
139+
}
136140
args::Subcommands::BranchDetails { ref_name } => {
137141
command::stacks::branch_details(ref_name, &args.current_dir, args.v3)
138142
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn list_branches(
104104
)?;
105105
info.stacks
106106
.into_iter()
107-
.map(|s| GitButlerStack::new(s, &remote_names))
107+
.filter_map(|s| GitButlerStack::try_new(s, &remote_names).transpose())
108108
.collect::<Result<Vec<_>, _>>()?
109109
} else {
110110
Vec::new()
@@ -392,13 +392,14 @@ impl GitbutlerStackSegment {
392392
}
393393

394394
impl GitButlerStack {
395-
fn new(
395+
fn try_new(
396396
stack: but_workspace::branch::Stack,
397397
names: &gix::remote::Names,
398-
) -> anyhow::Result<Self> {
398+
) -> anyhow::Result<Option<Self>> {
399+
let Some(id) = stack.id else { return Ok(None) };
399400
let first_segment = stack.segments.first();
400-
Ok(GitButlerStack {
401-
id: stack.id.context("Can't handle stacks without ID yet")?,
401+
Ok(Some(GitButlerStack {
402+
id,
402403
// The ones we have reachable are never
403404
in_workspace: true,
404405
name: stack
@@ -436,7 +437,7 @@ impl GitButlerStack {
436437
pr_or_mr: s.metadata.as_ref().and_then(|md| md.review.pull_request),
437438
})
438439
.collect(),
439-
})
440+
}))
440441
}
441442
fn new_from_old(stack: &Stack, names: &gix::remote::Names) -> anyhow::Result<Self> {
442443
Ok(GitButlerStack {

0 commit comments

Comments
 (0)