Compare commits

..

2 commits

Author SHA1 Message Date
RingOfStorms (Joshua Bell)
41ea974e49 small updates to git funcs 2025-09-19 17:07:19 -05:00
RingOfStorms (Joshua Bell)
ecddf8ad8d add more git alias 2025-09-18 22:14:56 -05:00
3 changed files with 46 additions and 15 deletions

View file

@ -7,8 +7,8 @@
userName = "RingOfStorms (Joshua Bell)"; userName = "RingOfStorms (Joshua Bell)";
extraConfig = { extraConfig = {
core.pager = "cat"; core.pager = "bat";
core.editor = "nvim"; core.editor = "nano";
pull.rebase = false; pull.rebase = false;

View file

@ -76,20 +76,48 @@ branchdel() {
fi fi
echo "Removing worktree at: $target_wt" echo "Removing worktree at: $target_wt"
if git -C "$repo_dir" worktree remove "$target_wt" 2>/dev/null; then # helper: attempt a guarded, forceful removal of a directory
rm -rf -- "$target_wt" 2>/dev/null || true remove_dir_forcefully() {
local dir="$1"
if [ -z "$dir" ]; then
return 1
fi
# resolve absolute paths
local abs_dir abs_repo
abs_dir=$(readlink -f -- "$dir" 2>/dev/null) || abs_dir="$dir"
abs_repo=$(readlink -f -- "$repo_dir" 2>/dev/null) || abs_repo="$repo_dir"
# safety checks: do not remove repository root or /
if [ "$abs_dir" = "/" ] || [ "$abs_dir" = "$abs_repo" ]; then
echo "Refusing to remove unsafe path: $abs_dir" >&2
return 1
fi
# try plain rm -rf
rm -rf -- "$abs_dir" 2>/dev/null && return 0
# fix permissions then try again
chmod -R u+rwx "$abs_dir" 2>/dev/null || true
rm -rf -- "$abs_dir" 2>/dev/null && return 0
# try removing contents first, then remove directory
if find "$abs_dir" -mindepth 1 -exec rm -rf -- {} + 2>/dev/null; then
rmdir "$abs_dir" 2>/dev/null || true
fi
# final existence check
[ ! -e "$abs_dir" ]
}
# try unregistering the worktree, prefer normal then fallback to --force
if git -C "$repo_dir" worktree remove "$target_wt" 2>/dev/null || git -C "$repo_dir" worktree remove --force "$target_wt" 2>/dev/null; then
if remove_dir_forcefully "$target_wt"; then
echo "Removed worktree: $target_wt" echo "Removed worktree: $target_wt"
# delete local branch if it exists else
if git -C "$repo_dir" show-ref --verify --quiet "refs/heads/$branch"; then echo "Worktree removed from git, but failed to fully delete directory: $target_wt" >&2
git -C "$repo_dir" branch -D "$branch" 2>/dev/null || true echo "Attempted to force-delete; you may need to remove it manually with sudo." >&2
echo "Deleted local branch: $branch"
fi fi
return 0
fi
# try with --force as a fallback
if git -C "$repo_dir" worktree remove --force "$target_wt" 2>/dev/null; then
rm -rf -- "$target_wt" 2>/dev/null || true
echo "Removed worktree (forced): $target_wt"
# delete local branch if it exists # delete local branch if it exists
if git -C "$repo_dir" show-ref --verify --quiet "refs/heads/$branch"; then if git -C "$repo_dir" show-ref --verify --quiet "refs/heads/$branch"; then
git -C "$repo_dir" branch -D "$branch" 2>/dev/null || true git -C "$repo_dir" branch -D "$branch" 2>/dev/null || true

View file

@ -53,6 +53,9 @@ with lib;
gcm = "git commit -m"; gcm = "git commit -m";
stashes = "git stash list"; stashes = "git stash list";
bd = "branch default"; bd = "branch default";
li = "link_ignored";
bx = "branchdel";
b = "branch";
# ripgrep # ripgrep
rg = "rg --no-ignore"; rg = "rg --no-ignore";