-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomptree.sh
More file actions
executable file
·70 lines (58 loc) · 1.82 KB
/
comptree.sh
File metadata and controls
executable file
·70 lines (58 loc) · 1.82 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
#!/usr/bin/env bash
# Show a single unified diff of two branches in VSCode (temporary readonly file).
# Usage: ./scripts/show-branch-diff.sh <branchA> <branchB> [--fetch] [--three-dot] [--wait]
set -euo pipefail
usage() {
cat <<EOF
Usage: $0 branchA branchB [--fetch] [--three-dot] [--wait]
--fetch : run 'git fetch --all' before generating diff
--three-dot : use 'branchA...branchB' (compare vs common ancestor) instead of 'branchA..branchB'
--wait : open VSCode and wait; temp diff file will be removed after VSCode exits
EOF
exit 1
}
if [ $# -lt 2 ]; then usage; fi
BR_A="$1"; BR_B="$2"; shift 2
FETCH=0; THREE_DOT=0; WAIT=0
while [ $# -gt 0 ]; do
case "$1" in
--fetch) FETCH=1;;
--three-dot) THREE_DOT=1;;
--wait) WAIT=1;;
*) usage;;
esac
shift
done
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
cd "$REPO_ROOT"
# Corrected: use a conditional test, not "$FETCH && ..."
if [ "$FETCH" -eq 1 ]; then
git fetch --all --prune
fi
SEP=".."
if [ "$THREE_DOT" -eq 1 ]; then
SEP="..."
fi
TMP=$(mktemp /tmp/git-branch-diff.XXXXXX.diff)
trap 'rm -f "$TMP" >/dev/null 2>&1 || true' EXIT
{
printf "Repository: %s\n" "$REPO_ROOT"
printf "Diff comparison: %s%s%s\n\n" "$BR_A" "$SEP" "$BR_B"
printf "Command: git diff %s%s%s\n\n" "$BR_A" "$SEP" "$BR_B"
} > "$TMP"
git diff --no-ext-diff --stat --summary "$BR_A$SEP$BR_B" >> "$TMP" 2>/dev/null || true
printf "\n\n" >> "$TMP"
git diff --no-ext-diff "$BR_A$SEP$BR_B" >> "$TMP" 2>/dev/null || true
chmod a-w "$TMP" || true
if command -v code >/dev/null 2>&1; then
if [ "$WAIT" -eq 1 ]; then
code --reuse-window --wait "$TMP"
rm -f "$TMP" || true
else
code --reuse-window "$TMP"
echo "Opened diff at: $TMP (temporary file; remove manually if desired)"
fi
else
echo "VSCode CLI 'code' not found. Diff saved to: $TMP"
fi
exit 0