forked from kollerma/git-submodule-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-fix-submodules
executable file
·57 lines (48 loc) · 1.55 KB
/
git-fix-submodules
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
#!/bin/bash -e
## Fix submodules: make sure all submodules
## are checked out correctly
## read input, display help if necessary
if [[ "$@" == *--help* ]]; then
cat<<EOF
Fix submodules
This command updates and initializes all submodules.
Orphaned submodule directories are removed if they are clean. The
HEADs of submodules are attached if necessary and possible.
Usage:
git fix-submodules [--skip-checks]
--skip-checks: skip safety checks
EOF
exit 0;
fi
## from the git mailinglist:
function git
{
LC_MESSAGES=C command git "$@"
}
export git
## ensure we are in the toplevel directory
cdup=$(git rev-parse --show-toplevel) &&
cd "$cdup" || {
echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
exit 1
}
## check for modified content and uncommitted changes
if [[ "$@" != *--skip-checks* ]]; then
git check-clean || exit 1
fi
## remove orphaned submodule directories
git rm-orphaned-submodule-dirs || exit 1
## continue only if there are submodules
if [ -f .gitmodules ]; then
## update / initialize submodules
git submodule --quiet update --init || exit 1
## do the same for the submodules
#git submodule --quiet foreach git fix-submodules "$@"
CMD='cd "$1"; git fix-submodules '"$@"
git submodule --quiet foreach 'echo "$toplevel/$path"' |
xargs -r -n1 -P5 bash -c "$CMD" xargs
## attach heads if possible
#git submodule --quiet foreach git attach-head
git submodule --quiet foreach 'echo "$toplevel/$path"' |
xargs -r -n1 -P5 bash -c 'cd "$1"; git attach-head' xargs
fi