Skip to content

Commit 875d062

Browse files
author
Gaspar Chilingarov
committed
Manage submodules init/update/delete automatically.
1 parent 59585ae commit 875d062

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

maint/remove_submodule.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
echo "check source and run commands manually :)"
4+
5+
exit 5
6+
7+
8+
# Remove the submodule entry from .git/config
9+
git submodule deinit -f path/to/submodule
10+
11+
# Remove the submodule directory from the superproject's .git/modules directory
12+
rm -rf .git/modules/path/to/submodule
13+
14+
# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
15+
git rm -f path/to/submodule
16+

maint/update_submodules.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
cd ..
4+
#git submodule foreach git pull
5+
git submodule update --remote --merge
6+

update.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,24 @@ cd $CWD
55

66
git pull
77

8-
# TODO: add functionality to detect submodule URL changes and
9-
# deinit/remove/add
8+
SUBMODULE_LIST=`git submodule status | awk '{print $2}'`
109

10+
HAS_REPOS_W_CHANGED_URLS=""
11+
12+
for SUBMOD in $SUBMODULE_LIST; do
13+
cd $CWD/$SUBMOD
14+
REPO_URL=`git remote -v | grep fetch | awk '{print $2}'`
15+
cd $CWD
16+
MANIFEST_URL=`egrep -A1 "path = $SUBMOD\$" .gitmodules | grep url | awk '{print $3}'`
17+
if [ "$MANIFEST_URL" != "$REPO_URL" ]; then
18+
echo "changed repo URL $SUBMOD $REPO_URL $MANIFEST_URL"
19+
HAS_REPOS_W_CHANGED_URLS="YES"
20+
rm -rf $CWD/$SUBMOD
21+
rm -rf $CWD/.git/modules/$SUBMOD
22+
fi
23+
done
24+
25+
cd $CWD
26+
git submodule sync
27+
git submodule update --init --recursive --depth 100 -j 3
1128
git submodule update --remote --merge

0 commit comments

Comments
 (0)