-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfleet
More file actions
executable file
·101 lines (90 loc) · 2.41 KB
/
Copy pathfleet
File metadata and controls
executable file
·101 lines (90 loc) · 2.41 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
# Run a git command across every OpenPhysics repo checked out locally.
#
# Memorable shortcuts for the fleet-git one-liners in doc/fleet-git.md:
# fleet push
# fleet pull --ff-only
# fleet status -s
# fleet --simulation log -1 --oneline
set -euo pipefail
# Resolve symlinks so `~/.local/bin/fleet` still finds sibling scripts.
SOURCE="${BASH_SOURCE[0]}"
while [[ -L "$SOURCE" ]]; do
DIR="$(cd "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE"
done
SCRIPT_DIR="$(cd "$(dirname "$SOURCE")" && pwd)"
usage() {
cat <<'EOF'
Usage: fleet [filters] <git-args...>
Run a git command in every catalog repo that exists locally beside Baton.
Filters (same as parse-repos.sh):
--simulation Only simulation repositories
--no-simulation Only non-simulation repositories
--type TYPE Filter by repos.json type field
--status STATUS Filter by status (active|template|draft|wip|archived)
--lineage LINEAGE Filter by lineage (original|phet|naap)
--catalog PATH Override path to repos.json
-h, --help Show this help
Examples:
fleet push
fleet pull --ff-only
fleet status -s
fleet fetch --all --prune
fleet --simulation log -1 --oneline
fleet --type tool branch -vv
See also: doc/fleet-git.md, scripts/clone-fleet.sh, scripts/fleet-exec.sh
EOF
}
FILTER_ARGS=()
GIT_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
--simulation|--no-simulation)
FILTER_ARGS+=("$1")
shift
;;
--type|--status|--lineage|--catalog)
if [[ $# -lt 2 ]]; then
echo "Missing value for $1" >&2
usage >&2
exit 2
fi
FILTER_ARGS+=("$1" "$2")
shift 2
;;
--)
shift
GIT_ARGS+=("$@")
break
;;
-*)
# Unknown dashed arg: treat as the start of git args (e.g. fleet -C is wrong;
# fleet status -s is handled once we leave the filter loop).
GIT_ARGS+=("$@")
break
;;
*)
GIT_ARGS+=("$@")
break
;;
esac
done
if [[ ${#GIT_ARGS[@]} -eq 0 ]]; then
usage >&2
exit 2
fi
FAILED=0
while IFS= read -r p; do
[[ -z "$p" ]] && continue
printf '\n\033[1m== %s ==\033[0m\n' "$(basename "$p")"
if ! git -C "$p" "${GIT_ARGS[@]}"; then
FAILED=1
fi
done < <("$SCRIPT_DIR/parse-repos.sh" paths --require-local "${FILTER_ARGS[@]}")
exit "$FAILED"