Skip to content
This repository was archived by the owner on Nov 18, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,18 @@ _try_worktree_add() {
return 0
}

# Build and validate folder name from branch/custom/override.
# Validate the branch operand and build the folder name.
# Prints sanitized folder name on success; returns 1 on validation failure.
# Usage: _resolve_folder_name <branch_name> [custom_name] [folder_override]
_resolve_folder_name() {
local branch_name="$1" custom_name="${2:-}" folder_override="${3:-}"

# Interactive input and provider branch names bypass the CLI flag parser.
if [[ "$branch_name" == -* ]]; then
log_error "Branch name cannot start with a dash"
return 1
fi

local sanitized_name

if [ -n "$folder_override" ]; then
Expand Down
13 changes: 13 additions & 0 deletions tests/cmd_create_integration.bats
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ _cmd_create_capture_stdout() {
[ -d "$TEST_WORKTREES_DIR/new-feature" ]
}

@test "new CLI rejects a prompted branch that Git would read as an option" {
git update-ref refs/remotes/origin/--detach HEAD
local before
before=$(git worktree list --porcelain)

run bash -c 'printf "%s\n" --detach | "$1" new --from HEAD --no-fetch --no-copy --no-hooks --no-sparse' _ "$PROJECT_ROOT/bin/gtr"

[ "$status" -ne 0 ]
[[ "$output" == *"Branch name cannot start with a dash"* ]]
[ "$(git worktree list --porcelain)" = "$before" ]
[ ! -e "$TEST_WORKTREES_DIR" ]
}

@test "new CLI keeps ordinary next steps readable" {
run "$PROJECT_ROOT/bin/gtr" new feature/ordinary --from HEAD --no-fetch --no-copy --no-hooks --yes
[ "$status" -eq 0 ]
Expand Down
Loading