Skip to content

Commit 6e66562

Browse files
CopilotByron
andcommitted
Change but branch new to output only branch name for agent use
Modified the output of `but branch new` command to print just the branch name instead of "Created branch {branch_name}". This makes it easier for agents and scripts to capture and use the output directly with other commands like `but commit --branch=[identifier]` or `but push [identifier]`. Added tests to verify the new output format. Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
1 parent 27e673d commit 6e66562

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

crates/but/src/branch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub async fn handle(
126126
anchor,
127127
},
128128
)?;
129-
println!("Created branch {branch_name}");
129+
println!("{branch_name}");
130130
Ok(())
131131
}
132132
Some(Subcommands::Delete { branch_name, force }) => {

crates/but/tests/but/branch.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use crate::utils::{Sandbox, setup_metadata};
2+
3+
#[test]
4+
fn branch_new_outputs_branch_name() -> anyhow::Result<()> {
5+
let env = Sandbox::init_scenario_with_target("one-stack")?;
6+
insta::assert_snapshot!(env.git_log()?, @r"
7+
* edd3eb7 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
8+
* 9477ae7 (A) add A
9+
* 0dc3733 (origin/main, origin/HEAD, main) add M
10+
");
11+
12+
setup_metadata(&env, &["A"])?;
13+
14+
// Create a new branch and capture the output
15+
let output = env
16+
.but("branch new my-feature")
17+
.assert()
18+
.success()
19+
.get_output()
20+
.stdout
21+
.clone();
22+
23+
let output_str = String::from_utf8(output)?;
24+
25+
// The output should be just the branch name (with newline)
26+
assert_eq!(output_str.trim(), "my-feature");
27+
28+
Ok(())
29+
}
30+
31+
#[test]
32+
fn branch_new_with_anchor() -> anyhow::Result<()> {
33+
let env = Sandbox::init_scenario_with_target("one-stack")?;
34+
setup_metadata(&env, &["A"])?;
35+
36+
// Create a new branch with an anchor (using longer ID)
37+
let output = env
38+
.but("branch new my-feature --anchor 9477ae7")
39+
.assert()
40+
.success()
41+
.get_output()
42+
.stdout
43+
.clone();
44+
45+
let output_str = String::from_utf8(output)?;
46+
47+
// The output should be just the branch name (with newline)
48+
assert_eq!(output_str.trim(), "my-feature");
49+
50+
Ok(())
51+
}

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)