dotfiles

Personal dotfiles
git clone https://git.bracken.jp/dotfiles.git
Log | Files | Refs | LICENSE

commit a60c476fb95194093a3224e6f51cc32d73711f87
parent e970221b52bfa323db0e48fc1692c4ac31319497
Author: Chris Bracken <chris@bracken.jp>
Date:   Fri, 15 May 2026 14:42:19 +0900

jj: add ws-add alias

Adds a workspace but also with a git worktree in it, so that repo
tooling that relies on git will still work.

Diffstat:
M.config/jj/config.toml | 1+
A.local/bin/jj-ws-add | 33+++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/.config/jj/config.toml b/.config/jj/config.toml @@ -10,6 +10,7 @@ ll = ["log", "-T", "builtin_log_oneline", "-r", "::"] ld = ["log", "-T", "builtin_log_detailed ++ diff.stat() ++ '\n'", "-r", "::", "--no-graph"] lp = ["log", "-T", "builtin_log_detailed ++ diff.stat() ++ '\n' ++ diff.git() ++ '\n'", "-r", "::", "--no-graph"] format = ["util", "exec", "--", "jj-format"] +ws-add = ["util", "exec", "--", "jj-ws-add"] [ui] diff-formatter = ":git" diff --git a/.local/bin/jj-ws-add b/.local/bin/jj-ws-add @@ -0,0 +1,33 @@ +#!/usr/bin/env zsh +set -euo pipefail + +if (( # == 0 )); then + print -u2 "Usage: jj ws-add <destination_path>" + exit 1 +fi + +# Resolve absolute destination path and workspace name. +DEST_ABS="${1:a}" +WS_NAME="${DEST_ABS:t}" + +# Move to current workspace root to ensure Git commands find the primary repo. +# We do this in case we're already in a workspace. +cd "$JJ_WORKSPACE_ROOT" +MAIN_ABS="$PWD" + +# Create the new jj workspace. +jj workspace add "$DEST_ABS" + +# Create a temporary Git worktree. +TEMP_GIT="${DEST_ABS}_temp_git" +git worktree add --detach --no-checkout "$TEMP_GIT" HEAD >/dev/null 2>&1 + +# Align Git worktree metadata and link pointers permanently. +mv ".git/worktrees/${TEMP_GIT:t}" ".git/worktrees/$WS_NAME" +print "gitdir: $MAIN_ABS/.git/worktrees/$WS_NAME" > "$DEST_ABS/.git" +print "$DEST_ABS/.git" > ".git/worktrees/$WS_NAME/gitdir" +rm -rf "$TEMP_GIT/.git" +rmdir "$TEMP_GIT" + +# Populate Git's index for the new workspace. +git -C "$DEST_ABS" reset >/dev/null 2>&1