forked from timvideos/litex-buildenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge-upstream.sh
executable file
·94 lines (79 loc) · 1.9 KB
/
merge-upstream.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
set -e
TARGETS=${@-$(find * -maxdepth 0 -type d)}
COMMIT_MSG=$(tempfile) || exit
trap "rm -f -- '$COMMIT_MSG'" EXIT
MODULES=()
for TARGET in $TARGETS; do
if [ ! -e $TARGET/.git ] || ! grep -q "gitdir:" $TARGET/.git 2> /dev/null; then
echo "Skipping $TARGET as not submodule"
continue
else
echo "Submodule $TARGET"
MODULES+=("$TARGET")
fi
git submodule sync --recursive -- $TARGET
git submodule update --recursive --init $TARGET
done
echo
echo "Found submodules:"
declare -p MODULES
echo
cat > $COMMIT_MSG <<EOF
Updating submodules.
EOF
DIRTY=0
for TARGET in ${MODULES[@]}; do
pushd $TARGET > /dev/null
VERSION=$(git describe --always --dirty)
echo -n "$TARGET version ($VERSION) " | grep --color -E "dirty|$"
if echo $VERSION | grep -q "dirty"; then
DIRTY=1
fi
popd > /dev/null
done
if [ $DIRTY = 0 ]; then
echo "All targets clean, good to update."
else
echo "Some target are dirty, can't update."
exit 1
fi
for TARGET in ${MODULES[@]}; do
(
case $TARGET in
*)
BRANCH=master
;;
esac
cd $TARGET
echo
echo "$TARGET checking for updates.."
BEFORE_VER=$(git describe --always --dirty)
git fetch origin | sed -e's/^/ /'
git checkout origin/$BRANCH | sed -e's/^/ /'
git submodule update --recursive --init
AFTER_VER=$(git describe --always --dirty)
if echo $AFTER_VER | grep -q "dirty"; then
echo "Updated version is dirty!?"
exit 1
fi
if [ x"$BEFORE_VER" = x"$AFTER_VER" ]; then
echo "$TARGET is unchanged"
else
echo "Move $TARGET from $BEFORE_VER to $AFTER_VER"
cat >> $COMMIT_MSG <<EOF
* $TARGET changed from $BEFORE_VER to $AFTER_VER
$(git log --graph --pretty=format:'%h - %s <%an>' --no-color --abbrev-commit $BEFORE_VER..$AFTER_VER | sed -e's/^/ /')
EOF
fi
echo
)
git add $TARGET
done
cat >> $COMMIT_MSG <<EOF
Full submodule status
--
EOF
git submodule status >> $COMMIT_MSG
echo "" >> $COMMIT_MSG
git commit -F- < $COMMIT_MSG