PageRenderTime 71ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/git/git-submodule.sh

https://review.tizen.org/git/
Shell | 906 lines | 737 code | 62 blank | 107 comment | 88 complexity | 407bfafd8779d288f6ba27fe63a08f3a MD5 | raw file
Possible License(s): GPL-3.0, AGPL-3.0, GPL-2.0, MPL-2.0, JSON, WTFPL, CC-BY-SA-4.0, CC-BY-3.0, BSD-3-Clause, LGPL-2.0, MPL-2.0-no-copyleft-exception, AGPL-1.0, 0BSD, Zlib, Unlicense, BSD-2-Clause, Apache-2.0, LGPL-3.0, ISC, MIT, CC-BY-SA-3.0, CC0-1.0, LGPL-2.1
  1. #!/bin/sh
  2. #
  3. # git-submodules.sh: add, init, update or list git submodules
  4. #
  5. # Copyright (c) 2007 Lars Hjemli
  6. dashless=$(basename "$0" | sed -e 's/-/ /')
  7. USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
  8. or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
  9. or: $dashless [--quiet] init [--] [<path>...]
  10. or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
  11. or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
  12. or: $dashless [--quiet] foreach [--recursive] <command>
  13. or: $dashless [--quiet] sync [--] [<path>...]"
  14. OPTIONS_SPEC=
  15. . git-sh-setup
  16. . git-parse-remote
  17. require_work_tree
  18. command=
  19. branch=
  20. force=
  21. reference=
  22. cached=
  23. recursive=
  24. init=
  25. files=
  26. nofetch=
  27. update=
  28. prefix=
  29. # Resolve relative url by appending to parent's url
  30. resolve_relative_url ()
  31. {
  32. remote=$(get_default_remote)
  33. remoteurl=$(git config "remote.$remote.url") ||
  34. die "remote ($remote) does not have a url defined in .git/config"
  35. url="$1"
  36. remoteurl=${remoteurl%/}
  37. while test -n "$url"
  38. do
  39. case "$url" in
  40. ../*)
  41. url="${url#../}"
  42. remoteurl="${remoteurl%/*}"
  43. ;;
  44. ./*)
  45. url="${url#./}"
  46. ;;
  47. *)
  48. break;;
  49. esac
  50. done
  51. echo "$remoteurl/${url%/}"
  52. }
  53. #
  54. # Get submodule info for registered submodules
  55. # $@ = path to limit submodule list
  56. #
  57. module_list()
  58. {
  59. git ls-files --error-unmatch --stage -- "$@" | sane_grep '^160000 '
  60. }
  61. #
  62. # Map submodule path to submodule name
  63. #
  64. # $1 = path
  65. #
  66. module_name()
  67. {
  68. # Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
  69. re=$(printf '%s\n' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
  70. name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
  71. sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
  72. test -z "$name" &&
  73. die "No submodule mapping found in .gitmodules for path '$path'"
  74. echo "$name"
  75. }
  76. #
  77. # Clone a submodule
  78. #
  79. # Prior to calling, cmd_update checks that a possibly existing
  80. # path is not a git repository.
  81. # Likewise, cmd_add checks that path does not exist at all,
  82. # since it is the location of a new submodule.
  83. #
  84. module_clone()
  85. {
  86. path=$1
  87. url=$2
  88. reference="$3"
  89. # If there already is a directory at the submodule path,
  90. # expect it to be empty (since that is the default checkout
  91. # action) and try to remove it.
  92. # Note: if $path is a symlink to a directory the test will
  93. # succeed but the rmdir will fail. We might want to fix this.
  94. if test -d "$path"
  95. then
  96. rmdir "$path" 2>/dev/null ||
  97. die "Directory '$path' exists, but is neither empty nor a git repository"
  98. fi
  99. test -e "$path" &&
  100. die "A file already exist at path '$path'"
  101. if test -n "$reference"
  102. then
  103. git-clone "$reference" -n "$url" "$path"
  104. else
  105. git-clone -n "$url" "$path"
  106. fi ||
  107. die "Clone of '$url' into submodule path '$path' failed"
  108. }
  109. #
  110. # Add a new submodule to the working tree, .gitmodules and the index
  111. #
  112. # $@ = repo path
  113. #
  114. # optional branch is stored in global branch variable
  115. #
  116. cmd_add()
  117. {
  118. # parse $args after "submodule ... add".
  119. while test $# -ne 0
  120. do
  121. case "$1" in
  122. -b | --branch)
  123. case "$2" in '') usage ;; esac
  124. branch=$2
  125. shift
  126. ;;
  127. -f | --force)
  128. force=$1
  129. ;;
  130. -q|--quiet)
  131. GIT_QUIET=1
  132. ;;
  133. --reference)
  134. case "$2" in '') usage ;; esac
  135. reference="--reference=$2"
  136. shift
  137. ;;
  138. --reference=*)
  139. reference="$1"
  140. shift
  141. ;;
  142. --)
  143. shift
  144. break
  145. ;;
  146. -*)
  147. usage
  148. ;;
  149. *)
  150. break
  151. ;;
  152. esac
  153. shift
  154. done
  155. repo=$1
  156. path=$2
  157. if test -z "$path"; then
  158. path=$(echo "$repo" |
  159. sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
  160. fi
  161. if test -z "$repo" -o -z "$path"; then
  162. usage
  163. fi
  164. # assure repo is absolute or relative to parent
  165. case "$repo" in
  166. ./*|../*)
  167. # dereference source url relative to parent's url
  168. realrepo=$(resolve_relative_url "$repo") || exit
  169. ;;
  170. *:*|/*)
  171. # absolute url
  172. realrepo=$repo
  173. ;;
  174. *)
  175. die "repo URL: '$repo' must be absolute or begin with ./|../"
  176. ;;
  177. esac
  178. # normalize path:
  179. # multiple //; leading ./; /./; /../; trailing /
  180. path=$(printf '%s/\n' "$path" |
  181. sed -e '
  182. s|//*|/|g
  183. s|^\(\./\)*||
  184. s|/\./|/|g
  185. :start
  186. s|\([^/]*\)/\.\./||
  187. tstart
  188. s|/*$||
  189. ')
  190. git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
  191. die "'$path' already exists in the index"
  192. if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
  193. then
  194. echo >&2 "The following path is ignored by one of your .gitignore files:" &&
  195. echo >&2 $path &&
  196. echo >&2 "Use -f if you really want to add it."
  197. exit 1
  198. fi
  199. # perhaps the path exists and is already a git repo, else clone it
  200. if test -e "$path"
  201. then
  202. if test -d "$path"/.git -o -f "$path"/.git
  203. then
  204. echo "Adding existing repo at '$path' to the index"
  205. else
  206. die "'$path' already exists and is not a valid git repo"
  207. fi
  208. case "$repo" in
  209. ./*|../*)
  210. url=$(resolve_relative_url "$repo") || exit
  211. ;;
  212. *)
  213. url="$repo"
  214. ;;
  215. esac
  216. git config submodule."$path".url "$url"
  217. else
  218. module_clone "$path" "$realrepo" "$reference" || exit
  219. (
  220. clear_local_git_env
  221. cd "$path" &&
  222. # ash fails to wordsplit ${branch:+-b "$branch"...}
  223. case "$branch" in
  224. '') git checkout -f -q ;;
  225. ?*) git checkout -f -q -b "$branch" "origin/$branch" ;;
  226. esac
  227. ) || die "Unable to checkout submodule '$path'"
  228. fi
  229. git add $force "$path" ||
  230. die "Failed to add submodule '$path'"
  231. git config -f .gitmodules submodule."$path".path "$path" &&
  232. git config -f .gitmodules submodule."$path".url "$repo" &&
  233. git add --force .gitmodules ||
  234. die "Failed to register submodule '$path'"
  235. }
  236. #
  237. # Execute an arbitrary command sequence in each checked out
  238. # submodule
  239. #
  240. # $@ = command to execute
  241. #
  242. cmd_foreach()
  243. {
  244. # parse $args after "submodule ... foreach".
  245. while test $# -ne 0
  246. do
  247. case "$1" in
  248. -q|--quiet)
  249. GIT_QUIET=1
  250. ;;
  251. --recursive)
  252. recursive=1
  253. ;;
  254. -*)
  255. usage
  256. ;;
  257. *)
  258. break
  259. ;;
  260. esac
  261. shift
  262. done
  263. toplevel=$(pwd)
  264. module_list |
  265. while read mode sha1 stage path
  266. do
  267. if test -e "$path"/.git
  268. then
  269. say "Entering '$prefix$path'"
  270. name=$(module_name "$path")
  271. (
  272. prefix="$prefix$path/"
  273. clear_local_git_env
  274. cd "$path" &&
  275. eval "$@" &&
  276. if test -n "$recursive"
  277. then
  278. cmd_foreach "--recursive" "$@"
  279. fi
  280. ) ||
  281. die "Stopping at '$path'; script returned non-zero status."
  282. fi
  283. done
  284. }
  285. #
  286. # Register submodules in .git/config
  287. #
  288. # $@ = requested paths (default to all)
  289. #
  290. cmd_init()
  291. {
  292. # parse $args after "submodule ... init".
  293. while test $# -ne 0
  294. do
  295. case "$1" in
  296. -q|--quiet)
  297. GIT_QUIET=1
  298. ;;
  299. --)
  300. shift
  301. break
  302. ;;
  303. -*)
  304. usage
  305. ;;
  306. *)
  307. break
  308. ;;
  309. esac
  310. shift
  311. done
  312. module_list "$@" |
  313. while read mode sha1 stage path
  314. do
  315. # Skip already registered paths
  316. name=$(module_name "$path") || exit
  317. url=$(git config submodule."$name".url)
  318. test -z "$url" || continue
  319. url=$(git config -f .gitmodules submodule."$name".url)
  320. test -z "$url" &&
  321. die "No url found for submodule path '$path' in .gitmodules"
  322. # Possibly a url relative to parent
  323. case "$url" in
  324. ./*|../*)
  325. url=$(resolve_relative_url "$url") || exit
  326. ;;
  327. esac
  328. git config submodule."$name".url "$url" ||
  329. die "Failed to register url for submodule path '$path'"
  330. upd="$(git config -f .gitmodules submodule."$name".update)"
  331. test -z "$upd" ||
  332. git config submodule."$name".update "$upd" ||
  333. die "Failed to register update mode for submodule path '$path'"
  334. say "Submodule '$name' ($url) registered for path '$path'"
  335. done
  336. }
  337. #
  338. # Update each submodule path to correct revision, using clone and checkout as needed
  339. #
  340. # $@ = requested paths (default to all)
  341. #
  342. cmd_update()
  343. {
  344. # parse $args after "submodule ... update".
  345. orig_args="$@"
  346. while test $# -ne 0
  347. do
  348. case "$1" in
  349. -q|--quiet)
  350. shift
  351. GIT_QUIET=1
  352. ;;
  353. -i|--init)
  354. init=1
  355. shift
  356. ;;
  357. -N|--no-fetch)
  358. shift
  359. nofetch=1
  360. ;;
  361. -r|--rebase)
  362. shift
  363. update="rebase"
  364. ;;
  365. --reference)
  366. case "$2" in '') usage ;; esac
  367. reference="--reference=$2"
  368. shift 2
  369. ;;
  370. --reference=*)
  371. reference="$1"
  372. shift
  373. ;;
  374. -m|--merge)
  375. shift
  376. update="merge"
  377. ;;
  378. --recursive)
  379. shift
  380. recursive=1
  381. ;;
  382. --)
  383. shift
  384. break
  385. ;;
  386. -*)
  387. usage
  388. ;;
  389. *)
  390. break
  391. ;;
  392. esac
  393. done
  394. if test -n "$init"
  395. then
  396. cmd_init "--" "$@" || return
  397. fi
  398. module_list "$@" |
  399. while read mode sha1 stage path
  400. do
  401. name=$(module_name "$path") || exit
  402. url=$(git config submodule."$name".url)
  403. update_module=$(git config submodule."$name".update)
  404. if test -z "$url"
  405. then
  406. # Only mention uninitialized submodules when its
  407. # path have been specified
  408. test "$#" != "0" &&
  409. say "Submodule path '$path' not initialized" &&
  410. say "Maybe you want to use 'update --init'?"
  411. continue
  412. fi
  413. if ! test -d "$path"/.git -o -f "$path"/.git
  414. then
  415. module_clone "$path" "$url" "$reference"|| exit
  416. subsha1=
  417. else
  418. subsha1=$(clear_local_git_env; cd "$path" &&
  419. git rev-parse --verify HEAD) ||
  420. die "Unable to find current revision in submodule path '$path'"
  421. fi
  422. if ! test -z "$update"
  423. then
  424. update_module=$update
  425. fi
  426. if test "$subsha1" != "$sha1"
  427. then
  428. force=
  429. if test -z "$subsha1"
  430. then
  431. force="-f"
  432. fi
  433. if test -z "$nofetch"
  434. then
  435. (clear_local_git_env; cd "$path" &&
  436. git-fetch) ||
  437. die "Unable to fetch in submodule path '$path'"
  438. fi
  439. case "$update_module" in
  440. rebase)
  441. command="git rebase"
  442. action="rebase"
  443. msg="rebased onto"
  444. ;;
  445. merge)
  446. command="git merge"
  447. action="merge"
  448. msg="merged in"
  449. ;;
  450. *)
  451. command="git checkout $force -q"
  452. action="checkout"
  453. msg="checked out"
  454. ;;
  455. esac
  456. (clear_local_git_env; cd "$path" && $command "$sha1") ||
  457. die "Unable to $action '$sha1' in submodule path '$path'"
  458. say "Submodule path '$path': $msg '$sha1'"
  459. fi
  460. if test -n "$recursive"
  461. then
  462. (clear_local_git_env; cd "$path" && cmd_update $orig_args) ||
  463. die "Failed to recurse into submodule path '$path'"
  464. fi
  465. done
  466. }
  467. set_name_rev () {
  468. revname=$( (
  469. clear_local_git_env
  470. cd "$1" && {
  471. git describe "$2" 2>/dev/null ||
  472. git describe --tags "$2" 2>/dev/null ||
  473. git describe --contains "$2" 2>/dev/null ||
  474. git describe --all --always "$2"
  475. }
  476. ) )
  477. test -z "$revname" || revname=" ($revname)"
  478. }
  479. #
  480. # Show commit summary for submodules in index or working tree
  481. #
  482. # If '--cached' is given, show summary between index and given commit,
  483. # or between working tree and given commit
  484. #
  485. # $@ = [commit (default 'HEAD'),] requested paths (default all)
  486. #
  487. cmd_summary() {
  488. summary_limit=-1
  489. for_status=
  490. diff_cmd=diff-index
  491. # parse $args after "submodule ... summary".
  492. while test $# -ne 0
  493. do
  494. case "$1" in
  495. --cached)
  496. cached="$1"
  497. ;;
  498. --files)
  499. files="$1"
  500. ;;
  501. --for-status)
  502. for_status="$1"
  503. ;;
  504. -n|--summary-limit)
  505. if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
  506. then
  507. :
  508. else
  509. usage
  510. fi
  511. shift
  512. ;;
  513. --)
  514. shift
  515. break
  516. ;;
  517. -*)
  518. usage
  519. ;;
  520. *)
  521. break
  522. ;;
  523. esac
  524. shift
  525. done
  526. test $summary_limit = 0 && return
  527. if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"})
  528. then
  529. head=$rev
  530. test $# = 0 || shift
  531. elif test -z "$1" -o "$1" = "HEAD"
  532. then
  533. # before the first commit: compare with an empty tree
  534. head=$(git hash-object -w -t tree --stdin </dev/null)
  535. test -z "$1" || shift
  536. else
  537. head="HEAD"
  538. fi
  539. if [ -n "$files" ]
  540. then
  541. test -n "$cached" &&
  542. die "--cached cannot be used with --files"
  543. diff_cmd=diff-files
  544. head=
  545. fi
  546. cd_to_toplevel
  547. # Get modified modules cared by user
  548. modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" |
  549. sane_egrep '^:([0-7]* )?160000' |
  550. while read mod_src mod_dst sha1_src sha1_dst status name
  551. do
  552. # Always show modules deleted or type-changed (blob<->module)
  553. test $status = D -o $status = T && echo "$name" && continue
  554. # Also show added or modified modules which are checked out
  555. GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
  556. echo "$name"
  557. done
  558. )
  559. test -z "$modules" && return
  560. git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules |
  561. sane_egrep '^:([0-7]* )?160000' |
  562. cut -c2- |
  563. while read mod_src mod_dst sha1_src sha1_dst status name
  564. do
  565. if test -z "$cached" &&
  566. test $sha1_dst = 0000000000000000000000000000000000000000
  567. then
  568. case "$mod_dst" in
  569. 160000)
  570. sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD)
  571. ;;
  572. 100644 | 100755 | 120000)
  573. sha1_dst=$(git hash-object $name)
  574. ;;
  575. 000000)
  576. ;; # removed
  577. *)
  578. # unexpected type
  579. echo >&2 "unexpected mode $mod_dst"
  580. continue ;;
  581. esac
  582. fi
  583. missing_src=
  584. missing_dst=
  585. test $mod_src = 160000 &&
  586. ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_src^0 >/dev/null &&
  587. missing_src=t
  588. test $mod_dst = 160000 &&
  589. ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null &&
  590. missing_dst=t
  591. total_commits=
  592. case "$missing_src,$missing_dst" in
  593. t,)
  594. errmsg=" Warn: $name doesn't contain commit $sha1_src"
  595. ;;
  596. ,t)
  597. errmsg=" Warn: $name doesn't contain commit $sha1_dst"
  598. ;;
  599. t,t)
  600. errmsg=" Warn: $name doesn't contain commits $sha1_src and $sha1_dst"
  601. ;;
  602. *)
  603. errmsg=
  604. total_commits=$(
  605. if test $mod_src = 160000 -a $mod_dst = 160000
  606. then
  607. range="$sha1_src...$sha1_dst"
  608. elif test $mod_src = 160000
  609. then
  610. range=$sha1_src
  611. else
  612. range=$sha1_dst
  613. fi
  614. GIT_DIR="$name/.git" \
  615. git rev-list --first-parent $range -- | wc -l
  616. )
  617. total_commits=" ($(($total_commits + 0)))"
  618. ;;
  619. esac
  620. sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
  621. sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
  622. if test $status = T
  623. then
  624. if test $mod_dst = 160000
  625. then
  626. echo "* $name $sha1_abbr_src(blob)->$sha1_abbr_dst(submodule)$total_commits:"
  627. else
  628. echo "* $name $sha1_abbr_src(submodule)->$sha1_abbr_dst(blob)$total_commits:"
  629. fi
  630. else
  631. echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
  632. fi
  633. if test -n "$errmsg"
  634. then
  635. # Don't give error msg for modification whose dst is not submodule
  636. # i.e. deleted or changed to blob
  637. test $mod_dst = 160000 && echo "$errmsg"
  638. else
  639. if test $mod_src = 160000 -a $mod_dst = 160000
  640. then
  641. limit=
  642. test $summary_limit -gt 0 && limit="-$summary_limit"
  643. GIT_DIR="$name/.git" \
  644. git log $limit --pretty='format: %m %s' \
  645. --first-parent $sha1_src...$sha1_dst
  646. elif test $mod_dst = 160000
  647. then
  648. GIT_DIR="$name/.git" \
  649. git log --pretty='format: > %s' -1 $sha1_dst
  650. else
  651. GIT_DIR="$name/.git" \
  652. git log --pretty='format: < %s' -1 $sha1_src
  653. fi
  654. echo
  655. fi
  656. echo
  657. done |
  658. if test -n "$for_status"; then
  659. if [ -n "$files" ]; then
  660. echo "# Submodules changed but not updated:"
  661. else
  662. echo "# Submodule changes to be committed:"
  663. fi
  664. echo "#"
  665. sed -e 's|^|# |' -e 's|^# $|#|'
  666. else
  667. cat
  668. fi
  669. }
  670. #
  671. # List all submodules, prefixed with:
  672. # - submodule not initialized
  673. # + different revision checked out
  674. #
  675. # If --cached was specified the revision in the index will be printed
  676. # instead of the currently checked out revision.
  677. #
  678. # $@ = requested paths (default to all)
  679. #
  680. cmd_status()
  681. {
  682. # parse $args after "submodule ... status".
  683. orig_args="$@"
  684. while test $# -ne 0
  685. do
  686. case "$1" in
  687. -q|--quiet)
  688. GIT_QUIET=1
  689. ;;
  690. --cached)
  691. cached=1
  692. ;;
  693. --recursive)
  694. recursive=1
  695. ;;
  696. --)
  697. shift
  698. break
  699. ;;
  700. -*)
  701. usage
  702. ;;
  703. *)
  704. break
  705. ;;
  706. esac
  707. shift
  708. done
  709. module_list "$@" |
  710. while read mode sha1 stage path
  711. do
  712. name=$(module_name "$path") || exit
  713. url=$(git config submodule."$name".url)
  714. displaypath="$prefix$path"
  715. if test -z "$url" || ! test -d "$path"/.git -o -f "$path"/.git
  716. then
  717. say "-$sha1 $displaypath"
  718. continue;
  719. fi
  720. set_name_rev "$path" "$sha1"
  721. if git diff-files --ignore-submodules=dirty --quiet -- "$path"
  722. then
  723. say " $sha1 $displaypath$revname"
  724. else
  725. if test -z "$cached"
  726. then
  727. sha1=$(clear_local_git_env; cd "$path" && git rev-parse --verify HEAD)
  728. set_name_rev "$path" "$sha1"
  729. fi
  730. say "+$sha1 $displaypath$revname"
  731. fi
  732. if test -n "$recursive"
  733. then
  734. (
  735. prefix="$displaypath/"
  736. clear_local_git_env
  737. cd "$path" &&
  738. cmd_status $orig_args
  739. ) ||
  740. die "Failed to recurse into submodule path '$path'"
  741. fi
  742. done
  743. }
  744. #
  745. # Sync remote urls for submodules
  746. # This makes the value for remote.$remote.url match the value
  747. # specified in .gitmodules.
  748. #
  749. cmd_sync()
  750. {
  751. while test $# -ne 0
  752. do
  753. case "$1" in
  754. -q|--quiet)
  755. GIT_QUIET=1
  756. shift
  757. ;;
  758. --)
  759. shift
  760. break
  761. ;;
  762. -*)
  763. usage
  764. ;;
  765. *)
  766. break
  767. ;;
  768. esac
  769. done
  770. cd_to_toplevel
  771. module_list "$@" |
  772. while read mode sha1 stage path
  773. do
  774. name=$(module_name "$path")
  775. url=$(git config -f .gitmodules --get submodule."$name".url)
  776. # Possibly a url relative to parent
  777. case "$url" in
  778. ./*|../*)
  779. url=$(resolve_relative_url "$url") || exit
  780. ;;
  781. esac
  782. if test -e "$path"/.git
  783. then
  784. (
  785. clear_local_git_env
  786. cd "$path"
  787. remote=$(get_default_remote)
  788. say "Synchronizing submodule url for '$name'"
  789. git config remote."$remote".url "$url"
  790. )
  791. fi
  792. done
  793. }
  794. # This loop parses the command line arguments to find the
  795. # subcommand name to dispatch. Parsing of the subcommand specific
  796. # options are primarily done by the subcommand implementations.
  797. # Subcommand specific options such as --branch and --cached are
  798. # parsed here as well, for backward compatibility.
  799. while test $# != 0 && test -z "$command"
  800. do
  801. case "$1" in
  802. add | foreach | init | update | status | summary | sync)
  803. command=$1
  804. ;;
  805. -q|--quiet)
  806. GIT_QUIET=1
  807. ;;
  808. -b|--branch)
  809. case "$2" in
  810. '')
  811. usage
  812. ;;
  813. esac
  814. branch="$2"; shift
  815. ;;
  816. --cached)
  817. cached="$1"
  818. ;;
  819. --)
  820. break
  821. ;;
  822. -*)
  823. usage
  824. ;;
  825. *)
  826. break
  827. ;;
  828. esac
  829. shift
  830. done
  831. # No command word defaults to "status"
  832. test -n "$command" || command=status
  833. # "-b branch" is accepted only by "add"
  834. if test -n "$branch" && test "$command" != add
  835. then
  836. usage
  837. fi
  838. # "--cached" is accepted only by "status" and "summary"
  839. if test -n "$cached" && test "$command" != status -a "$command" != summary
  840. then
  841. usage
  842. fi
  843. "cmd_$command" "$@"