git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/bin/git-update-all
diff options
context:
space:
mode:
authormail_redacted_for_web 2026-04-19 12:27:53 +0200
committermail_redacted_for_web 2026-04-19 12:27:53 +0200
commit1a544ef9580f7b64ce789a1dfe26b112b399eb9b (patch)
tree2b0b3435487ddff6cef09d1d5b3442b33ff3a2b7 /bin/git-update-all
parentde89bc2666d41474764a36b930940b72322d6c54 (diff)
downloaddotfiles-1a544ef9580f7b64ce789a1dfe26b112b399eb9b.tar.bz2
fix: abandon ship if we are not on a branch, also skip unnecessary awk by using for-each-ref
Diffstat (limited to 'bin/git-update-all')
-rwxr-xr-xbin/git-update-all23
1 files changed, 13 insertions, 10 deletions
diff --git a/bin/git-update-all b/bin/git-update-all
index d3f6033..0855339 100755
--- a/bin/git-update-all
+++ b/bin/git-update-all
@@ -5,13 +5,16 @@ GITBIN='/usr/bin/git'
# 1. Pull the current branch and also tags, and prune references vanished from remote
"$GITBIN" pull -tpf || exit 110
# 2. Pull all branches existing locally
-mybr="$("$GITBIN" branch --show-current)"
-while read -r branch
-do
- (
- printf '\033[1m\033[3mSwitching to %b.\033[0m\n' "$branch"
- "$GITBIN" switch "$branch" &&\
- "$GITBIN" pull &&\
- "$GITBIN" switch "$mybr"
- )
-done < <("$GITBIN" branch --list|awk '{print $NF}'|grep -vP "^${mybr}\$")
+if ! mybr="$("$GITBIN" symbolic-ref --short HEAD 2>/dev/null)"; then
+ printf 'Not on a branch, aborting.\n' >&2
+else
+ while read -r branch
+ do
+ (
+ printf '\033[1m\033[3mSwitching to %b.\033[0m\n' "$branch"
+ "$GITBIN" switch "$branch" &&\
+ "$GITBIN" pull &&\
+ "$GITBIN" switch "$mybr"
+ )
+ done < <("$GITBIN" for-each-ref --format='%(refname:short)' refs/heads/ | grep -vP "^${mybr}\$")
+fi