Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 610 lines (562 sloc) 12.434 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
f2dc06a @pkufranky git-submodule summary: limit summary size
pkufranky authored
7 USAGE="[--quiet] [--cached] \
8 [add <repo> [-b branch]|status|init|update|summary [-n|--summary-limit <n>] [<commit>]] \
9 [--] [<path>...]"
8f321a3 @gitster scripts: Add placeholders for OPTIONS_SPEC
gitster authored
10 OPTIONS_SPEC=
70c7ac2 @hjemli Add git-submodule command
hjemli authored
11 . git-sh-setup
12 require_work_tree
13
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
14 command=
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
15 branch=
70c7ac2 @hjemli Add git-submodule command
hjemli authored
16 quiet=
17 cached=
18
19 #
20 # print stuff on stdout unless -q was specified
21 #
22 say()
23 {
24 if test -z "$quiet"
25 then
26 echo "$@"
27 fi
28 }
29
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
30 # NEEDSWORK: identical function exists in get_repo_base in clone.sh
31 get_repo_base() {
32 (
33 cd "`/bin/pwd`" &&
34 cd "$1" || cd "$1.git" &&
35 {
36 cd .git
37 pwd
38 }
39 ) 2>/dev/null
40 }
41
f31a522 @mark987 git-submodule - allow a relative path as the subproject url
mark987 authored
42 # Resolve relative url by appending to parent's url
43 resolve_relative_url ()
44 {
45 branch="$(git symbolic-ref HEAD 2>/dev/null)"
46 remote="$(git config branch.${branch#refs/heads/}.remote)"
47 remote="${remote:-origin}"
48 remoteurl="$(git config remote.$remote.url)" ||
49 die "remote ($remote) does not have a url in .git/config"
50 url="$1"
51 while test -n "$url"
52 do
53 case "$url" in
54 ../*)
55 url="${url#../}"
56 remoteurl="${remoteurl%/*}"
57 ;;
58 ./*)
59 url="${url#./}"
60 ;;
61 *)
62 break;;
63 esac
64 done
65 echo "$remoteurl/$url"
66 }
67
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
68 #
69 # Map submodule path to submodule name
70 #
71 # $1 = path
72 #
73 module_name()
74 {
537601a @gitster git-submodule module_name: avoid using unwieldy "value_regexp" feature.
gitster authored
75 # Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
4f2e94c Fix sed string regex escaping in module_name.
Ralf Wildenhues authored
76 re=$(printf '%s' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
537601a @gitster git-submodule module_name: avoid using unwieldy "value_regexp" feature.
gitster authored
77 name=$( GIT_CONFIG=.gitmodules \
78 git config --get-regexp '^submodule\..*\.path$' |
79 sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
80 test -z "$name" &&
81 die "No submodule mapping found in .gitmodules for path '$path'"
82 echo "$name"
83 }
33aa6ff @hjemli git-submodule: move cloning into a separate function
hjemli authored
84
85 #
86 # Clone a submodule
87 #
23a485e @gitster git-submodule: rename shell functions for consistency
gitster authored
88 # Prior to calling, cmd_update checks that a possibly existing
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
89 # path is not a git repository.
23a485e @gitster git-submodule: rename shell functions for consistency
gitster authored
90 # Likewise, cmd_add checks that path does not exist at all,
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
91 # since it is the location of a new submodule.
92 #
33aa6ff @hjemli git-submodule: move cloning into a separate function
hjemli authored
93 module_clone()
94 {
95 path=$1
96 url=$2
97
98 # If there already is a directory at the submodule path,
99 # expect it to be empty (since that is the default checkout
100 # action) and try to remove it.
101 # Note: if $path is a symlink to a directory the test will
102 # succeed but the rmdir will fail. We might want to fix this.
103 if test -d "$path"
104 then
105 rmdir "$path" 2>/dev/null ||
106 die "Directory '$path' exist, but is neither empty nor a git repository"
107 fi
108
109 test -e "$path" &&
110 die "A file already exist at path '$path'"
111
112 git-clone -n "$url" "$path" ||
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
113 die "Clone of '$url' into submodule path '$path' failed"
33aa6ff @hjemli git-submodule: move cloning into a separate function
hjemli authored
114 }
115
70c7ac2 @hjemli Add git-submodule command
hjemli authored
116 #
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
117 # Add a new submodule to the working tree, .gitmodules and the index
118 #
119 # $@ = repo [path]
120 #
121 # optional branch is stored in global branch variable
122 #
23a485e @gitster git-submodule: rename shell functions for consistency
gitster authored
123 cmd_add()
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
124 {
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
125 # parse $args after "submodule ... add".
126 while test $# -ne 0
127 do
128 case "$1" in
129 -b | --branch)
130 case "$2" in '') usage ;; esac
131 branch=$2
132 shift
133 ;;
134 -q|--quiet)
135 quiet=1
136 ;;
137 --)
138 shift
139 break
140 ;;
141 -*)
142 usage
143 ;;
144 *)
145 break
146 ;;
147 esac
148 shift
149 done
150
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
151 repo=$1
152 path=$2
153
154 if test -z "$repo"; then
155 usage
156 fi
157
f31a522 @mark987 git-submodule - allow a relative path as the subproject url
mark987 authored
158 case "$repo" in
159 ./*|../*)
160 # dereference source url relative to parent's url
161 realrepo="$(resolve_relative_url $repo)" ;;
162 *)
163 # Turn the source into an absolute path if
164 # it is local
165 if base=$(get_repo_base "$repo"); then
166 repo="$base"
167 fi
fe50eef Fix adding a submodule with a remote url
Daniel Barkalow authored
168 realrepo=$repo
f31a522 @mark987 git-submodule - allow a relative path as the subproject url
mark987 authored
169 ;;
170 esac
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
171
172 # Guess path from repo if not specified or strip trailing slashes
173 if test -z "$path"; then
174 path=$(echo "$repo" | sed -e 's|/*$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
175 else
176 path=$(echo "$path" | sed -e 's|/*$||')
177 fi
178
179 test -e "$path" &&
180 die "'$path' already exists"
181
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
182 git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
183 die "'$path' already exists in the index"
184
f31a522 @mark987 git-submodule - allow a relative path as the subproject url
mark987 authored
185 module_clone "$path" "$realrepo" || exit
5188408 @Tux Do not rely on the exit status of "unset" for unset variables
Tux authored
186 (unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) ||
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
187 die "Unable to checkout submodule '$path'"
188 git add "$path" ||
189 die "Failed to add submodule '$path'"
190
191 GIT_CONFIG=.gitmodules git config submodule."$path".path "$path" &&
192 GIT_CONFIG=.gitmodules git config submodule."$path".url "$repo" &&
193 git add .gitmodules ||
194 die "Failed to register submodule '$path'"
195 }
196
197 #
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
198 # Register submodules in .git/config
70c7ac2 @hjemli Add git-submodule command
hjemli authored
199 #
200 # $@ = requested paths (default to all)
201 #
23a485e @gitster git-submodule: rename shell functions for consistency
gitster authored
202 cmd_init()
70c7ac2 @hjemli Add git-submodule command
hjemli authored
203 {
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
204 # parse $args after "submodule ... init".
205 while test $# -ne 0
206 do
207 case "$1" in
208 -q|--quiet)
209 quiet=1
210 ;;
211 --)
212 shift
213 break
214 ;;
215 -*)
216 usage
217 ;;
218 *)
219 break
220 ;;
221 esac
222 shift
223 done
224
70c7ac2 @hjemli Add git-submodule command
hjemli authored
225 git ls-files --stage -- "$@" | grep -e '^160000 ' |
226 while read mode sha1 stage path
227 do
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
228 # Skip already registered paths
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
229 name=$(module_name "$path") || exit
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
230 url=$(git config submodule."$name".url)
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
231 test -z "$url" || continue
70c7ac2 @hjemli Add git-submodule command
hjemli authored
232
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
233 url=$(GIT_CONFIG=.gitmodules git config submodule."$name".url)
70c7ac2 @hjemli Add git-submodule command
hjemli authored
234 test -z "$url" &&
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
235 die "No url found for submodule path '$path' in .gitmodules"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
236
f31a522 @mark987 git-submodule - allow a relative path as the subproject url
mark987 authored
237 # Possibly a url relative to parent
238 case "$url" in
239 ./*|../*)
240 url="$(resolve_relative_url "$url")"
241 ;;
242 esac
243
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
244 git config submodule."$name".url "$url" ||
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
245 die "Failed to register url for submodule path '$path'"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
246
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
247 say "Submodule '$name' ($url) registered for path '$path'"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
248 done
249 }
250
251 #
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
252 # Update each submodule path to correct revision, using clone and checkout as needed
70c7ac2 @hjemli Add git-submodule command
hjemli authored
253 #
254 # $@ = requested paths (default to all)
255 #
23a485e @gitster git-submodule: rename shell functions for consistency
gitster authored
256 cmd_update()
70c7ac2 @hjemli Add git-submodule command
hjemli authored
257 {
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
258 # parse $args after "submodule ... update".
259 while test $# -ne 0
260 do
261 case "$1" in
262 -q|--quiet)
263 quiet=1
264 ;;
265 --)
266 shift
267 break
268 ;;
269 -*)
270 usage
271 ;;
272 *)
273 break
274 ;;
275 esac
276 shift
277 done
278
70c7ac2 @hjemli Add git-submodule command
hjemli authored
279 git ls-files --stage -- "$@" | grep -e '^160000 ' |
280 while read mode sha1 stage path
281 do
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
282 name=$(module_name "$path") || exit
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
283 url=$(git config submodule."$name".url)
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
284 if test -z "$url"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
285 then
286 # Only mention uninitialized submodules when its
287 # path have been specified
288 test "$#" != "0" &&
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
289 say "Submodule path '$path' not initialized"
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
290 continue
291 fi
292
293 if ! test -d "$path"/.git
294 then
295 module_clone "$path" "$url" || exit
bf2d824 @hjemli git-submodule: remember to checkout after clone
hjemli authored
296 subsha1=
297 else
5188408 @Tux Do not rely on the exit status of "unset" for unset variables
Tux authored
298 subsha1=$(unset GIT_DIR; cd "$path" &&
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
299 git rev-parse --verify HEAD) ||
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
300 die "Unable to find current revision in submodule path '$path'"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
301 fi
211b7f1 @hjemli git-submodule: clone during update, not during init
hjemli authored
302
70c7ac2 @hjemli Add git-submodule command
hjemli authored
303 if test "$subsha1" != "$sha1"
304 then
5188408 @Tux Do not rely on the exit status of "unset" for unset variables
Tux authored
305 (unset GIT_DIR; cd "$path" && git-fetch &&
70c7ac2 @hjemli Add git-submodule command
hjemli authored
306 git-checkout -q "$sha1") ||
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
307 die "Unable to checkout '$sha1' in submodule path '$path'"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
308
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
309 say "Submodule path '$path': checked out '$sha1'"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
310 fi
311 done
312 }
313
bffe71f git-submodule: Instead of using only annotated tags, use any tags.
Emil Medve authored
314 set_name_rev () {
315 revname=$( (
5188408 @Tux Do not rely on the exit status of "unset" for unset variables
Tux authored
316 unset GIT_DIR
bffe71f git-submodule: Instead of using only annotated tags, use any tags.
Emil Medve authored
317 cd "$1" && {
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
318 git describe "$2" 2>/dev/null ||
319 git describe --tags "$2" 2>/dev/null ||
320 git describe --contains --tags "$2"
bffe71f git-submodule: Instead of using only annotated tags, use any tags.
Emil Medve authored
321 }
322 ) )
323 test -z "$revname" || revname=" ($revname)"
324 }
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
325 #
326 # Show commit summary for submodules in index or working tree
327 #
328 # If '--cached' is given, show summary between index and given commit,
329 # or between working tree and given commit
330 #
331 # $@ = [commit (default 'HEAD'),] requested paths (default all)
332 #
333 cmd_summary() {
f2dc06a @pkufranky git-submodule summary: limit summary size
pkufranky authored
334 summary_limit=-1
335
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
336 # parse $args after "submodule ... summary".
337 while test $# -ne 0
338 do
339 case "$1" in
340 --cached)
341 cached="$1"
342 ;;
f2dc06a @pkufranky git-submodule summary: limit summary size
pkufranky authored
343 -n|--summary-limit)
344 if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
345 then
346 :
347 else
348 usage
349 fi
350 shift
351 ;;
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
352 --)
353 shift
354 break
355 ;;
356 -*)
357 usage
358 ;;
359 *)
360 break
361 ;;
362 esac
363 shift
364 done
bffe71f git-submodule: Instead of using only annotated tags, use any tags.
Emil Medve authored
365
f2dc06a @pkufranky git-submodule summary: limit summary size
pkufranky authored
366 test $summary_limit = 0 && return
367
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
368 if rev=$(git rev-parse --verify "$1^0" 2>/dev/null)
369 then
370 head=$rev
371 shift
372 else
373 head=HEAD
374 fi
375
376 cd_to_toplevel
377 # Get modified modules cared by user
378 modules=$(git diff-index $cached --raw $head -- "$@" |
379 grep -e '^:160000' -e '^:[0-7]* 160000' |
380 while read mod_src mod_dst sha1_src sha1_dst status name
381 do
382 # Always show modules deleted or type-changed (blob<->module)
383 test $status = D -o $status = T && echo "$name" && continue
384 # Also show added or modified modules which are checked out
385 GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
386 echo "$name"
387 done
388 )
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
389
390 test -n "$modules" &&
391 git diff-index $cached --raw $head -- $modules |
392 grep -e '^:160000' -e '^:[0-7]* 160000' |
393 cut -c2- |
394 while read mod_src mod_dst sha1_src sha1_dst status name
395 do
396 if test -z "$cached" &&
397 test $sha1_dst = 0000000000000000000000000000000000000000
398 then
399 case "$mod_dst" in
400 160000)
401 sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD)
402 ;;
403 100644 | 100755 | 120000)
404 sha1_dst=$(git hash-object $name)
405 ;;
406 000000)
407 ;; # removed
408 *)
409 # unexpected type
410 echo >&2 "unexpected mode $mod_dst"
411 continue ;;
412 esac
413 fi
414 missing_src=
415 missing_dst=
416
417 test $mod_src = 160000 &&
418 ! GIT_DIR="$name/.git" git-rev-parse --verify $sha1_src^0 >/dev/null 2>&1 &&
419 missing_src=t
420
421 test $mod_dst = 160000 &&
422 ! GIT_DIR="$name/.git" git-rev-parse --verify $sha1_dst^0 >/dev/null 2>&1 &&
423 missing_dst=t
424
425 total_commits=
426 case "$missing_src,$missing_dst" in
427 t,)
428 errmsg=" Warn: $name doesn't contain commit $sha1_src"
429 ;;
430 ,t)
431 errmsg=" Warn: $name doesn't contain commit $sha1_dst"
432 ;;
433 t,t)
434 errmsg=" Warn: $name doesn't contain commits $sha1_src and $sha1_dst"
435 ;;
436 *)
437 errmsg=
438 total_commits=$(
439 if test $mod_src = 160000 -a $mod_dst = 160000
440 then
441 range="$sha1_src...$sha1_dst"
442 elif test $mod_src = 160000
443 then
444 range=$sha1_src
445 else
446 range=$sha1_dst
447 fi
448 GIT_DIR="$name/.git" \
449 git log --pretty=oneline --first-parent $range | wc -l
450 )
eed3559 git-submodule summary: fix that some "wc" flavors produce leading spaces
Johannes Sixt authored
451 total_commits=" ($(($total_commits + 0)))"
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
452 ;;
453 esac
454
455 sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
456 sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
457 if test $status = T
458 then
459 if test $mod_dst = 160000
460 then
461 echo "* $name $sha1_abbr_src(blob)->$sha1_abbr_dst(submodule)$total_commits:"
462 else
463 echo "* $name $sha1_abbr_src(submodule)->$sha1_abbr_dst(blob)$total_commits:"
464 fi
465 else
466 echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
467 fi
468 if test -n "$errmsg"
469 then
470 # Don't give error msg for modification whose dst is not submodule
471 # i.e. deleted or changed to blob
472 test $mod_dst = 160000 && echo "$errmsg"
473 else
474 if test $mod_src = 160000 -a $mod_dst = 160000
475 then
f2dc06a @pkufranky git-submodule summary: limit summary size
pkufranky authored
476 limit=
477 test $summary_limit -gt 0 && limit="-$summary_limit"
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
478 GIT_DIR="$name/.git" \
f2dc06a @pkufranky git-submodule summary: limit summary size
pkufranky authored
479 git log $limit --pretty='format: %m %s' \
1cb639e @pkufranky git-submodule summary: show commit summary
pkufranky authored
480 --first-parent $sha1_src...$sha1_dst
481 elif test $mod_dst = 160000
482 then
483 GIT_DIR="$name/.git" \
484 git log --pretty='format: > %s' -1 $sha1_dst
485 else
486 GIT_DIR="$name/.git" \
487 git log --pretty='format: < %s' -1 $sha1_src
488 fi
489 echo
490 fi
491 echo
492 done
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
493 }
70c7ac2 @hjemli Add git-submodule command
hjemli authored
494 #
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
495 # List all submodules, prefixed with:
70c7ac2 @hjemli Add git-submodule command
hjemli authored
496 # - submodule not initialized
497 # + different revision checked out
498 #
499 # If --cached was specified the revision in the index will be printed
500 # instead of the currently checked out revision.
501 #
502 # $@ = requested paths (default to all)
503 #
23a485e @gitster git-submodule: rename shell functions for consistency
gitster authored
504 cmd_status()
70c7ac2 @hjemli Add git-submodule command
hjemli authored
505 {
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
506 # parse $args after "submodule ... status".
507 while test $# -ne 0
508 do
509 case "$1" in
510 -q|--quiet)
511 quiet=1
512 ;;
513 --cached)
514 cached=1
515 ;;
516 --)
517 shift
518 break
519 ;;
520 -*)
521 usage
522 ;;
523 *)
524 break
525 ;;
526 esac
527 shift
528 done
529
70c7ac2 @hjemli Add git-submodule command
hjemli authored
530 git ls-files --stage -- "$@" | grep -e '^160000 ' |
531 while read mode sha1 stage path
532 do
941987a @hjemli git-submodule: give submodules proper names
hjemli authored
533 name=$(module_name "$path") || exit
5be6007 @gitster Rewrite "git-frotz" to "git frotz"
gitster authored
534 url=$(git config submodule."$name".url)
fcbcfe7 @pkufranky git-submodule: Fix typo 'url' which should be '$url'
pkufranky authored
535 if test -z "$url" || ! test -d "$path"/.git
70c7ac2 @hjemli Add git-submodule command
hjemli authored
536 then
537 say "-$sha1 $path"
538 continue;
539 fi
41c7c1b @neurocyte git-submodule: Fix two instances of the same typo
neurocyte authored
540 set_name_rev "$path" "$sha1"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
541 if git diff-files --quiet -- "$path"
542 then
bffe71f git-submodule: Instead of using only annotated tags, use any tags.
Emil Medve authored
543 say " $sha1 $path$revname"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
544 else
545 if test -z "$cached"
546 then
5188408 @Tux Do not rely on the exit status of "unset" for unset variables
Tux authored
547 sha1=$(unset GIT_DIR; cd "$path" && git rev-parse --verify HEAD)
41c7c1b @neurocyte git-submodule: Fix two instances of the same typo
neurocyte authored
548 set_name_rev "$path" "$sha1"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
549 fi
bffe71f git-submodule: Instead of using only annotated tags, use any tags.
Emil Medve authored
550 say "+$sha1 $path$revname"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
551 fi
552 done
553 }
554
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
555 # This loop parses the command line arguments to find the
556 # subcommand name to dispatch. Parsing of the subcommand specific
557 # options are primarily done by the subcommand implementations.
558 # Subcommand specific options such as --branch and --cached are
559 # parsed here as well, for backward compatibility.
560
561 while test $# != 0 && test -z "$command"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
562 do
563 case "$1" in
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
564 add | init | update | status | summary)
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
565 command=$1
70c7ac2 @hjemli Add git-submodule command
hjemli authored
566 ;;
567 -q|--quiet)
568 quiet=1
569 ;;
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
570 -b|--branch)
571 case "$2" in
572 '')
573 usage
574 ;;
575 esac
576 branch="$2"; shift
577 ;;
70c7ac2 @hjemli Add git-submodule command
hjemli authored
578 --cached)
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
579 cached="$1"
70c7ac2 @hjemli Add git-submodule command
hjemli authored
580 ;;
581 --)
582 break
583 ;;
584 -*)
585 usage
586 ;;
587 *)
588 break
589 ;;
590 esac
591 shift
592 done
593
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
594 # No command word defaults to "status"
595 test -n "$command" || command=status
596
597 # "-b branch" is accepted only by "add"
598 if test -n "$branch" && test "$command" != add
599 then
ecda072 git-submodule: provide easy way of adding new submodules
Sven Verdoolaege authored
600 usage
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
601 fi
602
28f9af5 @pkufranky git-submodule summary: code framework
pkufranky authored
603 # "--cached" is accepted only by "status" and "summary"
604 if test -n "$cached" && test "$command" != status -a "$command" != summary
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
605 then
70c7ac2 @hjemli Add git-submodule command
hjemli authored
606 usage
5c08dbb @gitster git-submodule: fix subcommand parser
gitster authored
607 fi
608
609 "cmd_$command" "$@"
Something went wrong with that request. Please try again.