-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·70 lines (56 loc) · 2 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·70 lines (56 loc) · 2 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
set -euo pipefail
# ArrowCode local updater script
# Updates the ArrowCode repository to the latest code on the current branch while preserving local changes
RED=$'\033[0;31m'
GRN=$'\033[0;32m'
CYN=$'\033[0;36m'
RST=$'\033[0m'
log() { printf '%s==>%s %s\n' "$CYN" "$RST" "$*"; }
ok() { printf '%s[ok]%s %s\n' "$GRN" "$RST" "$*"; }
err() { printf '%s[err]%s %s\n' "$RED" "$RST" "$*" >&2; }
# Find ArrowCode base directory dynamically (even if piped via stdin)
if [ -n "${BASH_SOURCE[0]:-}" ] && [ -f "${BASH_SOURCE[0]}" ]; then
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
else
# fallback to global/local shared locations if piped via stdin
DIR="${ARROWCODE_DIR:-$HOME/.local/share/arrowcode}"
fi
if [ ! -d "$DIR" ] || [ ! -f "$DIR/package.json" ]; then
# Try to find base from command line 'arrowcode' binary symlink or standard home folder
if command -v arrowcode >/dev/null 2>&1; then
BIN_PATH=$(which arrowcode)
if [ -h "$BIN_PATH" ]; then
REAL_BIN=$(readlink "$BIN_PATH")
DIR="$(cd "$(dirname "$REAL_BIN")/.." && pwd)"
fi
fi
fi
if [ ! -d "$DIR" ] || [ ! -f "$DIR/package.json" ]; then
err "Could not find ArrowCode installation directory. Please run the installer first or set ARROWCODE_DIR."
exit 1
fi
cd "$DIR"
log "Updating ArrowCode at $DIR..."
# Keep local changes with git stash if there are any
HAS_CHANGES=0
if ! git diff --quiet || ! git diff --cached --quiet; then
HAS_CHANGES=1
log "Saving local changes with git stash..."
git stash -u
fi
# Fetch and rebase / merge latest from branch
BRANCH=$(git rev-parse --abbrev-ref HEAD)
log "Fetching latest commits from remote on branch: $BRANCH"
git fetch origin "$BRANCH"
log "Pulling latest changes..."
git pull --rebase origin "$BRANCH"
# Restore local changes if stashed
if [ "$HAS_CHANGES" -eq 1 ]; then
log "Restoring local changes..."
git stash pop
fi
# Re-install dependencies with bun
log "Running bun install to ensure package sync..."
bun install
ok "ArrowCode successfully updated!"