Compare commits
2 commits
0581dbff86
...
41ea974e49
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41ea974e49 | ||
|
|
ecddf8ad8d |
3 changed files with 46 additions and 15 deletions
|
|
@ -7,8 +7,8 @@
|
|||
userName = "RingOfStorms (Joshua Bell)";
|
||||
|
||||
extraConfig = {
|
||||
core.pager = "cat";
|
||||
core.editor = "nvim";
|
||||
core.pager = "bat";
|
||||
core.editor = "nano";
|
||||
|
||||
pull.rebase = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -76,20 +76,48 @@ branchdel() {
|
|||
fi
|
||||
|
||||
echo "Removing worktree at: $target_wt"
|
||||
if git -C "$repo_dir" worktree remove "$target_wt" 2>/dev/null; then
|
||||
rm -rf -- "$target_wt" 2>/dev/null || true
|
||||
# helper: attempt a guarded, forceful removal of a directory
|
||||
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"
|
||||
# delete local branch if it exists
|
||||
if git -C "$repo_dir" show-ref --verify --quiet "refs/heads/$branch"; then
|
||||
git -C "$repo_dir" branch -D "$branch" 2>/dev/null || true
|
||||
echo "Deleted local branch: $branch"
|
||||
else
|
||||
echo "Worktree removed from git, but failed to fully delete directory: $target_wt" >&2
|
||||
echo "Attempted to force-delete; you may need to remove it manually with sudo." >&2
|
||||
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
|
||||
if git -C "$repo_dir" show-ref --verify --quiet "refs/heads/$branch"; then
|
||||
git -C "$repo_dir" branch -D "$branch" 2>/dev/null || true
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ with lib;
|
|||
gcm = "git commit -m";
|
||||
stashes = "git stash list";
|
||||
bd = "branch default";
|
||||
li = "link_ignored";
|
||||
bx = "branchdel";
|
||||
b = "branch";
|
||||
|
||||
# ripgrep
|
||||
rg = "rg --no-ignore";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue