Skip to content

Commit 650c136

Browse files
committed
Add branch apply go GitButler CLI
This will help measuring the performance changes during apply and unapply operations.
1 parent 3a383e1 commit 650c136

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

crates/gitbutler-cli/src/args.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ pub mod vbranch {
5252
/// The name of the virtual branch to unapply.
5353
name: String,
5454
},
55+
/// Add a branch to the workspace.
56+
Apply {
57+
/// The name of the virtual branch to apply.
58+
name: String,
59+
},
5560
/// Create a new commit to named virtual branch with all changes currently in the worktree or staging area assigned to it.
5661
Commit {
5762
/// The commit message

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use anyhow::{bail, Result};
1+
use anyhow::{bail, Context, Result};
22
use gitbutler_branch::{BranchCreateRequest, BranchIdentity, BranchUpdateRequest};
3-
use gitbutler_branch_actions::{get_branch_listing_details, list_branches};
3+
use gitbutler_branch_actions::{get_branch_listing_details, list_branches, BranchManagerExt};
44
use gitbutler_command_context::CommandContext;
55
use gitbutler_project::Project;
66
use gitbutler_stack::{Stack, VirtualBranchesHandle};
@@ -53,6 +53,23 @@ pub fn unapply(project: Project, branch_name: String) -> Result<()> {
5353
)?)
5454
}
5555

56+
pub fn apply(project: Project, branch_name: String) -> Result<()> {
57+
let branch = branch_by_name(&project, &branch_name)?;
58+
let ctx = CommandContext::open(&project)?;
59+
let mut guard = project.exclusive_worktree_access();
60+
debug_print(
61+
ctx.branch_manager().create_virtual_branch_from_branch(
62+
branch
63+
.source_refname
64+
.as_ref()
65+
.context("local reference name was missing")?,
66+
None,
67+
None,
68+
guard.write_permission(),
69+
)?,
70+
)
71+
}
72+
5673
pub fn create(project: Project, branch_name: String, set_default: bool) -> Result<()> {
5774
let new = gitbutler_branch_actions::create_virtual_branch(
5875
&project,

crates/gitbutler-cli/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ fn main() -> Result<()> {
2525
Some(vbranch::SubCommands::Unapply { name }) => {
2626
command::vbranch::unapply(project, name)
2727
}
28+
Some(vbranch::SubCommands::Apply { name }) => {
29+
command::vbranch::apply(project, name)
30+
}
2831
Some(vbranch::SubCommands::SetDefault { name }) => {
2932
command::vbranch::set_default(project, name)
3033
}

0 commit comments

Comments
 (0)