From 3ebfcbe07db26c96e5171714a071af9dcbfc647b Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Wed, 10 Nov 2021 17:23:46 +0100 Subject: [PATCH] bin/git: improve branch handling --- .local/bin/scripts/git-aur | 2 +- .local/bin/scripts/git-rmbranch | 11 +++++++---- .local/bin/scripts/git-rmgonebranches | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.local/bin/scripts/git-aur b/.local/bin/scripts/git-aur index a95be3c..8b38c35 100755 --- a/.local/bin/scripts/git-aur +++ b/.local/bin/scripts/git-aur @@ -21,7 +21,7 @@ case $command in git aur push --amend;; (push) makepkg --printsrcinfo > .SRCINFO - git add -f .SRCINFO *.install >/dev/null || true + git add -f .SRCINFO *.install 2>/dev/null || true git commit -v -a "$@" git push;; esac diff --git a/.local/bin/scripts/git-rmbranch b/.local/bin/scripts/git-rmbranch index 5c7d798..44f630a 100755 --- a/.local/bin/scripts/git-rmbranch +++ b/.local/bin/scripts/git-rmbranch @@ -1,7 +1,10 @@ #!/bin/sh -# Removes the given branch locally and remotely. -# With no argument it switches to the default branch and deletes the current branch. +# Remove the given branch locally and remotely. +# Without argument delete the current branch after switching to the default branch. branch=${1:-$(git curbranch)} -echo "${@:-$branch}" | sed 's/\([^ ]\+\)/\1@{push}/g' | xargs git rev-parse --abbrev-ref --revs-only | sed 's/\// /' | xargs --no-run-if-empty git push -d -test -n "$1" || git checkout main || git checkout master || git checkout $(cat "$(git rev-parse --git-path refs/remotes/origin/HEAD)" | sed 's|.*/||') +echo "${@:-$branch}" | sed 's/\([^ ]\+\)/\1@{push}/g' | + xargs git rev-parse --abbrev-ref --revs-only | sed 's/\// /' | + xargs -L 1 --no-run-if-empty git push -d +test -n "$1" || git checkout main || git checkout master || + git checkout $(cat "$(git rev-parse --git-path refs/remotes/origin/HEAD)" | sed 's|.*/||') git branch -D "${@:-$branch}" diff --git a/.local/bin/scripts/git-rmgonebranches b/.local/bin/scripts/git-rmgonebranches index 33366e1..9c5fc59 100755 --- a/.local/bin/scripts/git-rmgonebranches +++ b/.local/bin/scripts/git-rmgonebranches @@ -1,6 +1,6 @@ #!/bin/sh # Cleans up remote branches and removes branches where the remote-tracking branches got removed. -git fetch --prune && +git fetch --all --prune && for branch in `git branch -vv | grep ": gone]" | cut -d" " -f3` do git branch -D "$branch" done