Skip to content

Commit 36f23d5

Browse files
committed
CLI with branch list-remotes to list remote branches
1 parent 6a4849d commit 36f23d5

File tree

10 files changed

+33
-21
lines changed

10 files changed

+33
-21
lines changed

apps/desktop/src/lib/stores/remoteBranches.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class RemoteBranchService {
2121
try {
2222
const remoteBranches = plainToInstance(
2323
Branch,
24-
await invoke<any[]>('list_remote_branches', { projectId: this.projectId })
24+
await invoke<any[]>('list_local_branches', { projectId: this.projectId })
2525
);
2626
this.projectMetrics?.setMetric('normal_branch_count', remoteBranches.length);
2727
this.branches.set(remoteBranches);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
branch::get_uncommited_files,
99
branch_manager::BranchManagerExt,
1010
file::RemoteBranchFile,
11-
remote::{get_branch_data, list_remote_branches, RemoteBranch, RemoteBranchData},
11+
remote::{get_branch_data, list_local_branches, RemoteBranch, RemoteBranchData},
1212
VirtualBranchesExt,
1313
};
1414
use anyhow::{Context, Result};
@@ -474,9 +474,9 @@ impl VirtualBranchActions {
474474
branch::push(&ctx, branch_id, with_force, &helper, askpass)
475475
}
476476

477-
pub fn list_remote_branches(project: Project) -> Result<Vec<RemoteBranch>> {
477+
pub fn list_local_branches(project: Project) -> Result<Vec<RemoteBranch>> {
478478
let ctx = CommandContext::open(&project)?;
479-
list_remote_branches(&ctx)
479+
list_local_branches(&ctx)
480480
}
481481

482482
pub fn get_remote_branch_data(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod file;
1818
pub use file::{Get, RemoteBranchFile};
1919

2020
mod remote;
21-
pub use remote::{list_remote_branches, RemoteBranch, RemoteBranchData, RemoteCommit};
21+
pub use remote::{list_local_branches, RemoteBranch, RemoteBranchData, RemoteCommit};
2222

2323
pub mod conflicts;
2424

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ use gitbutler_repo::{LogUntil, RepoActionsExt, RepositoryExt};
1010
use gitbutler_serde::BStringForFrontend;
1111
use serde::Serialize;
1212

13-
// this struct is a mapping to the view `RemoteBranch` type in Typescript
14-
// found in src-tauri/src/routes/repo/[project_id]/types.ts
15-
//
16-
// it holds data calculated for presentation purposes of one Git branch
17-
// with comparison data to the Target commit, determining if it is mergeable,
18-
// and how far ahead or behind the Target it is.
19-
// an array of them can be requested from the frontend to show in the sidebar
20-
// Tray and should only contain branches that have not been converted into
21-
// virtual branches yet (ie, we have no `Branch` struct persisted in our data.
13+
/// this struct is a mapping to the view `RemoteBranch` type in Typescript
14+
/// found in src-tauri/src/routes/repo/[project_id]/types.ts
15+
///
16+
/// it holds data calculated for presentation purposes of one Git branch
17+
/// with comparison data to the Target commit, determining if it is mergeable,
18+
/// and how far ahead or behind the Target it is.
19+
/// an array of them can be requested from the frontend to show in the sidebar
20+
/// Tray and should only contain branches that have not been converted into
21+
/// virtual branches yet (ie, we have no `Branch` struct persisted in our data.
2222
#[derive(Debug, Clone, Serialize, PartialEq)]
2323
#[serde(rename_all = "camelCase")]
2424
pub struct RemoteBranch {
@@ -57,9 +57,14 @@ pub struct RemoteCommit {
5757
pub parent_ids: Vec<git2::Oid>,
5858
}
5959

60-
// for legacy purposes, this is still named "remote" branches, but it's actually
61-
// a list of all the normal (non-gitbutler) git branches.
62-
pub fn list_remote_branches(ctx: &CommandContext) -> Result<Vec<RemoteBranch>> {
60+
/// Return information on all local branches, while skipping gitbutler-specific branches in `refs/heads`.
61+
///
62+
/// Note to be confused with `list_branches()`, which is used for the new branch listing.
63+
///
64+
/// # Previous notes
65+
/// For legacy purposes, this is still named "remote" branches, but it's actually
66+
/// a list of all the normal (non-gitbutler) git branches.
67+
pub fn list_local_branches(ctx: &CommandContext) -> Result<Vec<RemoteBranch>> {
6368
let default_target = default_target(&ctx.project().gb_dir())?;
6469

6570
let mut remote_branches = vec![];

crates/gitbutler-branch-actions/tests/extra/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ fn detect_mergeable_branch() -> Result<()> {
13451345
vb_state.set_branch(branch4.clone())?;
13461346

13471347
let remotes =
1348-
gitbutler_branch_actions::list_remote_branches(ctx).expect("failed to list remotes");
1348+
gitbutler_branch_actions::list_local_branches(ctx).expect("failed to list remotes");
13491349
let _remote1 = &remotes
13501350
.iter()
13511351
.find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch")

crates/gitbutler-cli/src/args.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub mod vbranch {
3838

3939
#[derive(Debug, clap::Subcommand)]
4040
pub enum SubCommands {
41+
/// List all local branches that aren't GitButler specific.
42+
ListLocal,
4143
/// Provide the current state of all applied virtual branches.
4244
Status,
4345
/// Make the named branch the default so all worktree or index changes are associated with it automatically.

crates/gitbutler-cli/src/command/vbranch.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ pub fn list_all(project: Project) -> Result<()> {
1818
debug_print(list_branches(&ctx, None, None)?)
1919
}
2020

21+
pub fn list_local(project: Project) -> Result<()> {
22+
debug_print(VirtualBranchActions::list_local_branches(project)?)
23+
}
24+
2125
pub fn details(project: Project, branch_names: Vec<BranchIdentity>) -> Result<()> {
2226
let ctx = CommandContext::open(&project)?;
2327
debug_print(get_branch_listing_details(&ctx, branch_names)?)

crates/gitbutler-cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ fn main() -> Result<()> {
2020
args::Subcommands::Branch(vbranch::Platform { cmd }) => {
2121
let project = command::prepare::project_from_path(args.current_dir)?;
2222
match cmd {
23+
Some(vbranch::SubCommands::ListLocal) => command::vbranch::list_local(project),
2324
Some(vbranch::SubCommands::Status) => command::vbranch::status(project),
2425
Some(vbranch::SubCommands::Unapply { name }) => {
2526
command::vbranch::unapply(project, name)

crates/gitbutler-tauri/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn main() {
177177
virtual_branches::commands::push_change_reference,
178178
virtual_branches::commands::reorder_commit,
179179
virtual_branches::commands::update_commit_message,
180-
virtual_branches::commands::list_remote_branches,
180+
virtual_branches::commands::list_local_branches,
181181
virtual_branches::commands::list_branches,
182182
virtual_branches::commands::get_branch_listing_details,
183183
virtual_branches::commands::get_remote_branch_data,

crates/gitbutler-tauri/src/virtual_branches.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,12 @@ pub mod commands {
447447

448448
#[tauri::command(async)]
449449
#[instrument(skip(projects), err(Debug))]
450-
pub fn list_remote_branches(
450+
pub fn list_local_branches(
451451
projects: State<'_, projects::Controller>,
452452
project_id: ProjectId,
453453
) -> Result<Vec<RemoteBranch>, Error> {
454454
let project = projects.get(project_id)?;
455-
let branches = VirtualBranchActions::list_remote_branches(project)?;
455+
let branches = VirtualBranchActions::list_local_branches(project)?;
456456
Ok(branches)
457457
}
458458

0 commit comments

Comments
 (0)