-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-done.sh
More file actions
executable file
·81 lines (66 loc) · 1.96 KB
/
task-done.sh
File metadata and controls
executable file
·81 lines (66 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
TASKS_DIR="$ROOT_DIR/tasks"
CONF="$ROOT_DIR/repos.conf"
if [[ ! -f "$CONF" ]]; then
echo "Error: repos.conf not found."
exit 1
fi
mapfile -t VALID_REPOS < <(grep -v '^\s*#' "$CONF" | grep -v '^\s*$')
usage() {
echo "Usage: $0 <task-name> [--delete-branches]"
echo ""
echo "Tear down a workspace created by task-new.sh."
echo ""
echo " task-name The workspace to remove"
echo " --delete-branches Also delete the local branches (default: keep them)"
echo ""
echo "Active workspaces:"
if [[ -d "$TASKS_DIR" ]]; then
for d in "$TASKS_DIR"/*/; do
[[ -d "$d" ]] && echo " $(basename "$d")"
done
else
echo " (none)"
fi
exit 1
}
[[ $# -lt 1 ]] && usage
TASK_NAME="$1"
DELETE_BRANCHES=false
[[ "${2:-}" == "--delete-branches" ]] && DELETE_BRANCHES=true
TASK_DIR="$TASKS_DIR/$TASK_NAME"
if [[ ! -d "$TASK_DIR" ]]; then
echo "Error: workspace '$TASK_NAME' not found at $TASK_DIR"
exit 1
fi
echo "Removing workspace: $TASK_NAME"
echo ""
# Remove worktrees
for repo in "${VALID_REPOS[@]}"; do
src="$ROOT_DIR/$repo"
dest="$TASK_DIR/$repo"
if [[ -d "$dest" ]]; then
echo " Removing worktree: $repo"
git -C "$src" worktree remove "$dest" --force 2>&1 | sed 's/^/ /'
if $DELETE_BRANCHES; then
echo " Deleting branch '$TASK_NAME'"
git -C "$src" branch -D "$TASK_NAME" 2>&1 | sed 's/^/ /' || true
fi
fi
done
# Remove workspace directory
rm -rf "$TASK_DIR"
echo ""
echo "Workspace '$TASK_NAME' removed."
if ! $DELETE_BRANCHES; then
echo ""
echo "Local branches named '$TASK_NAME' were kept. To delete them:"
for repo in "${VALID_REPOS[@]}"; do
src="$ROOT_DIR/$repo"
if git -C "$src" rev-parse --verify "$TASK_NAME" &>/dev/null; then
echo " git -C $repo branch -d $TASK_NAME"
fi
done
fi