new branching strategy

This commit is contained in:
RingOfStorms (Joshua Bell) 2025-09-10 16:05:17 -05:00
parent fdbba0d508
commit 8bbc0f7825
4 changed files with 95 additions and 41 deletions

View file

@ -46,7 +46,6 @@ with lib;
cl = "clear"; cl = "clear";
# git # git
branch = "git checkout -b";
status = "git status"; status = "git status";
diff = "git diff"; diff = "git diff";
branches = "git branch -a"; branches = "git branch -a";

View file

@ -129,12 +129,89 @@ prunel () {
done; done;
} }
checkout () { branch() {
git fetch local branch_name
git checkout $1 branch_name=$1
pull if [ -z "$branch_name" ]; then
echo "Usage: branch <name>" >&2
return 1
fi
# Use XDG_DATA_HOME or default to ~/.local/share
local xdg=${XDG_DATA_HOME:-$HOME/.local/share}
local repo_dir
# Determine the git common dir (points into the main repo's .git)
local common_dir
common_dir=$(git rev-parse --git-common-dir 2>/dev/null) || {
echo "Not inside a git repository." >&2
return 1
}
# Make common_dir absolute if it's relative
if [ "${common_dir#/}" = "$common_dir" ]; then
common_dir="$(pwd)/$common_dir"
fi
# repo_dir is the path before '/.git' in the common_dir (handles worktrees)
repo_dir="${common_dir%%/.git*}"
if [ -z "$repo_dir" ]; then
echo "Unable to determine repository root." >&2
return 1
fi
local repo_base
repo_base=$(basename "$repo_dir")
local repo_hash
repo_hash=$(printf "%s" "$repo_dir" | sha1sum | awk '{print $1}')
# If user asked for default or master, cd back to repo root on default branch
local default_branch
default_branch=$(getdefault 2>/dev/null || echo "")
if [ "$branch_name" = "default" ] || [ "$branch_name" = "master" ] || [ "$branch_name" = "$default_branch" ]; then
cd "$repo_dir" || return 0
# git fetch
# git checkout "$default_branch"
# pull
return 0
fi
# Ensure we have up-to-date remote info
git fetch --all --prune
# If branch exists remotely and not locally, create local branch tracking remote
if git ls-remote --exit-code --heads origin "$branch_name" >/dev/null 2>&1; then
if ! git show-ref --verify --quiet "refs/heads/$branch_name"; then
git branch --track "$branch_name" "origin/$branch_name" 2>/dev/null || git branch "$branch_name" "origin/$branch_name"
fi
fi
# Worktree path
local wt_root
wt_root="$xdg/git_worktrees/${repo_base}_${repo_hash}"
local wt_path
wt_path="$wt_root/$branch_name"
mkdir -p "$wt_root"
# If worktree already exists, cd to it
if [ -d "$wt_path/.git" ] || [ -d "$wt_path" -a -d "$wt_path/.git" ]; then
cd "$wt_path" || return 0
return 0
fi
# If a worktree for this branch is already registered elsewhere, find it and cd
local existing
existing=$(git worktree list --porcelain 2>/dev/null | awk -v b="$branch_name" 'BEGIN{RS=""} $0 ~ "refs/heads/"b{for(i=1;i<=NF;i++) if ($i ~ /^worktree/) print $2 }')
if [ -n "$existing" ]; then
cd "$existing" || return 0
return 0
fi
# Create the worktree
mkdir -p "$wt_path"
git worktree add -B "$branch_name" "$wt_path" "origin/$branch_name" 2>/dev/null || git worktree add "$wt_path" "$branch_name"
cd "$wt_path" || return 0
} }
from_master () { from_master () {
git checkout $(getdefault) $@ git checkout $(getdefault) $@
} }

43
hosts/lio/flake.lock generated
View file

@ -29,22 +29,17 @@
"inputs": { "inputs": {
"home-manager": "home-manager", "home-manager": "home-manager",
"nix-flatpak": "nix-flatpak", "nix-flatpak": "nix-flatpak",
"nixpkgs": "nixpkgs_2",
"ragenix": "ragenix" "ragenix": "ragenix"
}, },
"locked": { "locked": {
"lastModified": 1757006046, "path": "../../common",
"narHash": "sha256-DSPEc465ijE7hVDFpuMDF0LTBIAa0N7V6YFdBfS9XL0=", "type": "path"
"ref": "refs/heads/master",
"rev": "307bf34c8c24a7b2b599bd22facae5ec5090c8bd",
"revCount": 639,
"type": "git",
"url": "https://git.joshuabell.xyz/ringofstorms/dotfiles"
}, },
"original": { "original": {
"type": "git", "path": "../../common",
"url": "https://git.joshuabell.xyz/ringofstorms/dotfiles" "type": "path"
} },
"parent": []
}, },
"crane": { "crane": {
"locked": { "locked": {
@ -194,22 +189,6 @@
} }
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": {
"lastModified": 1757347588,
"narHash": "sha256-tLdkkC6XnsY9EOZW9TlpesTclELy8W7lL2ClL+nma8o=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "b599843bad24621dcaa5ab60dac98f9b0eb1cabe",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": { "locked": {
"lastModified": 1741379970, "lastModified": 1741379970,
"narHash": "sha256-Wh7esNh7G24qYleLvgOSY/7HlDUzWaL/n4qzlBePpiw=", "narHash": "sha256-Wh7esNh7G24qYleLvgOSY/7HlDUzWaL/n4qzlBePpiw=",
@ -225,7 +204,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_4": { "nixpkgs_3": {
"locked": { "locked": {
"lastModified": 1755471983, "lastModified": 1755471983,
"narHash": "sha256-axUoWcm4cNQ36jOlnkD9D40LTfSQgk8ExfHSRm3rTtg=", "narHash": "sha256-axUoWcm4cNQ36jOlnkD9D40LTfSQgk8ExfHSRm3rTtg=",
@ -241,7 +220,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_5": { "nixpkgs_4": {
"locked": { "locked": {
"lastModified": 1755648324, "lastModified": 1755648324,
"narHash": "sha256-+2TxwJEXWXGC7JBsRGUHtmQ66lRGPcDI2kFKTTU5e2s=", "narHash": "sha256-+2TxwJEXWXGC7JBsRGUHtmQ66lRGPcDI2kFKTTU5e2s=",
@ -1141,7 +1120,7 @@
"agenix": "agenix", "agenix": "agenix",
"crane": "crane", "crane": "crane",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_3", "nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
}, },
"locked": { "locked": {
@ -1161,14 +1140,14 @@
"root": { "root": {
"inputs": { "inputs": {
"common": "common", "common": "common",
"nixpkgs": "nixpkgs_4", "nixpkgs": "nixpkgs_3",
"nixpkgs-unstable": "nixpkgs-unstable", "nixpkgs-unstable": "nixpkgs-unstable",
"ros_neovim": "ros_neovim" "ros_neovim": "ros_neovim"
} }
}, },
"ros_neovim": { "ros_neovim": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs_5", "nixpkgs": "nixpkgs_4",
"nvim_plugin-Almo7aya/openingh.nvim": "nvim_plugin-Almo7aya/openingh.nvim", "nvim_plugin-Almo7aya/openingh.nvim": "nvim_plugin-Almo7aya/openingh.nvim",
"nvim_plugin-CopilotC-Nvim/CopilotChat.nvim": "nvim_plugin-CopilotC-Nvim/CopilotChat.nvim", "nvim_plugin-CopilotC-Nvim/CopilotChat.nvim": "nvim_plugin-CopilotC-Nvim/CopilotChat.nvim",
"nvim_plugin-JoosepAlviste/nvim-ts-context-commentstring": "nvim_plugin-JoosepAlviste/nvim-ts-context-commentstring", "nvim_plugin-JoosepAlviste/nvim-ts-context-commentstring": "nvim_plugin-JoosepAlviste/nvim-ts-context-commentstring",

View file

@ -4,8 +4,8 @@
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
# Use relative to get current version for testing # Use relative to get current version for testing
# common.url = "path:../../common"; common.url = "path:../../common";
common.url = "git+https://git.joshuabell.xyz/ringofstorms/dotfiles"; # common.url = "git+https://git.joshuabell.xyz/ringofstorms/dotfiles";
ros_neovim.url = "git+https://git.joshuabell.xyz/ringofstorms/nvim"; ros_neovim.url = "git+https://git.joshuabell.xyz/ringofstorms/nvim";
}; };
@ -75,6 +75,7 @@
appimage-run appimage-run
nodejs_24 nodejs_24
foot foot
vlc
]; ];
# Also allow this key to work for root user, this will let us use this as a remote builder easier # Also allow this key to work for root user, this will let us use this as a remote builder easier
users.users.root.openssh.authorizedKeys.keys = [ users.users.root.openssh.authorizedKeys.keys = [
@ -117,11 +118,9 @@
"dev.vencord.Vesktop" "dev.vencord.Vesktop"
"md.obsidian.Obsidian" "md.obsidian.Obsidian"
"com.spotify.Client" "com.spotify.Client"
"org.videolan.VLC"
"com.bitwarden.desktop" "com.bitwarden.desktop"
"org.openscad.OpenSCAD" "org.openscad.OpenSCAD"
"org.blender.Blender" "org.blender.Blender"
"im.riot.Riot"
"com.rustdesk.RustDesk" "com.rustdesk.RustDesk"
"com.google.Chrome" "com.google.Chrome"
]; ];