Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 993 lines (929 sloc) 20.762 kb
70c7ac2 @hjemli Add git-submodule command
hjemli authored
1 #!/bin/sh
2 #
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
3 # git-submodules.sh: add, init, update or list git submodules
70c7ac2 @hjemli Add git-submodule command
hjemli authored
4 #
5 # Copyright (c) 2007 Lars Hjemli
6
1d5bec8 @jherland git submodule: Cleanup usage string and add option parsing to cmd_foreac...
jherland authored
7 dashless=$(basename "$0" | sed -e 's/-/ /')
d27b876 @jlehmann git submodule add: Require the new --force option to add ignored paths
jlehmann authored
8 USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
64b19ff @jherland git submodule status: Add --recursive to recurse into nested submodules
jherland authored
9 or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
1d5bec8 @jherland git submodule: Cleanup usage string and add option parsing to cmd_foreac...
jherland authored
10 or: $dashless [--quiet] init [--] [<path>...]
9db31bd @nmorey submodule: Add --force option for git submodule update
nmorey authored
11 or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
adc5423 @gitster Merge branch 'jh/submodule-foreach'
gitster authored
12 or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
15fc56a @jherland git submodule foreach: Add --recursive to recurse into nested submodules
jherland authored
13 or: $dashless [--quiet] foreach [--recursive] <command>
1d5bec8 @jherland git submodule: Cleanup usage string and add option parsing to cmd_foreac...
jherland authored
14 or: $dashless [--quiet] sync [--] [<path>...]"
8f321a3 @gitster scripts: Add placeholders for OPTIONS_SPEC
gitster authored
15 OPTIONS_SPEC=
70c7ac2 @hjemli Add git-submodule command
hjemli authored
16 . git-sh-setup
d0ad825 @avar i18n: git-submodule add git-sh-i18n
avar authored
17 . git-sh-i18n
98fcf84 @mark987 git-submodule - Use "get_default_remote" from git-parse-remote
mark987 authored
18 . git-parse-remote
70c7ac2 @hjemli Add git-submodule command
hjemli authored
19 require_work_tree
20
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
21 command=
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
22 branch=
d27b876 @jlehmann git submodule add: Require the new --force option to add ignored paths
jlehmann authored
23 force=
d92a395 @mstsirkin Add --reference option to git submodule.
mstsirkin authored
24 reference=
70c7ac2 @hjemli Add git-submodule command
hjemli authored
25 cached=
48bb303 git-submodule.sh: properly initialize shell variables
Gerrit Pape authored
26 recursive=
27 init=
1c244f6 @jlehmann git submodule summary: add --files option
jlehmann authored
28 files=
31ca3ac @Fabianx submodule: add --no-fetch parameter to update command
Fabianx authored
29 nofetch=
3294842 @jherland Rename submodule.<name>.rebase to submodule.<name>.update
jherland authored
30 update=
15fc56a @jherland git submodule foreach: Add --recursive to recurse into nested submodules
jherland authored
31 prefix=
70c7ac2 @hjemli Add git-submodule command
hjemli authored
32
f31a522 @mark987 git-submodule - allow a relative path as the subproject url
mark987 authored
33 # Resolve relative url by appending to parent's url
34 resolve_relative_url ()
35 {
98fcf84 @mark987 git-submodule - Use "get_default_remote" from git-parse-remote
mark987 authored
36 remote=$(get_default_remote)
8e7e6f3 @mark987 git-submodule - Fix errors regarding resolve_relative_url
mark987 authored
37 remoteurl=$(git config "remote.$remote.url") ||
4d68932 @jlehmann submodule add: allow relative repository path even when no url is set
jlehmann authored
38 remoteurl=$(pwd) # the repository is its own authoritative upstream
f31a522 @mark987 git-submodule - allow a relative path as the subproject url
mark987 authored
39 url="$1"
99b120a @mark987 git-submodule.sh - Remove trailing / from URL if found
mark987 authored
40 remoteurl=${remoteurl%/}
ea640cc @trast submodule: fix relative url parsing for scp-style origin
trast authored
41 sep=/
f31a522 @mark987 git-submodule - allow a relative path as the subproject url
mark987 authored
42 while test -n "$url"
43 do
44 case "$url" in
45 ../*)
46 url="${url#../}"
ea640cc @trast submodule: fix relative url parsing for scp-style origin
trast authored
47 case "$remoteurl" in
48 */*)
49 remoteurl="${remoteurl%/*}"
50 ;;
51 *:*)
52 remoteurl="${remoteurl%:*}"
53 sep=:
54 ;;
55 *)
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
56 die "$(eval_gettext "cannot strip one component off url '\$remoteurl'")"
ea640cc @trast submodule: fix relative url parsing for scp-style origin
trast authored
57 ;;
58 esac
f31a522 @mark987 git-submodule - allow a relative path as the subproject url
mark987 authored
59 ;;
60 ./*)
61 url="${url#./}"
62 ;;
63 *)
64 break;;
65 esac
66 done
ea640cc @trast submodule: fix relative url parsing for scp-style origin
trast authored
67 echo "$remoteurl$sep${url%/}"
f31a522 @mark987 git-submodule - allow a relative path as the subproject url
mark987 authored
68 }
69
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
70 #
a7b3269 @davvid git-submodule: replace duplicated code with a module_list function
davvid authored
71 # Get submodule info for registered submodules
72 # $@ = path to limit submodule list
73 #
74 module_list()
75 {
313ee0d submodule: process conflicting submodules only once
Nicolas Morey-Chaisemartin authored
76 git ls-files --error-unmatch --stage -- "$@" |
77 perl -e '
78 my %unmerged = ();
79 my ($null_sha1) = ("0" x 40);
80 while (<STDIN>) {
81 chomp;
82 my ($mode, $sha1, $stage, $path) =
83 /^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/;
84 next unless $mode eq "160000";
85 if ($stage ne "0") {
86 if (!$unmerged{$path}++) {
87 print "$mode $null_sha1 U\t$path\n";
88 }
89 next;
90 }
91 print "$_\n";
92 }
93 '
a7b3269 @davvid git-submodule: replace duplicated code with a module_list function
davvid authored
94 }
95
96 #
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
97 # Map submodule path to submodule name
98 #
99 # $1 = path
100 #
101 module_name()
102 {
537601a @gitster git-submodule module_name: avoid using unwieldy "value_regexp" feature.
gitster authored
103 # Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
fe22e54 Improve sed portability
Chris Ridd authored
104 re=$(printf '%s\n' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
a5099bb @imyousuf Use '-f' option to point to the .gitmodules file
imyousuf authored
105 name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
537601a @gitster git-submodule module_name: avoid using unwieldy "value_regexp" feature.
gitster authored
106 sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
107 test -z "$name" &&
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
108 die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$path'")"
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
109 echo "$name"
110 }
33aa6ff @hjemli git-submodule: move cloning into a separate function
hjemli authored
111
112 #
113 # Clone a submodule
114 #
23a485e @gitster git-submodule: rename shell functions for consistency
gitster authored
115 # Prior to calling, cmd_update checks that a possibly existing
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
116 # path is not a git repository.
23a485e @gitster git-submodule: rename shell functions for consistency
gitster authored
117 # Likewise, cmd_add checks that path does not exist at all,
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
118 # since it is the location of a new submodule.
119 #
33aa6ff @hjemli git-submodule: move cloning into a separate function
hjemli authored
120 module_clone()
121 {
122 path=$1
123 url=$2
d92a395 @mstsirkin Add --reference option to git submodule.
mstsirkin authored
124 reference="$3"
7e60407 @jlehmann submodule: update and add must honor --quiet flag
jlehmann authored
125 quiet=
126 if test -n "$GIT_QUIET"
127 then
128 quiet=-q
129 fi
33aa6ff @hjemli git-submodule: move cloning into a separate function
hjemli authored
130
d92a395 @mstsirkin Add --reference option to git submodule.
mstsirkin authored
131 if test -n "$reference"
132 then
7e60407 @jlehmann submodule: update and add must honor --quiet flag
jlehmann authored
133 git-clone $quiet "$reference" -n "$url" "$path"
d92a395 @mstsirkin Add --reference option to git submodule.
mstsirkin authored
134 else
7e60407 @jlehmann submodule: update and add must honor --quiet flag
jlehmann authored
135 git-clone $quiet -n "$url" "$path"
d92a395 @mstsirkin Add --reference option to git submodule.
mstsirkin authored
136 fi ||
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
137 die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")"
33aa6ff @hjemli git-submodule: move cloning into a separate function
hjemli authored
138 }
139
70c7ac2 @hjemli Add git-submodule command
hjemli authored
140 #
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
141 # Add a new submodule to the working tree, .gitmodules and the index
142 #
ec05df3 @mark987 git-submodule - make "submodule add" more strict, and document it
mark987 authored
143 # $@ = repo path
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
144 #
145 # optional branch is stored in global branch variable
146 #
23a485e @gitster git-submodule: rename shell functions for consistency
gitster authored
147 cmd_add()
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
148 {
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
149 # parse $args after "submodule ... add".
150 while test $# -ne 0
151 do
152 case "$1" in
153 -b | --branch)
154 case "$2" in '') usage ;; esac
155 branch=$2
156 shift
157 ;;
d27b876 @jlehmann git submodule add: Require the new --force option to add ignored paths
jlehmann authored
158 -f | --force)
159 force=$1
160 ;;
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
161 -q|--quiet)
2e6a30e @bebarino submodule, repack: migrate to git-sh-setup's say()
bebarino authored
162 GIT_QUIET=1
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
163 ;;
d92a395 @mstsirkin Add --reference option to git submodule.
mstsirkin authored
164 --reference)
165 case "$2" in '') usage ;; esac
166 reference="--reference=$2"
167 shift
168 ;;
169 --reference=*)
170 reference="$1"
171 shift
172 ;;
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
173 --)
174 shift
175 break
176 ;;
177 -*)
178 usage
179 ;;
180 *)
181 break
182 ;;
183 esac
184 shift
185 done
186
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
187 repo=$1
188 path=$2
189
1414e57 @jlehmann git submodule add: make the <path> parameter optional
jlehmann authored
190 if test -z "$path"; then
191 path=$(echo "$repo" |
192 sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
193 fi
194
ec05df3 @mark987 git-submodule - make "submodule add" more strict, and document it
mark987 authored
195 if test -z "$repo" -o -z "$path"; then
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
196 usage
197 fi
198
ec05df3 @mark987 git-submodule - make "submodule add" more strict, and document it
mark987 authored
199 # assure repo is absolute or relative to parent
200 case "$repo" in
201 ./*|../*)
202 # dereference source url relative to parent's url
203 realrepo=$(resolve_relative_url "$repo") || exit
204 ;;
205 *:*|/*)
206 # absolute url
207 realrepo=$repo
208 ;;
209 *)
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
210 die "$(eval_gettext "repo URL: '\$repo' must be absolute or begin with ./|../")"
ec05df3 @mark987 git-submodule - make "submodule add" more strict, and document it
mark987 authored
211 ;;
212 esac
213
db75ada @mjg git submodule: Fix adding of submodules at paths with ./, .. and //
mjg authored
214 # normalize path:
215 # multiple //; leading ./; /./; /../; trailing /
216 path=$(printf '%s/\n' "$path" |
217 sed -e '
218 s|//*|/|g
219 s|^\(\./\)*||
220 s|/\./|/|g
221 :start
222 s|\([^/]*\)/\.\./||
223 tstart
224 s|/*$||
225 ')
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
226 git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
227 die "$(eval_gettext "'\$path' already exists in the index")"
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
228
d27b876 @jlehmann git submodule add: Require the new --force option to add ignored paths
jlehmann authored
229 if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
230 then
6ff875c @jonseymour submodule: take advantage of gettextln and eval_gettextln.
jonseymour authored
231 eval_gettextln "The following path is ignored by one of your .gitignore files:
3a4c3ed @avar i18n: git-submodule "[...] path is ignored" message
avar authored
232 \$path
6ff875c @jonseymour submodule: take advantage of gettextln and eval_gettextln.
jonseymour authored
233 Use -f if you really want to add it." >&2
d27b876 @jlehmann git submodule add: Require the new --force option to add ignored paths
jlehmann authored
234 exit 1
235 fi
236
d4264ca @mark987 git-submodule - Allow adding a submodule in-place
mark987 authored
237 # perhaps the path exists and is already a git repo, else clone it
238 if test -e "$path"
239 then
e965647 @mark987 git-submodule - Fix bugs in adding an existing repo as a module
mark987 authored
240 if test -d "$path"/.git -o -f "$path"/.git
d4264ca @mark987 git-submodule - Allow adding a submodule in-place
mark987 authored
241 then
6ff875c @jonseymour submodule: take advantage of gettextln and eval_gettextln.
jonseymour authored
242 eval_gettextln "Adding existing repo at '\$path' to the index"
d4264ca @mark987 git-submodule - Allow adding a submodule in-place
mark987 authored
243 else
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
244 die "$(eval_gettext "'\$path' already exists and is not a valid git repo")"
d4264ca @mark987 git-submodule - Allow adding a submodule in-place
mark987 authored
245 fi
c2f9391 @mark987 git-submodule - register submodule URL if adding in place
mark987 authored
246
d4264ca @mark987 git-submodule - Allow adding a submodule in-place
mark987 authored
247 else
248
d92a395 @mstsirkin Add --reference option to git submodule.
mstsirkin authored
249 module_clone "$path" "$realrepo" "$reference" || exit
ea10b60 @bjj Work around ash "alternate value" expansion bug
bjj authored
250 (
74ae141 @Oblomov submodules: ensure clean environment when operating in a submodule
Oblomov authored
251 clear_local_git_env
ea10b60 @bjj Work around ash "alternate value" expansion bug
bjj authored
252 cd "$path" &&
253 # ash fails to wordsplit ${branch:+-b "$branch"...}
254 case "$branch" in
255 '') git checkout -f -q ;;
502dc5b @jrn git submodule -b ... of current HEAD fails
jrn authored
256 ?*) git checkout -f -q -B "$branch" "origin/$branch" ;;
ea10b60 @bjj Work around ash "alternate value" expansion bug
bjj authored
257 esac
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
258 ) || die "$(eval_gettext "Unable to checkout submodule '\$path'")"
d4264ca @mark987 git-submodule - Allow adding a submodule in-place
mark987 authored
259 fi
c56dce3 @gitster Merge branch 'jl/submodule-add-relurl-wo-upstream'
gitster authored
260 git config submodule."$path".url "$realrepo"
d4264ca @mark987 git-submodule - Allow adding a submodule in-place
mark987 authored
261
d27b876 @jlehmann git submodule add: Require the new --force option to add ignored paths
jlehmann authored
262 git add $force "$path" ||
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
263 die "$(eval_gettext "Failed to add submodule '\$path'")"
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
264
a5099bb @imyousuf Use '-f' option to point to the .gitmodules file
imyousuf authored
265 git config -f .gitmodules submodule."$path".path "$path" &&
266 git config -f .gitmodules submodule."$path".url "$repo" &&
31991b0 @avar git submodule: add submodules with git add -f <path>
avar authored
267 git add --force .gitmodules ||
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
268 die "$(eval_gettext "Failed to register submodule '\$path'")"
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
269 }
270
271 #
19a31f9 @mark987 git-submodule - Add 'foreach' subcommand
mark987 authored
272 # Execute an arbitrary command sequence in each checked out
273 # submodule
274 #
275 # $@ = command to execute
276 #
277 cmd_foreach()
278 {
1d5bec8 @jherland git submodule: Cleanup usage string and add option parsing to cmd_foreac...
jherland authored
279 # parse $args after "submodule ... foreach".
280 while test $# -ne 0
281 do
282 case "$1" in
283 -q|--quiet)
284 GIT_QUIET=1
285 ;;
15fc56a @jherland git submodule foreach: Add --recursive to recurse into nested submodules
jherland authored
286 --recursive)
287 recursive=1
288 ;;
1d5bec8 @jherland git submodule: Cleanup usage string and add option parsing to cmd_foreac...
jherland authored
289 -*)
290 usage
291 ;;
292 *)
293 break
294 ;;
295 esac
296 shift
297 done
298
f030c96 @avar git-submodule foreach: Add $toplevel variable
avar authored
299 toplevel=$(pwd)
300
4dca1aa @drafnel git-submodule.sh: preserve stdin for the command spawned by foreach
drafnel authored
301 # dup stdin so that it can be restored when running the external
302 # command in the subshell (and a recursive call to this function)
303 exec 3<&0
304
a7b3269 @davvid git-submodule: replace duplicated code with a module_list function
davvid authored
305 module_list |
19a31f9 @mark987 git-submodule - Add 'foreach' subcommand
mark987 authored
306 while read mode sha1 stage path
307 do
308 if test -e "$path"/.git
309 then
490b6d5 @avar i18n: git-submodule "Entering [...]" message
avar authored
310 say "$(eval_gettext "Entering '\$prefix\$path'")"
1e7f2aa @jherland git submodule foreach: Provide access to submodule name, as '$name'
jherland authored
311 name=$(module_name "$path")
15fc56a @jherland git submodule foreach: Add --recursive to recurse into nested submodules
jherland authored
312 (
313 prefix="$prefix$path/"
74ae141 @Oblomov submodules: ensure clean environment when operating in a submodule
Oblomov authored
314 clear_local_git_env
15fc56a @jherland git submodule foreach: Add --recursive to recurse into nested submodules
jherland authored
315 cd "$path" &&
316 eval "$@" &&
317 if test -n "$recursive"
318 then
319 cmd_foreach "--recursive" "$@"
320 fi
4dca1aa @drafnel git-submodule.sh: preserve stdin for the command spawned by foreach
drafnel authored
321 ) <&3 3<&- ||
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
322 die "$(eval_gettext "Stopping at '\$path'; script returned non-zero status.")"
19a31f9 @mark987 git-submodule - Add 'foreach' subcommand
mark987 authored
323 fi
324 done
325 }
326
327 #
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
328 # Register submodules in .git/config
70c7ac2 @hjemli Add git-submodule command
hjemli authored
329 #
330 # $@ = requested paths (default to all)
331 #
23a485e @gitster git-submodule: rename shell functions for consistency
gitster authored
332 cmd_init()
70c7ac2 @hjemli Add git-submodule command
hjemli authored
333 {
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
334 # parse $args after "submodule ... init".
335 while test $# -ne 0
336 do
337 case "$1" in
338 -q|--quiet)
2e6a30e @bebarino submodule, repack: migrate to git-sh-setup's say()
bebarino authored
339 GIT_QUIET=1
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
340 ;;
341 --)
342 shift
343 break
344 ;;
345 -*)
346 usage
347 ;;
348 *)
349 break
350 ;;
351 esac
352 shift
353 done
354
a7b3269 @davvid git-submodule: replace duplicated code with a module_list function
davvid authored
355 module_list "$@" |
70c7ac2 @hjemli Add git-submodule command
hjemli authored
356 while read mode sha1 stage path
357 do
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
358 # Skip already registered paths
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
359 name=$(module_name "$path") || exit
2cd9de3 @jlehmann submodule add: always initialize .git/config entry
jlehmann authored
360 if test -z "$(git config "submodule.$name.url")"
361 then
362 url=$(git config -f .gitmodules submodule."$name".url)
363 test -z "$url" &&
0591c0a @gitster Merge branch 'jc/submodule-sync-no-auto-vivify'
gitster authored
364 die "$(eval_gettext "No url found for submodule path '\$path' in .gitmodules")"
2cd9de3 @jlehmann submodule add: always initialize .git/config entry
jlehmann authored
365
366 # Possibly a url relative to parent
367 case "$url" in
368 ./*|../*)
369 url=$(resolve_relative_url "$url") || exit
370 ;;
371 esac
372 git config submodule."$name".url "$url" ||
0591c0a @gitster Merge branch 'jc/submodule-sync-no-auto-vivify'
gitster authored
373 die "$(eval_gettext "Failed to register url for submodule path '\$path'")"
2cd9de3 @jlehmann submodule add: always initialize .git/config entry
jlehmann authored
374 fi
70c7ac2 @hjemli Add git-submodule command
hjemli authored
375
2cd9de3 @jlehmann submodule add: always initialize .git/config entry
jlehmann authored
376 # Copy "update" setting when it is not set yet
3294842 @jherland Rename submodule.<name>.rebase to submodule.<name>.update
jherland authored
377 upd="$(git config -f .gitmodules submodule."$name".update)"
378 test -z "$upd" ||
2cd9de3 @jlehmann submodule add: always initialize .git/config entry
jlehmann authored
379 test -n "$(git config submodule."$name".update)" ||
3294842 @jherland Rename submodule.<name>.rebase to submodule.<name>.update
jherland authored
380 git config submodule."$name".update "$upd" ||
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
381 die "$(eval_gettext "Failed to register update mode for submodule path '\$path'")"
ca2cedb @whot git-submodule: add support for --rebase.
whot authored
382
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
383 say "$(eval_gettext "Submodule '\$name' (\$url) registered for path '\$path'")"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
384 done
385 }
386
387 #
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
388 # Update each submodule path to correct revision, using clone and checkout as needed
70c7ac2 @hjemli Add git-submodule command
hjemli authored
389 #
390 # $@ = requested paths (default to all)
391 #
23a485e @gitster git-submodule: rename shell functions for consistency
gitster authored
392 cmd_update()
70c7ac2 @hjemli Add git-submodule command
hjemli authored
393 {
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
394 # parse $args after "submodule ... update".
98dbe63 @kballard submodule: only preserve flags across recursive status/update invocation...
kballard authored
395 orig_flags=
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
396 while test $# -ne 0
397 do
398 case "$1" in
399 -q|--quiet)
2e6a30e @bebarino submodule, repack: migrate to git-sh-setup's say()
bebarino authored
400 GIT_QUIET=1
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
401 ;;
be4d2c8 @dscho submodule update: add convenience option --init
dscho authored
402 -i|--init)
d92a395 @mstsirkin Add --reference option to git submodule.
mstsirkin authored
403 init=1
be4d2c8 @dscho submodule update: add convenience option --init
dscho authored
404 ;;
31ca3ac @Fabianx submodule: add --no-fetch parameter to update command
Fabianx authored
405 -N|--no-fetch)
406 nofetch=1
407 ;;
9db31bd @nmorey submodule: Add --force option for git submodule update
nmorey authored
408 -f|--force)
409 force=$1
410 ;;
ca2cedb @whot git-submodule: add support for --rebase.
whot authored
411 -r|--rebase)
3294842 @jherland Rename submodule.<name>.rebase to submodule.<name>.update
jherland authored
412 update="rebase"
ca2cedb @whot git-submodule: add support for --rebase.
whot authored
413 ;;
d92a395 @mstsirkin Add --reference option to git submodule.
mstsirkin authored
414 --reference)
415 case "$2" in '') usage ;; esac
416 reference="--reference=$2"
98dbe63 @kballard submodule: only preserve flags across recursive status/update invocation...
kballard authored
417 orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
418 shift
d92a395 @mstsirkin Add --reference option to git submodule.
mstsirkin authored
419 ;;
420 --reference=*)
421 reference="$1"
422 ;;
42b4917 @jherland git-submodule: add support for --merge.
jherland authored
423 -m|--merge)
424 update="merge"
425 ;;
b13fd5c @jherland git submodule update: Introduce --recursive to update nested submodules
jherland authored
426 --recursive)
427 recursive=1
428 ;;
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
429 --)
430 shift
431 break
432 ;;
433 -*)
434 usage
435 ;;
436 *)
437 break
438 ;;
439 esac
98dbe63 @kballard submodule: only preserve flags across recursive status/update invocation...
kballard authored
440 orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
441 shift
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
442 done
443
d92a395 @mstsirkin Add --reference option to git submodule.
mstsirkin authored
444 if test -n "$init"
445 then
446 cmd_init "--" "$@" || return
447 fi
448
1b4735d @olsonse submodule: no [--merge|--rebase] when newly cloned
olsonse authored
449 cloned_modules=
15ffb7c @iveqy submodule update: continue when a checkout fails
iveqy authored
450 module_list "$@" | {
451 err=
70c7ac2 @hjemli Add git-submodule command
hjemli authored
452 while read mode sha1 stage path
453 do
313ee0d submodule: process conflicting submodules only once
Nicolas Morey-Chaisemartin authored
454 if test "$stage" = U
455 then
456 echo >&2 "Skipping unmerged submodule $path"
457 continue
458 fi
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
459 name=$(module_name "$path") || exit
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
460 url=$(git config submodule."$name".url)
3294842 @jherland Rename submodule.<name>.rebase to submodule.<name>.update
jherland authored
461 update_module=$(git config submodule."$name".update)
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
462 if test -z "$url"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
463 then
464 # Only mention uninitialized submodules when its
465 # path have been specified
466 test "$#" != "0" &&
1c2ef66 @avar i18n: git-submodule "path not initialized" message
avar authored
467 say "$(eval_gettext "Submodule path '\$path' not initialized
468 Maybe you want to use 'update --init'?")"
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
469 continue
470 fi
471
ba88a1f @hjemli Teach git-submodule.sh about the .git file
hjemli authored
472 if ! test -d "$path"/.git -o -f "$path"/.git
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
473 then
d92a395 @mstsirkin Add --reference option to git submodule.
mstsirkin authored
474 module_clone "$path" "$url" "$reference"|| exit
1b4735d @olsonse submodule: no [--merge|--rebase] when newly cloned
olsonse authored
475 cloned_modules="$cloned_modules;$name"
bf2d824 @hjemli git-submodule: remember to checkout after clone
hjemli authored
476 subsha1=
477 else
74ae141 @Oblomov submodules: ensure clean environment when operating in a submodule
Oblomov authored
478 subsha1=$(clear_local_git_env; cd "$path" &&
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
479 git rev-parse --verify HEAD) ||
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
480 die "$(eval_gettext "Unable to find current revision in submodule path '\$path'")"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
481 fi
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
482
3294842 @jherland Rename submodule.<name>.rebase to submodule.<name>.update
jherland authored
483 if ! test -z "$update"
ca2cedb @whot git-submodule: add support for --rebase.
whot authored
484 then
3294842 @jherland Rename submodule.<name>.rebase to submodule.<name>.update
jherland authored
485 update_module=$update
ca2cedb @whot git-submodule: add support for --rebase.
whot authored
486 fi
487
70c7ac2 @hjemli Add git-submodule command
hjemli authored
488 if test "$subsha1" != "$sha1"
489 then
9db31bd @nmorey submodule: Add --force option for git submodule update
nmorey authored
490 subforce=$force
491 # If we don't already have a -f flag and the submodule has never been checked out
492 if test -z "$subsha1" -a -z "$force"
b9b378a @pkufranky git-submodule: Fix "Unable to checkout" for the initial 'update'
pkufranky authored
493 then
9db31bd @nmorey submodule: Add --force option for git submodule update
nmorey authored
494 subforce="-f"
b9b378a @pkufranky git-submodule: Fix "Unable to checkout" for the initial 'update'
pkufranky authored
495 fi
31ca3ac @Fabianx submodule: add --no-fetch parameter to update command
Fabianx authored
496
497 if test -z "$nofetch"
498 then
e5f522d @jlehmann submodule update: Don't fetch when the submodule commit is already prese...
jlehmann authored
499 # Run fetch only if $sha1 isn't present or it
500 # is not reachable from a ref.
74ae141 @Oblomov submodules: ensure clean environment when operating in a submodule
Oblomov authored
501 (clear_local_git_env; cd "$path" &&
f5799e0 @drafnel git-submodule.sh: separate parens by a space to avoid confusing some she...
drafnel authored
502 ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
e5f522d @jlehmann submodule update: Don't fetch when the submodule commit is already prese...
jlehmann authored
503 test -z "$rev") || git-fetch)) ||
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
504 die "$(eval_gettext "Unable to fetch in submodule path '\$path'")"
31ca3ac @Fabianx submodule: add --no-fetch parameter to update command
Fabianx authored
505 fi
506
1b4735d @olsonse submodule: no [--merge|--rebase] when newly cloned
olsonse authored
507 # Is this something we just cloned?
508 case ";$cloned_modules;" in
509 *";$name;"*)
510 # then there is no local change to integrate
511 update_module= ;;
512 esac
513
877449c @gitster git-submodule.sh: clarify the "should we die now" logic
gitster authored
514 must_die_on_failure=
3294842 @jherland Rename submodule.<name>.rebase to submodule.<name>.update
jherland authored
515 case "$update_module" in
516 rebase)
517 command="git rebase"
ee653c8 @avar i18n: git-submodule $update_module say + die messages
avar authored
518 die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$path'")"
519 say_msg="$(eval_gettext "Submodule path '\$path': rebased into '\$sha1'")"
877449c @gitster git-submodule.sh: clarify the "should we die now" logic
gitster authored
520 must_die_on_failure=yes
3294842 @jherland Rename submodule.<name>.rebase to submodule.<name>.update
jherland authored
521 ;;
42b4917 @jherland git-submodule: add support for --merge.
jherland authored
522 merge)
523 command="git merge"
ee653c8 @avar i18n: git-submodule $update_module say + die messages
avar authored
524 die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$path'")"
525 say_msg="$(eval_gettext "Submodule path '\$path': merged in '\$sha1'")"
877449c @gitster git-submodule.sh: clarify the "should we die now" logic
gitster authored
526 must_die_on_failure=yes
42b4917 @jherland git-submodule: add support for --merge.
jherland authored
527 ;;
3294842 @jherland Rename submodule.<name>.rebase to submodule.<name>.update
jherland authored
528 *)
9db31bd @nmorey submodule: Add --force option for git submodule update
nmorey authored
529 command="git checkout $subforce -q"
ee653c8 @avar i18n: git-submodule $update_module say + die messages
avar authored
530 die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$path'")"
531 say_msg="$(eval_gettext "Submodule path '\$path': checked out '\$sha1'")"
3294842 @jherland Rename submodule.<name>.rebase to submodule.<name>.update
jherland authored
532 ;;
533 esac
70c7ac2 @hjemli Add git-submodule command
hjemli authored
534
15ffb7c @iveqy submodule update: continue when a checkout fails
iveqy authored
535 if (clear_local_git_env; cd "$path" && $command "$sha1")
536 then
ff968f0 @gitster Merge branch 'fg/submodule-keep-updating'
gitster authored
537 say "$say_msg"
877449c @gitster git-submodule.sh: clarify the "should we die now" logic
gitster authored
538 elif test -n "$must_die_on_failure"
539 then
ff968f0 @gitster Merge branch 'fg/submodule-keep-updating'
gitster authored
540 die_with_status 2 "$die_msg"
15ffb7c @iveqy submodule update: continue when a checkout fails
iveqy authored
541 else
ff968f0 @gitster Merge branch 'fg/submodule-keep-updating'
gitster authored
542 err="${err};$die_msg"
877449c @gitster git-submodule.sh: clarify the "should we die now" logic
gitster authored
543 continue
15ffb7c @iveqy submodule update: continue when a checkout fails
iveqy authored
544 fi
70c7ac2 @hjemli Add git-submodule command
hjemli authored
545 fi
b13fd5c @jherland git submodule update: Introduce --recursive to update nested submodules
jherland authored
546
547 if test -n "$recursive"
548 then
15ffb7c @iveqy submodule update: continue when a checkout fails
iveqy authored
549 (clear_local_git_env; cd "$path" && eval cmd_update "$orig_flags")
550 res=$?
551 if test $res -gt 0
552 then
ff968f0 @gitster Merge branch 'fg/submodule-keep-updating'
gitster authored
553 die_msg="$(eval_gettext "Failed to recurse into submodule path '\$path'")"
15ffb7c @iveqy submodule update: continue when a checkout fails
iveqy authored
554 if test $res -eq 1
555 then
ff968f0 @gitster Merge branch 'fg/submodule-keep-updating'
gitster authored
556 err="${err};$die_msg"
15ffb7c @iveqy submodule update: continue when a checkout fails
iveqy authored
557 continue
558 else
ff968f0 @gitster Merge branch 'fg/submodule-keep-updating'
gitster authored
559 die_with_status $res "$die_msg"
15ffb7c @iveqy submodule update: continue when a checkout fails
iveqy authored
560 fi
561 fi
b13fd5c @jherland git submodule update: Introduce --recursive to update nested submodules
jherland authored
562 fi
70c7ac2 @hjemli Add git-submodule command
hjemli authored
563 done
15ffb7c @iveqy submodule update: continue when a checkout fails
iveqy authored
564
565 if test -n "$err"
566 then
567 OIFS=$IFS
568 IFS=';'
569 for e in $err
570 do
571 if test -n "$e"
572 then
573 echo >&2 "$e"
574 fi
575 done
576 IFS=$OIFS
577 exit 1
578 fi
579 }
70c7ac2 @hjemli Add git-submodule command
hjemli authored
580 }
581
bffe71f git-submodule: Instead of using only annotated tags, use any tags.
Emil Medve authored
582 set_name_rev () {
583 revname=$( (
74ae141 @Oblomov submodules: ensure clean environment when operating in a submodule
Oblomov authored
584 clear_local_git_env
bffe71f git-submodule: Instead of using only annotated tags, use any tags.
Emil Medve authored
585 cd "$1" && {
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
586 git describe "$2" 2>/dev/null ||
587 git describe --tags "$2" 2>/dev/null ||
f669ac0 @mark987 git-submodule - possibly use branch name to describe a module
mark987 authored
588 git describe --contains "$2" 2>/dev/null ||
589 git describe --all --always "$2"
bffe71f git-submodule: Instead of using only annotated tags, use any tags.
Emil Medve authored
590 }
591 ) )
592 test -z "$revname" || revname=" ($revname)"
593 }
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
594 #
595 # Show commit summary for submodules in index or working tree
596 #
597 # If '--cached' is given, show summary between index and given commit,
598 # or between working tree and given commit
599 #
600 # $@ = [commit (default 'HEAD'),] requested paths (default all)
601 #
602 cmd_summary() {
f2dc06a @pkufranky git-submodule summary: limit summary size
pkufranky authored
603 summary_limit=-1
d0f64dd @pkufranky git-submodule summary: --for-status option
pkufranky authored
604 for_status=
1c244f6 @jlehmann git submodule summary: add --files option
jlehmann authored
605 diff_cmd=diff-index
f2dc06a @pkufranky git-submodule summary: limit summary size
pkufranky authored
606
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
607 # parse $args after "submodule ... summary".
608 while test $# -ne 0
609 do
610 case "$1" in
611 --cached)
612 cached="$1"
613 ;;
1c244f6 @jlehmann git submodule summary: add --files option
jlehmann authored
614 --files)
615 files="$1"
616 ;;
d0f64dd @pkufranky git-submodule summary: --for-status option
pkufranky authored
617 --for-status)
618 for_status="$1"
619 ;;
f2dc06a @pkufranky git-submodule summary: limit summary size
pkufranky authored
620 -n|--summary-limit)
621 if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
622 then
623 :
624 else
625 usage
626 fi
627 shift
628 ;;
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
629 --)
630 shift
631 break
632 ;;
633 -*)
634 usage
635 ;;
636 *)
637 break
638 ;;
639 esac
640 shift
641 done
bffe71f git-submodule: Instead of using only annotated tags, use any tags.
Emil Medve authored
642
f2dc06a @pkufranky git-submodule summary: limit summary size
pkufranky authored
643 test $summary_limit = 0 && return
644
3deea89 @jherland submodule summary: Don't barf when invoked in an empty repo
jherland authored
645 if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"})
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
646 then
647 head=$rev
caa9c3c @peff submodule summary: do not shift a non-existent positional variable
peff authored
648 test $# = 0 || shift
3deea89 @jherland submodule summary: Don't barf when invoked in an empty repo
jherland authored
649 elif test -z "$1" -o "$1" = "HEAD"
650 then
14e940d @gitster submodule summary: do not fail before the first commit
gitster authored
651 # before the first commit: compare with an empty tree
652 head=$(git hash-object -w -t tree --stdin </dev/null)
2ea6c2c @jlehmann git submodule summary: Handle HEAD as argument when on an unborn branch
jlehmann authored
653 test -z "$1" || shift
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
654 else
3deea89 @jherland submodule summary: Don't barf when invoked in an empty repo
jherland authored
655 head="HEAD"
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
656 fi
657
1c244f6 @jlehmann git submodule summary: add --files option
jlehmann authored
658 if [ -n "$files" ]
659 then
660 test -n "$cached" &&
b9b9c22 @avar i18n: git-submodule "cached cannot be used" message
avar authored
661 die "$(gettext -- "--cached cannot be used with --files")"
1c244f6 @jlehmann git submodule summary: add --files option
jlehmann authored
662 diff_cmd=diff-files
663 head=
664 fi
665
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
666 cd_to_toplevel
667 # Get modified modules cared by user
1807650 @jlehmann git submodule: ignore dirty submodules for summary and status
jlehmann authored
668 modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" |
e1622bf @gitster Protect scripted Porcelains from GREP_OPTIONS insanity
gitster authored
669 sane_egrep '^:([0-7]* )?160000' |
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
670 while read mod_src mod_dst sha1_src sha1_dst status name
671 do
672 # Always show modules deleted or type-changed (blob<->module)
673 test $status = D -o $status = T && echo "$name" && continue
674 # Also show added or modified modules which are checked out
675 GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
676 echo "$name"
677 done
678 )
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
679
d0f64dd @pkufranky git-submodule summary: --for-status option
pkufranky authored
680 test -z "$modules" && return
681
1807650 @jlehmann git submodule: ignore dirty submodules for summary and status
jlehmann authored
682 git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules |
e1622bf @gitster Protect scripted Porcelains from GREP_OPTIONS insanity
gitster authored
683 sane_egrep '^:([0-7]* )?160000' |
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
684 cut -c2- |
685 while read mod_src mod_dst sha1_src sha1_dst status name
686 do
687 if test -z "$cached" &&
688 test $sha1_dst = 0000000000000000000000000000000000000000
689 then
690 case "$mod_dst" in
691 160000)
692 sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD)
693 ;;
694 100644 | 100755 | 120000)
695 sha1_dst=$(git hash-object $name)
696 ;;
697 000000)
698 ;; # removed
699 *)
700 # unexpected type
6ff875c @jonseymour submodule: take advantage of gettextln and eval_gettextln.
jonseymour authored
701 eval_gettextln "unexpected mode \$mod_dst" >&2
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
702 continue ;;
703 esac
704 fi
705 missing_src=
706 missing_dst=
707
708 test $mod_src = 160000 &&
30353a4 submodule: use git rev-parse -q
Miklos Vajna authored
709 ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_src^0 >/dev/null &&
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
710 missing_src=t
711
712 test $mod_dst = 160000 &&
30353a4 submodule: use git rev-parse -q
Miklos Vajna authored
713 ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null &&
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
714 missing_dst=t
bffe71f git-submodule: Instead of using only annotated tags, use any tags.
Emil Medve authored
715
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
716 total_commits=
717 case "$missing_src,$missing_dst" in
718 t,)
f62f821 @avar i18n: git-submodule $errmsg messages
avar authored
719 errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \$sha1_src")"
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
720 ;;
721 ,t)
f62f821 @avar i18n: git-submodule $errmsg messages
avar authored
722 errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \$sha1_dst")"
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
723 ;;
724 t,t)
f62f821 @avar i18n: git-submodule $errmsg messages
avar authored
725 errmsg="$(eval_gettext " Warn: \$name doesn't contain commits \$sha1_src and \$sha1_dst")"
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
726 ;;
727 *)
728 errmsg=
729 total_commits=$(
730 if test $mod_src = 160000 -a $mod_dst = 160000
731 then
732 range="$sha1_src...$sha1_dst"
733 elif test $mod_src = 160000
734 then
735 range=$sha1_src
736 else
737 range=$sha1_dst
738 fi
739 GIT_DIR="$name/.git" \
b0e621a @peff script with rev-list instead of log
peff authored
740 git rev-list --first-parent $range -- | wc -l
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
741 )
eed3559 git-submodule summary: fix that some "wc" flavors produce leading spaces
Johannes Sixt authored
742 total_commits=" ($(($total_commits + 0)))"
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
743 ;;
744 esac
745
746 sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
747 sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
748 if test $status = T
749 then
b3e7344 @avar i18n: git-submodule "blob" and "submodule" messages
avar authored
750 blob="$(gettext "blob")"
751 submodule="$(gettext "submodule")"
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
752 if test $mod_dst = 160000
753 then
b3e7344 @avar i18n: git-submodule "blob" and "submodule" messages
avar authored
754 echo "* $name $sha1_abbr_src($blob)->$sha1_abbr_dst($submodule)$total_commits:"
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
755 else
b3e7344 @avar i18n: git-submodule "blob" and "submodule" messages
avar authored
756 echo "* $name $sha1_abbr_src($submodule)->$sha1_abbr_dst($blob)$total_commits:"
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
757 fi
758 else
759 echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
760 fi
761 if test -n "$errmsg"
762 then
763 # Don't give error msg for modification whose dst is not submodule
764 # i.e. deleted or changed to blob
765 test $mod_dst = 160000 && echo "$errmsg"
766 else
767 if test $mod_src = 160000 -a $mod_dst = 160000
768 then
f2dc06a @pkufranky git-submodule summary: limit summary size
pkufranky authored
769 limit=
770 test $summary_limit -gt 0 && limit="-$summary_limit"
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
771 GIT_DIR="$name/.git" \
f2dc06a @pkufranky git-submodule summary: limit summary size
pkufranky authored
772 git log $limit --pretty='format: %m %s' \
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
773 --first-parent $sha1_src...$sha1_dst
774 elif test $mod_dst = 160000
775 then
776 GIT_DIR="$name/.git" \
777 git log --pretty='format: > %s' -1 $sha1_dst
778 else
779 GIT_DIR="$name/.git" \
780 git log --pretty='format: < %s' -1 $sha1_src
781 fi
782 echo
783 fi
784 echo
d0f64dd @pkufranky git-submodule summary: --for-status option
pkufranky authored
785 done |
786 if test -n "$for_status"; then
f17a5d3 @jlehmann git status: Show uncommitted submodule changes too when enabled
jlehmann authored
787 if [ -n "$files" ]; then
6ff875c @jonseymour submodule: take advantage of gettextln and eval_gettextln.
jonseymour authored
788 gettextln "# Submodules changed but not updated:"
f17a5d3 @jlehmann git status: Show uncommitted submodule changes too when enabled
jlehmann authored
789 else
6ff875c @jonseymour submodule: take advantage of gettextln and eval_gettextln.
jonseymour authored
790 gettextln "# Submodule changes to be committed:"
f17a5d3 @jlehmann git status: Show uncommitted submodule changes too when enabled
jlehmann authored
791 fi
d0f64dd @pkufranky git-submodule summary: --for-status option
pkufranky authored
792 echo "#"
793 sed -e 's|^|# |' -e 's|^# $|#|'
794 else
795 cat
796 fi
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
797 }
70c7ac2 @hjemli Add git-submodule command
hjemli authored
798 #
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
799 # List all submodules, prefixed with:
70c7ac2 @hjemli Add git-submodule command
hjemli authored
800 # - submodule not initialized
801 # + different revision checked out
802 #
803 # If --cached was specified the revision in the index will be printed
804 # instead of the currently checked out revision.
805 #
806 # $@ = requested paths (default to all)
807 #
23a485e @gitster git-submodule: rename shell functions for consistency
gitster authored
808 cmd_status()
70c7ac2 @hjemli Add git-submodule command
hjemli authored
809 {
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
810 # parse $args after "submodule ... status".
98dbe63 @kballard submodule: only preserve flags across recursive status/update invocation...
kballard authored
811 orig_flags=
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
812 while test $# -ne 0
813 do
814 case "$1" in
815 -q|--quiet)
2e6a30e @bebarino submodule, repack: migrate to git-sh-setup's say()
bebarino authored
816 GIT_QUIET=1
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
817 ;;
818 --cached)
819 cached=1
820 ;;
64b19ff @jherland git submodule status: Add --recursive to recurse into nested submodules
jherland authored
821 --recursive)
822 recursive=1
823 ;;
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
824 --)
825 shift
826 break
827 ;;
828 -*)
829 usage
830 ;;
831 *)
832 break
833 ;;
834 esac
98dbe63 @kballard submodule: only preserve flags across recursive status/update invocation...
kballard authored
835 orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
836 shift
837 done
838
a7b3269 @davvid git-submodule: replace duplicated code with a module_list function
davvid authored
839 module_list "$@" |
70c7ac2 @hjemli Add git-submodule command
hjemli authored
840 while read mode sha1 stage path
841 do
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
842 name=$(module_name "$path") || exit
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
843 url=$(git config submodule."$name".url)
64b19ff @jherland git submodule status: Add --recursive to recurse into nested submodules
jherland authored
844 displaypath="$prefix$path"
313ee0d submodule: process conflicting submodules only once
Nicolas Morey-Chaisemartin authored
845 if test "$stage" = U
846 then
847 say "U$sha1 $displaypath"
848 continue
849 fi
ba88a1f @hjemli Teach git-submodule.sh about the .git file
hjemli authored
850 if test -z "$url" || ! test -d "$path"/.git -o -f "$path"/.git
70c7ac2 @hjemli Add git-submodule command
hjemli authored
851 then
64b19ff @jherland git submodule status: Add --recursive to recurse into nested submodules
jherland authored
852 say "-$sha1 $displaypath"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
853 continue;
854 fi
41c7c1b @neurocyte git-submodule: Fix two instances of the same typo
neurocyte authored
855 set_name_rev "$path" "$sha1"
1807650 @jlehmann git submodule: ignore dirty submodules for summary and status
jlehmann authored
856 if git diff-files --ignore-submodules=dirty --quiet -- "$path"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
857 then
64b19ff @jherland git submodule status: Add --recursive to recurse into nested submodules
jherland authored
858 say " $sha1 $displaypath$revname"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
859 else
860 if test -z "$cached"
861 then
74ae141 @Oblomov submodules: ensure clean environment when operating in a submodule
Oblomov authored
862 sha1=$(clear_local_git_env; cd "$path" && git rev-parse --verify HEAD)
41c7c1b @neurocyte git-submodule: Fix two instances of the same typo
neurocyte authored
863 set_name_rev "$path" "$sha1"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
864 fi
64b19ff @jherland git submodule status: Add --recursive to recurse into nested submodules
jherland authored
865 say "+$sha1 $displaypath$revname"
866 fi
867
868 if test -n "$recursive"
869 then
870 (
871 prefix="$displaypath/"
74ae141 @Oblomov submodules: ensure clean environment when operating in a submodule
Oblomov authored
872 clear_local_git_env
64b19ff @jherland git submodule status: Add --recursive to recurse into nested submodules
jherland authored
873 cd "$path" &&
a7eff1a @kballard submodule: preserve all arguments exactly when recursing
kballard authored
874 eval cmd_status "$orig_args"
64b19ff @jherland git submodule status: Add --recursive to recurse into nested submodules
jherland authored
875 ) ||
497ee87 @avar i18n: git-submodule die + eval_gettext messages
avar authored
876 die "$(eval_gettext "Failed to recurse into submodule path '\$path'")"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
877 fi
878 done
879 }
2327f61 @davvid git-submodule: add "sync" command
davvid authored
880 #
881 # Sync remote urls for submodules
882 # This makes the value for remote.$remote.url match the value
883 # specified in .gitmodules.
884 #
885 cmd_sync()
886 {
887 while test $# -ne 0
888 do
889 case "$1" in
890 -q|--quiet)
2e6a30e @bebarino submodule, repack: migrate to git-sh-setup's say()
bebarino authored
891 GIT_QUIET=1
2327f61 @davvid git-submodule: add "sync" command
davvid authored
892 shift
893 ;;
894 --)
895 shift
896 break
897 ;;
898 -*)
899 usage
900 ;;
901 *)
902 break
903 ;;
904 esac
905 done
906 cd_to_toplevel
907 module_list "$@" |
908 while read mode sha1 stage path
909 do
910 name=$(module_name "$path")
911 url=$(git config -f .gitmodules --get submodule."$name".url)
baede9f @jherland Fix submodule sync with relative submodule URLs
jherland authored
912
913 # Possibly a url relative to parent
914 case "$url" in
915 ./*|../*)
916 url=$(resolve_relative_url "$url") || exit
917 ;;
918 esac
919
ccee608 @gitster submodule sync: do not auto-vivify uninteresting submodule
gitster authored
920 if git config "submodule.$name.url" >/dev/null 2>/dev/null
2327f61 @davvid git-submodule: add "sync" command
davvid authored
921 then
0591c0a @gitster Merge branch 'jc/submodule-sync-no-auto-vivify'
gitster authored
922 say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
ccee608 @gitster submodule sync: do not auto-vivify uninteresting submodule
gitster authored
923 git config submodule."$name".url "$url"
924
925 if test -e "$path"/.git
926 then
927 (
928 clear_local_git_env
929 cd "$path"
930 remote=$(get_default_remote)
931 git config remote."$remote".url "$url"
932 )
933 fi
2327f61 @davvid git-submodule: add "sync" command
davvid authored
934 fi
935 done
936 }
70c7ac2 @hjemli Add git-submodule command
hjemli authored
937
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
938 # This loop parses the command line arguments to find the
939 # subcommand name to dispatch. Parsing of the subcommand specific
940 # options are primarily done by the subcommand implementations.
941 # Subcommand specific options such as --branch and --cached are
942 # parsed here as well, for backward compatibility.
943
944 while test $# != 0 && test -z "$command"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
945 do
946 case "$1" in
2327f61 @davvid git-submodule: add "sync" command
davvid authored
947 add | foreach | init | update | status | summary | sync)
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
948 command=$1
70c7ac2 @hjemli Add git-submodule command
hjemli authored
949 ;;
950 -q|--quiet)
2e6a30e @bebarino submodule, repack: migrate to git-sh-setup's say()
bebarino authored
951 GIT_QUIET=1
70c7ac2 @hjemli Add git-submodule command
hjemli authored
952 ;;
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
953 -b|--branch)
954 case "$2" in
955 '')
956 usage
957 ;;
958 esac
959 branch="$2"; shift
960 ;;
70c7ac2 @hjemli Add git-submodule command
hjemli authored
961 --cached)
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
962 cached="$1"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
963 ;;
964 --)
965 break
966 ;;
967 -*)
968 usage
969 ;;
970 *)
971 break
972 ;;
973 esac
974 shift
975 done
976
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
977 # No command word defaults to "status"
978 test -n "$command" || command=status
979
980 # "-b branch" is accepted only by "add"
981 if test -n "$branch" && test "$command" != add
982 then
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
983 usage
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
984 fi
985
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
986 # "--cached" is accepted only by "status" and "summary"
987 if test -n "$cached" && test "$command" != status -a "$command" != summary
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
988 then
70c7ac2 @hjemli Add git-submodule command
hjemli authored
989 usage
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
990 fi
991
992 "cmd_$command" "$@"
Something went wrong with that request. Please try again.