mirror of
https://github.com/harivansh-afk/nix.git
synced 2026-04-15 06:04:42 +00:00
Add netty-specific worktree helper commands and a zsh wrapper that creates sibling worktrees and cds into them. Also split script packaging so Darwin keeps the existing wt integration while netty gets git-worktree-based helpers. Co-authored-by: Codex <noreply@openai.com>
29 lines
695 B
Bash
29 lines
695 B
Bash
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
if [[ $# -ne 1 ]]; then
|
|
printf 'usage: wt-create <worktree-name>\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
branch_name=$1
|
|
repo_root=$(git rev-parse --show-toplevel 2>/dev/null) || {
|
|
printf 'wt-create: not inside a git repository\n' >&2
|
|
exit 1
|
|
}
|
|
|
|
target_path=$(wt-path "$branch_name")
|
|
|
|
if [[ -e "$target_path" ]]; then
|
|
printf 'wt-create: path already exists: %s\n' "$target_path" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if git -C "$repo_root" show-ref --verify --quiet "refs/heads/$branch_name"; then
|
|
git -C "$repo_root" worktree add -- "$target_path" "$branch_name" 1>&2
|
|
else
|
|
git -C "$repo_root" worktree add -b "$branch_name" -- "$target_path" HEAD 1>&2
|
|
fi
|
|
|
|
printf '%s\n' "$target_path"
|