-
Notifications
You must be signed in to change notification settings - Fork 2
/
update
executable file
·34 lines (26 loc) · 1006 Bytes
/
update
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
#!/usr/bin/env bash
test -z "${DEBUG}" || set -x
: "${UPDATE_LIST:=}"
for d in $UPDATE_LIST; do
hi="$(tput bold; tput setaf 7; tput setab 1;)"
warn="${hi}WARNING$(tput sgr0): unable to update ${d} >>>"
warnRepo="${warn} not a git repo."
warnBranch="${warn} not on main."
warnDirty="${warn} DIRTY."
# test for git repo
test -d "$d/.git" || { echo -e "$warnRepo" >&2; continue; }
pushd "$d" > /dev/null || exit
git diff --no-ext-diff --quiet --exit-code \
|| { echo -e "$warnDirty" >&2; continue; }
# current branch
_branch=$(git symbolic-ref HEAD 2>/dev/null)
test -n "$_branch" || _branch=$(git describe --contains --all HEAD)
test -n "$_branch" || _branch=$(git rev-parse --short HEAD)
_branch=${_branch##refs/heads/}
case $_branch in
master) git pull --quiet origin "$_branch" > /dev/null ;;
main) git pull --quiet origin "$_branch" > /dev/null ;;
?|*) echo -e "$warnBranch" >&2; continue ;;
esac
popd > /dev/null || exit
done