Skip to content

Commit cdc1df6

Browse files
authored
Merge pull request #11061 from gitbutlerapp/copilot/add-search-filter-functionality
Output branch name from `but branch new` for programmatic use
2 parents 0af83bd + 144cd3b commit cdc1df6

File tree

5 files changed

+64
-6
lines changed

5 files changed

+64
-6
lines changed

Cargo.lock

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/but/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ tracing-subscriber = { version = "0.3", features = [
7171
tracing-forest = { version = "0.2.0" }
7272
ratatui = "0.29.0"
7373
crossterm = "0.29.0"
74-
open.workspace = true
74+
atty = "0.2.0"
7575

7676
[dev-dependencies]
7777
but-core = { workspace = true, features = ["testing"] }

crates/but/src/branch/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::io::{self, Write};
2-
1+
use atty::Stream;
32
use but_settings::AppSettings;
43
use but_workspace::{StackId, ui::StackEntry};
54
use gitbutler_command_context::CommandContext;
65
use gitbutler_project::Project;
6+
use std::io::{self, Write};
77

88
mod list;
99

@@ -126,7 +126,11 @@ pub async fn handle(
126126
anchor,
127127
},
128128
)?;
129-
println!("Created branch {branch_name}");
129+
if atty::is(Stream::Stdout) {
130+
println!("Created branch {branch_name}");
131+
} else {
132+
println!("{branch_name}");
133+
}
130134
Ok(())
131135
}
132136
Some(Subcommands::Delete { branch_name, force }) => {

crates/but/tests/but/branch.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use crate::utils::{Sandbox, setup_metadata};
2+
use snapbox::str;
3+
4+
#[test]
5+
fn branch_new_outputs_branch_name() -> anyhow::Result<()> {
6+
let env = Sandbox::init_scenario_with_target("one-stack")?;
7+
insta::assert_snapshot!(env.git_log()?, @r"
8+
* edd3eb7 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
9+
* 9477ae7 (A) add A
10+
* 0dc3733 (origin/main, origin/HEAD, main) add M
11+
");
12+
13+
setup_metadata(&env, &["A"])?;
14+
15+
env.but("branch new my-feature")
16+
.assert()
17+
.success()
18+
.stderr_eq(str![])
19+
.stdout_eq(str![[r#"
20+
my-feature
21+
22+
"#]]);
23+
24+
env.but("branch new --anchor 9477ae7 my-anchored-feature")
25+
.assert()
26+
.success()
27+
.stderr_eq(str![])
28+
.stdout_eq(str![[r#"
29+
my-anchored-feature
30+
31+
"#]]);
32+
Ok(())
33+
}

crates/but/tests/but/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod branch;
12
mod commit;
23
mod journey;
34
mod rub;

0 commit comments

Comments
 (0)