-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathgitAddWorktreesBetween.sh
More file actions
executable file
Β·61 lines (49 loc) Β· 1.92 KB
/
gitAddWorktreesBetween.sh
File metadata and controls
executable file
Β·61 lines (49 loc) Β· 1.92 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
#!/bin/bash
# Usage:
# ./gitAddWorktreesBetween.sh <older-hash> <newer-hash>
# or
# ./gitAddWorktreesBetween.sh "<since-date>" "<until-date>"
#
# Requires: AddWorktreeFromGitLogLineData.sh in the same directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WORKTREE_SCRIPT="$SCRIPT_DIR/AddWorktreeFromGitLogLineData.sh"
if [ $# -ne 2 ]; then
echo "Usage: $0 <older-hash|since-date> <newer-hash|until-date>"
exit 1
fi
START=$1
END=$2
# Detect whether inputs are commit hashes or dates
if [[ "$START" =~ ^[0-9a-fA-F]{6,40}$ && "$END" =~ ^[0-9a-fA-F]{6,40}$ ]]; then
echo "π Using commit range: $START..$END"
COMMITS=$(git log --reverse --pretty=format:'%H %ad' --date=format:'%Y-%m-%d %H:%M' "$START".."$END")
else
echo "π Using date range: $START β $END"
COMMITS=$(git log --reverse --pretty=format:'%H %ad' --date=format:'%Y-%m-%d %H:%M' --since="$START" --until="$END")
fi
if [ -z "$COMMITS" ]; then
echo "β οΈ No commits found in range."
exit 0
fi
echo "β‘οΈ Creating worktrees for $(echo "$COMMITS" | wc -l) commits..."
# Loop over commits
echo "$COMMITS" | while read -r HASH DATE TIME; do
# Construct expected worktree folder name (based on AddWorktreeFromGitLogLineData.sh logic)
DATE_PART=$(echo "$DATE" | cut -d'-' -f2-3)
TIME_PART=$(echo "$TIME" | tr ':' '-')
BRANCHES=$(git branch --contains "$HASH" 2>/dev/null | sed 's/^[* ]*//')
[ -z "$BRANCHES" ] && BRANCHES="noBranch"
BRANCHES_CLEAN=$(echo "$BRANCHES" | tr '\n' '+' | tr -d ' ' | tr '/' '_' | sed 's/+$//')
SHORT_HASH=$(git rev-parse --short "$HASH")
NAME="trice_${DATE_PART}-${TIME_PART}_${SHORT_HASH}_${BRANCHES_CLEAN}"
DIR="../${NAME}"
if [ -d "$DIR" ]; then
echo "βοΈ Skipping existing worktree: $DIR"
continue
fi
echo ""
echo "π§± Processing commit $HASH ($DATE $TIME)"
bash "$WORKTREE_SCRIPT" "$HASH" "$DATE" "$TIME"
done
echo ""
echo "β
All worktrees created (existing ones skipped)."