-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgit-for-each-pull
More file actions
executable file
·67 lines (58 loc) · 1.45 KB
/
Copy pathgit-for-each-pull
File metadata and controls
executable file
·67 lines (58 loc) · 1.45 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
#!/usr/bin/env bash
set -eu -o pipefail
shopt -s lastpipe
# shellcheck source-path=..
. "$HOME"/bin/.o
# shellcheck source-path=..
. "$HOME"/bin/.oc
function ask-continue { return $?; }
options=$(unset GETOPT_COMPATIBLE && getopt -o "hni" --long dry-run,interactive,set-head,help -- "$@")
eval "set -- $options"
dry_run=
set_head=
while (( $# )); do
opt=$1; shift
case "$opt" in
-h|--help)
echo "Usage: $0 [-n|--dry-run] [-h|--help] [--set-head]"
exit
;;
-n|--dry-run) dry_run=: ;;
-i|--interactive) function ask-continue { ooc "error; continue?"; } ;;
--set-head) set_head=: ;;
--) break ;;
esac
done
if (( $# )); then
echo "No args expected"
exit 1
fi
msgs=()
find -L . -maxdepth 2 -name .git | sort \
| while read -r repo; do
repo=$(realpath --relative-base=. "${repo%/.git}")
if [[ $set_head ]]; then
o git -C "$repo" remote set-head --auto origin || ask-continue
fi
head=$(git -C "$repo" symbolic-ref -q refs/remotes/origin/HEAD) || {
msgs+=("$repo - origin/HEAD unknown")
continue
}
branch=$(git -C "$repo" current-branch) || {
msgs+=("$repo - no current branch")
continue
}
status=$(git -C "$repo" status --porcelain --untracked-files=no)
if [[ $branch != "${head##*/}" ]]; then
msgs+=("$repo - different branch: $branch != ${head##*/}")
elif [[ $status ]]; then
msgs+=("$repo - dirty")
else
if [[ ! $dry_run ]]; then
o git -C "$repo" pull || ask-continue
fi
fi
done
for msg in "${msgs[@]}"; do
oo "$msg"
done