From d7a4ab18392bf2b7bd97b64b367aeb747080c199 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 30 Jun 2022 14:19:20 +0200 Subject: [PATCH] gwt: Add helper for worktre management --- gwt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 gwt diff --git a/gwt b/gwt new file mode 100755 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 -- 2.39.2