new git branching strategy and linking
This commit is contained in:
parent
951dd38e9d
commit
b363f169ce
4 changed files with 55 additions and 24 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
prefix = [
|
prefix = [
|
||||||
"~/projects"
|
"~/projects"
|
||||||
"~/.config"
|
"~/.config"
|
||||||
|
"~/.local/share/git_worktrees/"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -62,11 +62,6 @@ in
|
||||||
identityFile = age.secrets.nix2t.path;
|
identityFile = age.secrets.nix2t.path;
|
||||||
user = "joshua.bell";
|
user = "joshua.bell";
|
||||||
localForwards = [
|
localForwards = [
|
||||||
# {
|
|
||||||
# bind.port = 3000;
|
|
||||||
# host.port = 3000;
|
|
||||||
# host.address = "localhost";
|
|
||||||
# }
|
|
||||||
{
|
{
|
||||||
bind.port = 3002;
|
bind.port = 3002;
|
||||||
host.port = 3002;
|
host.port = 3002;
|
||||||
|
|
@ -79,8 +74,15 @@ in
|
||||||
};
|
};
|
||||||
"t_" = lib.mkIf (hasSecret "nix2t") {
|
"t_" = lib.mkIf (hasSecret "nix2t") {
|
||||||
identityFile = age.secrets.nix2t.path;
|
identityFile = age.secrets.nix2t.path;
|
||||||
hostname = "10.12.14.103";
|
hostname = "10.12.14.181";
|
||||||
user = "joshua.bell";
|
user = "joshua.bell";
|
||||||
|
localForwards = [
|
||||||
|
{
|
||||||
|
bind.port = 3002;
|
||||||
|
host.port = 3002;
|
||||||
|
host.address = "localhost";
|
||||||
|
}
|
||||||
|
];
|
||||||
setEnv = {
|
setEnv = {
|
||||||
TERM = "vt100";
|
TERM = "vt100";
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,7 @@
|
||||||
branch() {
|
branch() {
|
||||||
local branch_name=${1:-}
|
local branch_name=${1:-}
|
||||||
if [ -z "$branch_name" ]; then
|
|
||||||
echo "Usage: branch <name>" >&2
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
# branch <name> — create or open a worktree for <name>
|
|
||||||
# This function will change directory into the selected worktree so the
|
|
||||||
# caller's shell is moved into it.
|
|
||||||
|
|
||||||
local xdg=${XDG_DATA_HOME:-$HOME/.local/share}
|
|
||||||
|
|
||||||
|
# Determine repo root early so we can run branches inside it
|
||||||
local common_dir
|
local common_dir
|
||||||
if ! common_dir=$(git rev-parse --git-common-dir 2>/dev/null); then
|
if ! common_dir=$(git rev-parse --git-common-dir 2>/dev/null); then
|
||||||
echo "Not inside a git repository." >&2
|
echo "Not inside a git repository." >&2
|
||||||
|
|
@ -25,6 +16,36 @@ branch() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If no branch was provided, present an interactive selector combining local and remote branches
|
||||||
|
if [ -z "$branch_name" ]; then
|
||||||
|
if ! command -v fzf >/dev/null 2>&1; then
|
||||||
|
echo "Usage: branch <name>" >&2
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
local branches_list_raw branches_list selection
|
||||||
|
if declare -f local_branches >/dev/null 2>&1; then
|
||||||
|
branches_list_raw=$(local_branches 2>/dev/null || true; remote_branches 2>/dev/null || true)
|
||||||
|
else
|
||||||
|
branches_list_raw=$(git -C "$repo_dir" branch --format='%(refname:short)' 2>/dev/null || true; git -C "$repo_dir" branch -r --format='%(refname:short)' 2>/dev/null | sed 's#^.*/##' || true)
|
||||||
|
fi
|
||||||
|
|
||||||
|
branches_list=$(printf "%s
|
||||||
|
" "$branches_list_raw" | awk '!seen[$0]++')
|
||||||
|
if [ -z "$branches_list" ]; then
|
||||||
|
echo "No branches found." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
selection=$(printf "%s\n" "$branches_list" | fzf --height=40% --prompt="Select branch: ")
|
||||||
|
if [ -z "$selection" ]; then
|
||||||
|
echo "No branch selected." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
branch_name="$selection"
|
||||||
|
fi
|
||||||
|
|
||||||
local repo_base repo_hash default_branch
|
local repo_base repo_hash default_branch
|
||||||
repo_base=$(basename "$repo_dir")
|
repo_base=$(basename "$repo_dir")
|
||||||
repo_hash=$(printf "%s" "$repo_dir" | sha1sum | awk '{print $1}')
|
repo_hash=$(printf "%s" "$repo_dir" | sha1sum | awk '{print $1}')
|
||||||
|
|
|
||||||
|
|
@ -38,24 +38,26 @@ EOF
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local -a candidates
|
local -a candidates=()
|
||||||
IFS=$'\0' read -r -d '' -a candidates < <(git -C "$repo_root" ls-files --others --ignored --exclude-standard -z || true)
|
while IFS= read -r -d '' file; do
|
||||||
|
candidates+=("$file")
|
||||||
|
done < <(git -C "$repo_root" ls-files --others --ignored --exclude-standard -z || true)
|
||||||
|
|
||||||
if [ ${#candidates[@]} -eq 0 ]; then
|
if [ ${#candidates[@]} -eq 0 ]; then
|
||||||
echo "No untracked/ignored files found in $repo_root"
|
echo "No untracked/ignored files found in $repo_root"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
declare -A _seen
|
|
||||||
local -a tops=()
|
local -a tops=()
|
||||||
for c in "${candidates[@]}"; do
|
for c in "${candidates[@]}"; do
|
||||||
c="${c%/}"
|
c="${c%/}"
|
||||||
local top="${c%%/*}"
|
local top="${c%%/*}"
|
||||||
[ -z "$top" ] && continue
|
[ -z "$top" ] && continue
|
||||||
if [ -z "${_seen[$top]:-}" ]; then
|
local found=0
|
||||||
_seen[$top]=1
|
for existing in "${tops[@]}"; do
|
||||||
tops+=("$top")
|
[ "$existing" = "$top" ] && found=1 && break
|
||||||
fi
|
done
|
||||||
|
[ "$found" -eq 0 ] && tops+=("$top")
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ ${#tops[@]} -eq 0 ]; then
|
if [ ${#tops[@]} -eq 0 ]; then
|
||||||
|
|
@ -89,7 +91,12 @@ EOF
|
||||||
if [ -z "$selected" ]; then
|
if [ -z "$selected" ]; then
|
||||||
echo "No files selected." && return 0
|
echo "No files selected." && return 0
|
||||||
fi
|
fi
|
||||||
IFS=$'\n' read -r -d '' -a chosen < <(printf "%s\n" "$selected" && printf '\0')
|
chosen=()
|
||||||
|
while IFS= read -r line; do
|
||||||
|
chosen+=("$line")
|
||||||
|
done <<EOF
|
||||||
|
$selected
|
||||||
|
EOF
|
||||||
else
|
else
|
||||||
chosen=("${filtered[@]}")
|
chosen=("${filtered[@]}")
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue