]> piware.de Git - bin.git/commitdiff
gwt: Add helper for worktre management
authorMartin Pitt <martin@piware.de>
Thu, 30 Jun 2022 12:19:20 +0000 (14:19 +0200)
committerMartin Pitt <martin@piware.de>
Thu, 30 Jun 2022 12:19:20 +0000 (14:19 +0200)
gwt [new file with mode: 0755]

diff --git a/gwt b/gwt
new file mode 100755 (executable)
index 0000000..1a4c03c
--- /dev/null
+++ b/gwt
@@ -0,0 +1,21 @@
+#!/bin/sh
+set -eux
+
+proj=$(basename $(dirname $(pwd)))
+
+prune() {
+    for branch in $(git remote prune "$1" | grep -o "$1/.*$"); do
+        branch="${branch#*/}"
+        echo "Cleaning up $branch"
+        git worktree remove --force "$branch"
+        git branch -D "$branch"
+    done
+    git worktree prune
+}
+
+case "$1" in
+    checkout) git worktree add ../$2 ;;
+    add) git worktree add ../$2 -b $2 main ;;
+    prune) prune "$2";;
+    *) echo "Unknown command $1" >&2; exit 1 ;;
+esac