-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgit-all
More file actions
executable file
·51 lines (44 loc) · 1.74 KB
/
git-all
File metadata and controls
executable file
·51 lines (44 loc) · 1.74 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
#!/bin/bash
#=======================================================================================================================
# Description
# Run a git command recursively for all git repositories, starting from the current one.
# NB: it ignores all directories whose name starts with a '_'.
# Arguments
# $@ - Any arguments to be passed to git
#=======================================================================================================================
# shellcheck source=./common.sh
. "$(dirname "$(realpath "$0")")/common.sh"
USAGE_INFO="Usage: $0 <git_command> [arg...]"
# The first argument must be a git command
cmd="$1"
shift
[[ -z "$cmd" ]] && usage "No git command specified"
# Change the pipe behaviour to allow modifying vars in a subshell (https://github.com/koalaman/shellcheck/wiki/SC2031)
shopt -s lastpipe
# Iterate through all known repositories, ignoring dirs starting with '_'
declare -a err_repos=()
find -type d -name .git ! -path '*/_*' |
xargs dirname |
xargs realpath |
sort |
while read -r dir; do
log "Running ${CLR_OK}git $cmd${CLR_OFF} in $(dirname "$dir")/${CLR_VAR}$(basename "$dir")${CLR_OFF}"
git -C "$dir" "$cmd" "$@"
rc=$?
if ((rc != 0)); then
error "git returned non-zero exit code $rc"
err_repos+=("$dir")
fi
log '--------------------------------------------------------------------------------'
done
# If there was any failure, output a list of failed repositories
if ((${#err_repos[@]})); then
echo
error "✘ Failed in the following repos:"
for dir in "${err_repos[@]}"; do
echo -e "• $(dirname "$dir")/${CLR_VAR}$(basename "$dir")${CLR_OFF}"
done
exit 1
fi
ok "✔ Succeeded"
exit 0