Skip to content

Commit 98534ce

Browse files
committed
but-testing apply to test new implementation more easily in the real-world.
1 parent 3948e73 commit 98534ce

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
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};
@@ -633,6 +636,32 @@ pub fn remove_reference(
633636
Ok(())
634637
}
635638

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

0 commit comments

Comments
 (0)