This repository has been archived by the owner on Apr 9, 2018. It is now read-only.
forked from adtools/amigaos-cross-toolchain
-
Notifications
You must be signed in to change notification settings - Fork 12
/
update_sub
executable file
·100 lines (91 loc) · 2.31 KB
/
update_sub
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
findmaster() {
# search the master branch by reading .gitmodules
cat "$2/.gitmodules" | \
while read line
do
a=($line)
if [ "${a[0]}" == "[submodule" ]; then
[ "$seen" == "1" ] && return
[ "[submodule \"$1\"]" == "$line" ] && seen=1
else
[ "${a[0]}" == "branch" ] && [ "$seen" == "1" ] && { echo ${a[2]}; return; }
fi
done
}
parselog() {
# collect the commit messages
git log | \
while read line
do
a=($line)
if [ "${a[0]}" == "commit" ]; then
x=${a[1]}
[ "$x" == "$1" ] && { echo -e $msg | sort -u ; break; }
while read line
do
[ "$line" == "" ] && break
done
else
msg="$msg\n$line"
fi
done
}
export script=$(readlink -f $0)
if [ "$2" == "" ]; then
# make the latest commit in each submodule of branch mainbranch the current revision in each submodule
mainbranch=$(git branch | grep \* | cut -d ' ' -f2)
# reset submodules to last revision
git pull
git submodule update
# call me for each submodule
git submodule foreach "$script \"\$name\" \"\$toplevel\" \"$mainbranch\" \"$1\""
# submodules are at most recent positions
if [ "$1" != "" ]; then
# now the merged submodules are added. stash these changes, merge the branch, pop stash and commit
git stash
git merge "$1"
git stash pop
git commit -m "@S updated submodule references"
git push
fi
git commit -m "@S updated submodule references"
git push
else
# called from git submodule above
# make the latest commit in this branch $3 the current revision in this submodule
# get current revision
revision=$(git rev-parse HEAD)
if [ "$3" == "master" ]; then
branch=$(findmaster "$1" "$2")
[ "$branch" == "" ] && branch=master
else
branch="$3"
fi
# switch to branch and check it out, then pull if branch exists
git checkout $branch || exit 0
git pull
head=$(git rev-parse HEAD)
if [ "$revision" != "$head" ]; then
echo scanning from $revision to $head
# get the log messages in between
msg=$(parselog $revision)
if [ "$msg" != "" ]; then
# commit the changes to the master module
pushd "$2"
git add "$1"
git commit -m "@S $1:$msg"
popd
fi
fi
# branch is now up to date
if [ "$4" != "" ]; then
# merge specified branch into "master / what's defined in .gitmodules"
git merge "$4" || exit 0
git push
# add the changes to the master module
pushd "$2"
git add "$1"
popd
fi
fi