]>
git.cameronkatri.com Git - cgit.git/blob - submodules.sh
3 # submodules.sh: init, update or list git submodules
5 # Copyright (C) 2006 Lars Hjemli
7 # Licensed under GNU General Public License v2
8 # (see COPYING for full license text)
12 usage
="submodules.sh [-i | -u] [-q] [--cached] [path...]"
37 # Silently checkout specified submodule revision, return exit status of git-checkout
44 $(cd "$1" && git checkout "$2" 1>/dev/null 2>/dev/null)
49 # Find all (requested) submodules, run clone + checkout on missing paths
51 # $@ = requested paths (default to all)
55 git
ls-files --stage -- $@
| grep -e '^160000 ' |
56 while read mode sha1 stage path
58 test -d "$path/.git" && continue
62 rmdir "$path" 2>/dev
/null
||
63 die
"Directory '$path' exist, but not as a submodule"
66 test -e "$path" && die
"A file already exist at path '$path'"
68 url
=$(sed -nre "s/^$path[ \t]+//p" .gitmodules)
69 test -z "$url" && die
"No url found for $path in .gitmodules"
71 git clone
"$url" "$path" || die
"Clone of submodule '$path' failed"
72 module_checkout
"$path" "$sha1" || die
"Checkout of submodule '$path' failed"
73 say
"Submodule '$path' initialized"
78 # Checkout correct revision of each initialized submodule
80 # $@ = requested paths (default to all)
84 git
ls-files --stage -- $@
| grep -e '^160000 ' |
85 while read mode sha1 stage path
87 if ! test -d "$path/.git"
89 say
"Submodule '$path' not initialized"
92 subsha1
=$(cd "$path" && git rev-parse --verify HEAD) ||
93 die
"Unable to find current revision of submodule '$path'"
94 if test "$subsha1" != "$sha1"
96 module_checkout
"$path" "$sha1" ||
97 die
"Unable to checkout revision $sha1 of submodule '$path'"
98 say
"Submodule '$path' reset to revision $sha1"
104 # List all registered submodules, prefixed with:
105 # - submodule not initialized
106 # + different version checked out
108 # If --cached was specified the revision in the index will be printed
109 # instead of the currently checked out revision.
111 # $@ = requested paths (default to all)
115 git
ls-files --stage -- $@
| grep -e '^160000 ' |
116 while read mode sha1 stage path
118 if ! test -d "$path/.git"
123 revname
=$(cd "$path" && git describe $sha1)
124 if git
diff-files --quiet -- "$path"
126 say
" $sha1 $path\t($revname)"
130 sha1
=$(cd "$path" && git rev-parse HEAD)
131 revname
=$(cd "$path" && git describe HEAD)
133 say
"+$sha1 $path\t($revname)"
139 while case "$#" in 0) break ;; esac
173 if test "$init" = "1"
176 elif test "$update" = "1"