This repository has been archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-submodules.sh
executable file
·76 lines (63 loc) · 1.8 KB
/
update-submodules.sh
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
#!/bin/bash
CONTINUE_FROM=${1%/}
set -eu
export LANG=C
# Check if the repository is clean at start.
# If this is the case, changes will be committed automatically.
REPOSITORY_IS_CLEAN_AT_START=0
if [ $(git status --short | wc -l) = 0 ]; then
REPOSITORY_IS_CLEAN_AT_START=1
fi
# Check if there are changes which were not pushed yet.
# If this is the case, the last commit is amended at the end of the run.
LAST_UPDATE_IS_PUSHED=0
if [ $(git log --oneline origin/master..HEAD | wc -l) = 0 ]; then
LAST_UPDATE_IS_PUSHED=1
fi
# Check if the last commit was a submodule update.
# If this is the case, the last commit is amended at the end of the run.
LAST_COMMIT_IS_SUBMODULE_UPDATE=0
if git log --oneline -n 1 HEAD | egrep -q "Update submodules$"; then
LAST_COMMIT_IS_SUBMODULE_UPDATE=1
fi
SKIP=0
if [ -n "$CONTINUE_FROM" ]; then
SKIP=1
fi
for SUBMODULE in $(git submodule | awk '{print $2}'); do
echo $SUBMODULE
if [ $SUBMODULE = "$CONTINUE_FROM" ]; then
SKIP=0
fi
if [ $SKIP = 1 ]; then
continue
fi
echo "Entering '$SUBMODULE'"
( cd $SUBMODULE && git pull )
done
echo
echo "==========================================="
# Check if the repository is clean (= if there were any changes).
# If this is the case, stop here.
if [ $(git status --short | wc -l) = 0 ]; then
echo "DONE - No changes."
exit 0
fi
if [ $REPOSITORY_IS_CLEAN_AT_START = 1 ]; then
echo "DONE - Committing changes..."
git add .
# Amend the last commit if it was not pushed yet
if [ $LAST_UPDATE_IS_PUSHED = 0 ] && [ $LAST_COMMIT_IS_SUBMODULE_UPDATE = 1 ]; then
git commit --amend -m "Update submodules"
else
git commit -m "Update submodules"
fi
else
echo "DONE"
echo
echo "Repository was not clean at start, please check changes and commit manually:"
echo
echo "\$ git add ."
echo "\$ git commit -m \"Update submodules\""
fi
exit 0