Skip to content

Commit 144cd3b

Browse files
committed
refactor
1 parent 6e66562 commit 144cd3b

File tree

4 files changed

+41
-35
lines changed

4 files changed

+41
-35
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
@@ -70,7 +70,7 @@ tracing-subscriber = { version = "0.3", features = [
7070
tracing-forest = { version = "0.2.0" }
7171
ratatui = "0.29.0"
7272
crossterm = "0.29.0"
73-
open.workspace = true
73+
atty = "0.2.0"
7474

7575
[dev-dependencies]
7676
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!("{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: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::utils::{Sandbox, setup_metadata};
2+
use snapbox::str;
23

34
#[test]
45
fn branch_new_outputs_branch_name() -> anyhow::Result<()> {
@@ -11,41 +12,22 @@ fn branch_new_outputs_branch_name() -> anyhow::Result<()> {
1112

1213
setup_metadata(&env, &["A"])?;
1314

14-
// Create a new branch and capture the output
15-
let output = env
16-
.but("branch new my-feature")
15+
env.but("branch new my-feature")
1716
.assert()
1817
.success()
19-
.get_output()
20-
.stdout
21-
.clone();
18+
.stderr_eq(str![])
19+
.stdout_eq(str![[r#"
20+
my-feature
2221
23-
let output_str = String::from_utf8(output)?;
22+
"#]]);
2423

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")
24+
env.but("branch new --anchor 9477ae7 my-anchored-feature")
3925
.assert()
4026
.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");
27+
.stderr_eq(str![])
28+
.stdout_eq(str![[r#"
29+
my-anchored-feature
4930
31+
"#]]);
5032
Ok(())
5133
}

0 commit comments

Comments
 (0)