Skip to content

Commit

Permalink
Branches: Allow renaming of current branch (#1245)
Browse files Browse the repository at this point in the history
* allow rename of current branch

* pass options to rename command

* don't create new connection unless needed

* pass options to rename
  • Loading branch information
quinchs authored Mar 11, 2024
1 parent bf68748 commit 2d08d26
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/branch/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub async fn branch_main(options: &Options, cmd: &BranchCommand) -> anyhow::Resu
Command::Drop(drop) => drop::main(drop, &context, &mut connection).await,
Command::Wipe(wipe) => wipe::main(wipe, &context, &mut connection).await,
Command::List(list) => list::main(list, &context, &mut connection).await,
Command::Rename(rename) => rename::main(rename, &context, &mut connection).await,
Command::Rename(rename) => rename::main(rename, &context, &mut connection, &options).await,
Command::Rebase(rebase) => rebase::main(rebase, &context, &mut connection, &options).await,
unhandled => anyhow::bail!("unimplemented branch command '{:?}'", unhandled)
}
Expand Down
21 changes: 19 additions & 2 deletions src/branch/rename.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
use crate::branch::connections::get_connection_to_modify;
use crate::branch::context::Context;
use crate::branch::option::Rename;
use crate::options::Options;
use crate::connect::Connection;
use crate::print;

pub async fn main(
options: &Rename,
_context: &Context,
context: &Context,
connection: &mut Connection,
cli_opts: &Options,
) -> anyhow::Result<()> {
if options.old_name == context.branch {
let mut modify_connection = get_connection_to_modify(&context.branch, &cli_opts, connection).await?;
rename(&mut modify_connection.connection, &options).await?;
modify_connection.clean().await?;
context.update_branch(&options.new_name).await?;
} else {
rename(connection, &options).await?;
}

eprintln!("Renamed branch {} to {}", options.old_name, options.new_name);

Ok(())
}

async fn rename(connection: &mut Connection, options: &Rename) -> anyhow::Result<()> {
let status = connection
.execute(
&format!(
Expand All @@ -22,6 +40,5 @@ pub async fn main(

print::completion(status);

eprintln!("Renamed branch {} to {}", options.old_name, options.new_name);
Ok(())
}

0 comments on commit 2d08d26

Please sign in to comment.