|
1 | | -use anyhow::{bail, Result}; |
| 1 | +use anyhow::{bail, Context, Result}; |
2 | 2 | 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}; |
4 | 4 | use gitbutler_command_context::CommandContext; |
5 | 5 | use gitbutler_project::Project; |
6 | 6 | use gitbutler_stack::{Stack, VirtualBranchesHandle}; |
@@ -53,6 +53,23 @@ pub fn unapply(project: Project, branch_name: String) -> Result<()> { |
53 | 53 | )?) |
54 | 54 | } |
55 | 55 |
|
| 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 | + |
56 | 73 | pub fn create(project: Project, branch_name: String, set_default: bool) -> Result<()> { |
57 | 74 | let new = gitbutler_branch_actions::create_virtual_branch( |
58 | 75 | &project, |
|
0 commit comments