Skip to content

Commit 1cd81a6

Browse files
authored
Merge pull request #11042 from gitbutlerapp/copilot/fix-user-profile-update-issue-again
Default `but branch` to `list` subcommand
2 parents f08318c + c01fc72 commit 1cd81a6

File tree

4 files changed

+59
-11
lines changed

4 files changed

+59
-11
lines changed

crates/but/src/branch/mod.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod list;
1010
#[derive(Debug, clap::Parser)]
1111
pub struct Platform {
1212
#[clap(subcommand)]
13-
pub cmd: Subcommands,
13+
pub cmd: Option<Subcommands>,
1414
}
1515

1616
#[derive(Debug, clap::Subcommand)]
@@ -48,12 +48,21 @@ pub enum Subcommands {
4848
},
4949
}
5050

51-
pub async fn handle(cmd: &Subcommands, project: &Project, _json: bool) -> anyhow::Result<()> {
51+
pub async fn handle(
52+
cmd: &Option<Subcommands>,
53+
project: &Project,
54+
_json: bool,
55+
) -> anyhow::Result<()> {
5256
match cmd {
53-
Subcommands::New {
57+
None => {
58+
let local = false;
59+
list::list(project, local).await
60+
}
61+
Some(Subcommands::List { local }) => list::list(project, *local).await,
62+
Some(Subcommands::New {
5463
branch_name,
5564
anchor,
56-
} => {
65+
}) => {
5766
let ctx =
5867
CommandContext::open(project, AppSettings::load_from_default_path_creating()?)?;
5968
// Get branch name or use canned name
@@ -120,7 +129,7 @@ pub async fn handle(cmd: &Subcommands, project: &Project, _json: bool) -> anyhow
120129
println!("Created branch {branch_name}");
121130
Ok(())
122131
}
123-
Subcommands::Delete { branch_name, force } => {
132+
Some(Subcommands::Delete { branch_name, force }) => {
124133
let stacks = but_api::workspace::stacks(
125134
project.id,
126135
Some(but_workspace::StacksFilter::InWorkspace),
@@ -141,8 +150,7 @@ pub async fn handle(cmd: &Subcommands, project: &Project, _json: bool) -> anyhow
141150
println!("Branch '{}' not found in any stack", branch_name);
142151
Ok(())
143152
}
144-
Subcommands::List { local } => list::list(project, *local).await,
145-
Subcommands::Unapply { branch_name, force } => {
153+
Some(Subcommands::Unapply { branch_name, force }) => {
146154
let stacks = but_api::workspace::stacks(
147155
project.id,
148156
Some(but_workspace::StacksFilter::InWorkspace),

crates/but/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ pub async fn handle_args(args: impl Iterator<Item = OsString>) -> Result<()> {
154154
let project = get_or_init_project(&args.current_dir)?;
155155
let result = branch::handle(cmd, &project, args.json).await;
156156
let metrics_command = match cmd {
157-
branch::Subcommands::New { .. } => CommandName::BranchNew,
158-
branch::Subcommands::Delete { .. } => CommandName::BranchDelete,
159-
branch::Subcommands::List { .. } => CommandName::BranchList,
160-
branch::Subcommands::Unapply { .. } => CommandName::BranchUnapply,
157+
None | Some(branch::Subcommands::List { .. }) => CommandName::BranchList,
158+
Some(branch::Subcommands::New { .. }) => CommandName::BranchNew,
159+
Some(branch::Subcommands::Delete { .. }) => CommandName::BranchDelete,
160+
Some(branch::Subcommands::Unapply { .. }) => CommandName::BranchUnapply,
161161
};
162162
metrics_if_configured(app_settings, metrics_command, props(start, &result)).ok();
163163
result

crates/but/tests/but/journey.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ fn from_workspace() -> anyhow::Result<()> {
118118
"snapshots/from-workspace/status01-verbose.stdout.term.svg"
119119
]);
120120

121+
// List is the default
122+
env.but("branch")
123+
.assert()
124+
.success()
125+
.stdout_eq(file!["snapshots/from-workspace/branch01.stdout.term.svg"]);
126+
127+
// But list is also explicit.
128+
env.but("branch list")
129+
.assert()
130+
.success()
131+
.stdout_eq(file!["snapshots/from-workspace/branch01.stdout.term.svg"]);
132+
121133
// TODO: more operations on the repository!
122134
Ok(())
123135
}
Lines changed: 28 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)