Use "namespace" instead of "prefix" for branches

This commit is contained in:
2021-11-24 17:22:10 +01:00
parent 711d9131da
commit 3e18caf719
2 changed files with 13 additions and 7 deletions

View File

@@ -81,11 +81,11 @@ pub struct WorktreeAddArgs {
pub name: String, pub name: String,
#[clap( #[clap(
short = 'p', short = 'n',
long = "branch-prefix", long = "branch-namespace",
about = "Prefix for the branch name" about = "Namespace of the branch"
)] )]
pub branch_prefix: Option<String>, pub branch_namespace: Option<String>,
#[clap(short = 't', long = "track", about = "Remote branch to track")] #[clap(short = 't', long = "track", about = "Remote branch to track")]
pub track: Option<String>, pub track: Option<String>,
} }

View File

@@ -18,6 +18,7 @@ use repo::{
}; };
const GIT_MAIN_WORKTREE_DIRECTORY: &str = ".git-main-working-tree"; const GIT_MAIN_WORKTREE_DIRECTORY: &str = ".git-main-working-tree";
const BRANCH_NAMESPACE_SEPARATOR: &str = "/";
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@@ -733,7 +734,9 @@ fn remove_worktree(
} }
let branch_name = head.shorthand().unwrap(); let branch_name = head.shorthand().unwrap();
if !branch_name.ends_with(name) { if branch_name != name
&& !branch_name.ends_with(&format!("{}{}", BRANCH_NAMESPACE_SEPARATOR, name))
{
return Err(WorktreeRemoveFailureReason::Error(format!( return Err(WorktreeRemoveFailureReason::Error(format!(
"Branch {} is checked out in worktree, this does not look correct", "Branch {} is checked out in worktree, this does not look correct",
&branch_name &branch_name
@@ -890,8 +893,11 @@ pub fn run() {
process::exit(1); process::exit(1);
} }
let branch_name = match action_args.branch_prefix { let branch_name = match action_args.branch_namespace {
Some(prefix) => format!("{}{}", &prefix, &action_args.name), Some(prefix) => format!(
"{}{}{}",
&prefix, BRANCH_NAMESPACE_SEPARATOR, &action_args.name
),
None => action_args.name.clone(), None => action_args.name.clone(),
}; };