-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate-submodule.sh
More file actions
executable file
·57 lines (42 loc) · 1.35 KB
/
update-submodule.sh
File metadata and controls
executable file
·57 lines (42 loc) · 1.35 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
#! /bin/bash -
# Updates all submodules. Submodules are mainly clones of github
# repos. Some of them are clones of repos i forked in github to be
# able to modify them easily. Therefore for each submodule i have a
# origin repo and a upstream repo for those that are clones of forks
# in github.
TMPFILE=$(mktemp)
trap 'rm -f $TMPFILE' EXIT
cat << 'EOF' > $TMPFILE
echo -e "\e[31mRepository:\e[0m $(basename $(pwd))"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Current branch is $BRANCH"
if [ ! "xmaster" == "x$BRANCH" ]; then
git checkout master
fi
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Current branch is now $BRANCH"
echo "Fetching origin"
git fetch origin > /dev/null 2>&1
if $(git fetch upstream > /dev/null 2>&1); then
echo "Upstream branch detected"
# Make origin and local in sync
git rebase origin/$BRANCH
git push origin $BRANCH
# Save commits before destroying them with a rebase
git branch --force $BRANCH-before-rebase
# Rebase local changes onto up-to-date upstream
if ! git rebase upstream/master; then
echo "ERROR on rebasing: do it manually or git rebase --abort"
exit
fi
# Push
git push -f origin $BRANCH
git push -f origin $BRANCH-before-rebase
else
echo "No upstream branch"
git rebase origin/$BRANCH
fi
# For git submodule foreach not to fail
exit
EOF
git submodule foreach "bash $TMPFILE"