Skip to content

Commit 80143de

Browse files
committed
but-testing apply to test new implementation more easily in the real-world.
1 parent 62f98d6 commit 80143de

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

crates/but-testing/src/args.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ pub struct Args {
3636

3737
#[derive(Debug, clap::Subcommand)]
3838
pub enum Subcommands {
39+
/// Make an existing branch appear in the workspace.
40+
Apply {
41+
/// The 0-based place in the worktree into which the branch should be inserted.
42+
#[clap(long, short = 'o')]
43+
order: Option<usize>,
44+
/// The name of the branch to apply to the workspace, like `feature` or `origin/other`.
45+
branch_name: String,
46+
},
3947
/// Add the given Git repository as project for use with GitButler.
4048
AddProject {
4149
/// The long name of the remote reference to track, like `refs/remotes/origin/main`,

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ use but_core::UnifiedDiff;
33
use but_db::poll::ItemKind;
44
use but_graph::VirtualBranchesTomlMetadata;
55
use but_settings::AppSettings;
6+
use but_workspace::branch::OnWorkspaceMergeConflict;
7+
use but_workspace::branch::apply::{IntegrationMode, WorkspaceReferenceNaming};
8+
use but_workspace::branch::checkout::UncommitedWorktreeChanges;
69
use but_workspace::branch::create_reference::{Anchor, Position};
710
use but_workspace::{DiffSpec, HunkHeader};
811
use gitbutler_project::{Project, ProjectId};
@@ -634,6 +637,32 @@ pub fn remove_reference(
634637
Ok(())
635638
}
636639

640+
pub fn apply(args: &super::Args, short_name: &str, order: Option<usize>) -> anyhow::Result<()> {
641+
let (repo, project, graph, mut meta) =
642+
repo_and_maybe_project_and_graph(args, RepositoryOpenMode::Merge)?;
643+
let branch = repo.find_reference(short_name)?;
644+
let ws = graph.to_workspace()?;
645+
_ = but_workspace::branch::apply(
646+
branch.name(),
647+
&ws,
648+
&repo,
649+
&mut *meta,
650+
but_workspace::branch::apply::Options {
651+
integration_mode: IntegrationMode::AlwaysMerge,
652+
on_workspace_conflict: OnWorkspaceMergeConflict::MaterializeAndReportConflictingStacks,
653+
workspace_reference_naming: WorkspaceReferenceNaming::Default,
654+
uncommitted_changes: UncommitedWorktreeChanges::KeepAndAbortOnConflict,
655+
order,
656+
},
657+
)?;
658+
659+
if project.is_some() {
660+
// write metadata if there are projects - this is a special case while we use vb.toml.
661+
ManuallyDrop::into_inner(meta);
662+
}
663+
Ok(())
664+
}
665+
637666
pub fn create_reference(
638667
args: &super::Args,
639668
short_name: &str,

crates/but-testing/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use command::parse_diff_spec;
77
use gix::bstr::BString;
88

99
mod args;
10+
use crate::args::Subcommands;
1011
use crate::command::{RepositoryOpenMode, repo_and_maybe_project};
1112
use args::Args;
1213

@@ -31,6 +32,7 @@ async fn main() -> Result<()> {
3132
}
3233

3334
match &args.cmd {
35+
Subcommands::Apply { branch_name, order } => command::apply(&args, branch_name, *order),
3436
args::Subcommands::AddProject {
3537
switch_to_workspace,
3638
path,
@@ -39,7 +41,6 @@ async fn main() -> Result<()> {
3941
path.to_owned(),
4042
switch_to_workspace.to_owned(),
4143
),
42-
4344
args::Subcommands::RemoveReference {
4445
permit_empty_stacks,
4546
keep_metadata,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl BranchManager<'_> {
168168
let applied_branch_stack_id = ws
169169
.find_segment_and_stack_by_refname(branch_to_apply)
170170
.with_context(||
171-
format!("Failed to apply branch and we probably have to handle more of the outcome\n{out:?}")
171+
format!("BUG: Can't find the branch to apply in workspace, but the 'apply' function should have failed instead \n{out:?}")
172172
)?
173173
.0
174174
.id

0 commit comments

Comments
 (0)