Skip to content

Commit

Permalink
CLI with branch list-remotes to list remote branches
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 29, 2024
1 parent edebd05 commit 31d30e8
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 18 deletions.
6 changes: 3 additions & 3 deletions crates/gitbutler-branch-actions/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
branch::get_uncommited_files,
branch_manager::BranchManagerExt,
file::RemoteBranchFile,
remote::{get_branch_data, list_remote_branches, RemoteBranch, RemoteBranchData},
remote::{get_branch_data, list_local_branches, RemoteBranch, RemoteBranchData},
VirtualBranchesExt,
};
use anyhow::{Context, Result};
Expand Down Expand Up @@ -474,9 +474,9 @@ impl VirtualBranchActions {
branch::push(&ctx, branch_id, with_force, &helper, askpass)
}

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

pub fn get_remote_branch_data(
Expand Down
2 changes: 1 addition & 1 deletion crates/gitbutler-branch-actions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod file;
pub use file::{Get, RemoteBranchFile};

mod remote;
pub use remote::{list_remote_branches, RemoteBranch, RemoteBranchData, RemoteCommit};
pub use remote::{list_local_branches, RemoteBranch, RemoteBranchData, RemoteCommit};

pub mod conflicts;

Expand Down
29 changes: 17 additions & 12 deletions crates/gitbutler-branch-actions/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ use gitbutler_repo::{LogUntil, RepoActionsExt, RepositoryExt};
use gitbutler_serde::BStringForFrontend;
use serde::Serialize;

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

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

let mut remote_branches = vec![];
Expand Down
2 changes: 1 addition & 1 deletion crates/gitbutler-branch-actions/tests/extra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ fn detect_mergeable_branch() -> Result<()> {
vb_state.set_branch(branch4.clone())?;

let remotes =
gitbutler_branch_actions::list_remote_branches(ctx).expect("failed to list remotes");
gitbutler_branch_actions::list_local_branches(ctx).expect("failed to list remotes");
let _remote1 = &remotes
.iter()
.find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch")
Expand Down
2 changes: 2 additions & 0 deletions crates/gitbutler-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub mod vbranch {

#[derive(Debug, clap::Subcommand)]
pub enum SubCommands {
/// List all local branches that aren't GitButler specific.
ListLocal,
/// Provide the current state of all applied virtual branches.
Status,
/// Make the named branch the default so all worktree or index changes are associated with it automatically.
Expand Down
4 changes: 4 additions & 0 deletions crates/gitbutler-cli/src/command/vbranch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub fn list_all(project: Project) -> Result<()> {
debug_print(list_branches(&ctx, None, None)?)
}

pub fn list_local(project: Project) -> Result<()> {
debug_print(VirtualBranchActions::list_local_branches(project)?)
}

pub fn details(project: Project, branch_names: Vec<BranchIdentity>) -> Result<()> {
let ctx = CommandContext::open(&project)?;
debug_print(get_branch_listing_details(&ctx, branch_names)?)
Expand Down
1 change: 1 addition & 0 deletions crates/gitbutler-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn main() -> Result<()> {
args::Subcommands::Branch(vbranch::Platform { cmd }) => {
let project = command::prepare::project_from_path(args.current_dir)?;
match cmd {
Some(vbranch::SubCommands::ListLocal) => command::vbranch::list_local(project),
Some(vbranch::SubCommands::Status) => command::vbranch::status(project),
Some(vbranch::SubCommands::Unapply { name }) => {
command::vbranch::unapply(project, name)
Expand Down
2 changes: 1 addition & 1 deletion crates/gitbutler-tauri/src/virtual_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ pub mod commands {
project_id: ProjectId,
) -> Result<Vec<RemoteBranch>, Error> {
let project = projects.get(project_id)?;
let branches = VirtualBranchActions::list_remote_branches(project)?;
let branches = VirtualBranchActions::list_local_branches(project)?;
Ok(branches)
}

Expand Down

0 comments on commit 31d30e8

Please sign in to comment.