logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

git-submodule (10493B)


  1. #!/bin/sh
  2. #
  3. # git-submodule.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] [--cached]
  8. or: $dashless [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
  9. or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
  10. or: $dashless [--quiet] init [--] [<path>...]
  11. or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
  12. or: $dashless [--quiet] update [--init [--filter=<filter-spec>]] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--[no-]single-branch] [--] [<path>...]
  13. or: $dashless [--quiet] set-branch (--default|--branch <branch>) [--] <path>
  14. or: $dashless [--quiet] set-url [--] <path> <newurl>
  15. or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
  16. or: $dashless [--quiet] foreach [--recursive] <command>
  17. or: $dashless [--quiet] sync [--recursive] [--] [<path>...]
  18. or: $dashless [--quiet] absorbgitdirs [--] [<path>...]"
  19. OPTIONS_SPEC=
  20. SUBDIRECTORY_OK=Yes
  21. . git-sh-setup
  22. require_work_tree
  23. wt_prefix=$(git rev-parse --show-prefix)
  24. cd_to_toplevel
  25. # Tell the rest of git that any URLs we get don't come
  26. # directly from the user, so it can apply policy as appropriate.
  27. GIT_PROTOCOL_FROM_USER=0
  28. export GIT_PROTOCOL_FROM_USER
  29. command=
  30. quiet=
  31. branch=
  32. force=
  33. reference=
  34. cached=
  35. recursive=
  36. init=
  37. require_init=
  38. files=
  39. remote=
  40. no_fetch=
  41. rebase=
  42. merge=
  43. checkout=
  44. name=
  45. depth=
  46. progress=
  47. dissociate=
  48. single_branch=
  49. jobs=
  50. recommend_shallow=
  51. filter=
  52. all=
  53. default=
  54. summary_limit=
  55. for_status=
  56. #
  57. # Add a new submodule to the working tree, .gitmodules and the index
  58. #
  59. # $@ = repo path
  60. #
  61. # optional branch is stored in global branch variable
  62. #
  63. cmd_add()
  64. {
  65. # parse $args after "submodule ... add".
  66. while test $# -ne 0
  67. do
  68. case "$1" in
  69. -b | --branch)
  70. case "$2" in '') usage ;; esac
  71. branch="--branch=$2"
  72. shift
  73. ;;
  74. -b* | --branch=*)
  75. branch="$1"
  76. ;;
  77. -f | --force)
  78. force=$1
  79. ;;
  80. -q|--quiet)
  81. quiet=$1
  82. ;;
  83. --progress)
  84. progress=$1
  85. ;;
  86. --reference)
  87. case "$2" in '') usage ;; esac
  88. reference="--reference=$2"
  89. shift
  90. ;;
  91. --reference=*)
  92. reference="$1"
  93. ;;
  94. --ref-format)
  95. case "$2" in '') usage ;; esac
  96. ref_format="--ref-format=$2"
  97. shift
  98. ;;
  99. --ref-format=*)
  100. ref_format="$1"
  101. ;;
  102. --dissociate)
  103. dissociate=$1
  104. ;;
  105. --name)
  106. case "$2" in '') usage ;; esac
  107. name="--name=$2"
  108. shift
  109. ;;
  110. --name=*)
  111. name="$1"
  112. ;;
  113. --depth)
  114. case "$2" in '') usage ;; esac
  115. depth="--depth=$2"
  116. shift
  117. ;;
  118. --depth=*)
  119. depth="$1"
  120. ;;
  121. --)
  122. shift
  123. break
  124. ;;
  125. -*)
  126. usage
  127. ;;
  128. *)
  129. break
  130. ;;
  131. esac
  132. shift
  133. done
  134. if test -z "$1"
  135. then
  136. usage
  137. fi
  138. git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add \
  139. $quiet \
  140. $force \
  141. $progress \
  142. ${branch:+"$branch"} \
  143. ${reference:+"$reference"} \
  144. ${ref_format:+"$ref_format"} \
  145. $dissociate \
  146. ${name:+"$name"} \
  147. ${depth:+"$depth"} \
  148. -- \
  149. "$@"
  150. }
  151. #
  152. # Execute an arbitrary command sequence in each checked out
  153. # submodule
  154. #
  155. # $@ = command to execute
  156. #
  157. cmd_foreach()
  158. {
  159. # parse $args after "submodule ... foreach".
  160. while test $# -ne 0
  161. do
  162. case "$1" in
  163. -q|--quiet)
  164. quiet=$1
  165. ;;
  166. --recursive)
  167. recursive=$1
  168. ;;
  169. -*)
  170. usage
  171. ;;
  172. *)
  173. break
  174. ;;
  175. esac
  176. shift
  177. done
  178. git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach \
  179. $quiet \
  180. $recursive \
  181. -- \
  182. "$@"
  183. }
  184. #
  185. # Register submodules in .git/config
  186. #
  187. # $@ = requested paths (default to all)
  188. #
  189. cmd_init()
  190. {
  191. # parse $args after "submodule ... init".
  192. while test $# -ne 0
  193. do
  194. case "$1" in
  195. -q|--quiet)
  196. quiet=$1
  197. ;;
  198. --)
  199. shift
  200. break
  201. ;;
  202. -*)
  203. usage
  204. ;;
  205. *)
  206. break
  207. ;;
  208. esac
  209. shift
  210. done
  211. git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init \
  212. $quiet \
  213. -- \
  214. "$@"
  215. }
  216. #
  217. # Unregister submodules from .git/config and remove their work tree
  218. #
  219. cmd_deinit()
  220. {
  221. # parse $args after "submodule ... deinit".
  222. while test $# -ne 0
  223. do
  224. case "$1" in
  225. -f|--force)
  226. force=$1
  227. ;;
  228. -q|--quiet)
  229. quiet=$1
  230. ;;
  231. --all)
  232. all=$1
  233. ;;
  234. --)
  235. shift
  236. break
  237. ;;
  238. -*)
  239. usage
  240. ;;
  241. *)
  242. break
  243. ;;
  244. esac
  245. shift
  246. done
  247. git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit \
  248. $quiet \
  249. $force \
  250. $all \
  251. -- \
  252. "$@"
  253. }
  254. #
  255. # Update each submodule path to correct revision, using clone and checkout as needed
  256. #
  257. # $@ = requested paths (default to all)
  258. #
  259. cmd_update()
  260. {
  261. # parse $args after "submodule ... update".
  262. while test $# -ne 0
  263. do
  264. case "$1" in
  265. -q|--quiet)
  266. quiet=$1
  267. ;;
  268. -v|--verbose)
  269. quiet=
  270. ;;
  271. --progress)
  272. progress=$1
  273. ;;
  274. -i|--init)
  275. init=$1
  276. ;;
  277. --require-init)
  278. require_init=$1
  279. ;;
  280. --remote)
  281. remote=$1
  282. ;;
  283. -N|--no-fetch)
  284. no_fetch=$1
  285. ;;
  286. -f|--force)
  287. force=$1
  288. ;;
  289. -r|--rebase)
  290. rebase=$1
  291. ;;
  292. --ref-format)
  293. case "$2" in '') usage ;; esac
  294. ref_format="--ref-format=$2"
  295. shift
  296. ;;
  297. --ref-format=*)
  298. ref_format="$1"
  299. ;;
  300. --reference)
  301. case "$2" in '') usage ;; esac
  302. reference="--reference=$2"
  303. shift
  304. ;;
  305. --reference=*)
  306. reference="$1"
  307. ;;
  308. --dissociate)
  309. dissociate=$1
  310. ;;
  311. -m|--merge)
  312. merge=$1
  313. ;;
  314. --recursive)
  315. recursive=$1
  316. ;;
  317. --checkout)
  318. checkout=$1
  319. ;;
  320. --recommend-shallow|--no-recommend-shallow)
  321. recommend_shallow=$1
  322. ;;
  323. --depth)
  324. case "$2" in '') usage ;; esac
  325. depth="--depth=$2"
  326. shift
  327. ;;
  328. --depth=*)
  329. depth="$1"
  330. ;;
  331. -j|--jobs)
  332. case "$2" in '') usage ;; esac
  333. jobs="--jobs=$2"
  334. shift
  335. ;;
  336. -j*|--jobs=*)
  337. jobs="$1"
  338. ;;
  339. --single-branch|--no-single-branch)
  340. single_branch=$1
  341. ;;
  342. --filter)
  343. case "$2" in '') usage ;; esac
  344. filter="--filter=$2"
  345. shift
  346. ;;
  347. --filter=*)
  348. filter="$1"
  349. ;;
  350. --)
  351. shift
  352. break
  353. ;;
  354. -*)
  355. usage
  356. ;;
  357. *)
  358. break
  359. ;;
  360. esac
  361. shift
  362. done
  363. git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \
  364. $quiet \
  365. $force \
  366. $progress \
  367. $remote \
  368. $recursive \
  369. $init \
  370. $no_fetch \
  371. $rebase \
  372. $merge \
  373. $checkout \
  374. ${ref_format:+"$ref_format"} \
  375. ${reference:+"$reference"} \
  376. $dissociate \
  377. ${depth:+"$depth"} \
  378. $require_init \
  379. $single_branch \
  380. $recommend_shallow \
  381. $jobs \
  382. $filter \
  383. -- \
  384. "$@"
  385. }
  386. #
  387. # Configures a submodule's default branch
  388. #
  389. # $@ = requested path
  390. #
  391. cmd_set_branch() {
  392. # parse $args after "submodule ... set-branch".
  393. while test $# -ne 0
  394. do
  395. case "$1" in
  396. -q|--quiet)
  397. # we don't do anything with this but we need to accept it
  398. ;;
  399. -d|--default)
  400. default=$1
  401. ;;
  402. -b|--branch)
  403. case "$2" in '') usage ;; esac
  404. branch="--branch=$2"
  405. shift
  406. ;;
  407. -b*|--branch=*)
  408. branch="$1"
  409. ;;
  410. --)
  411. shift
  412. break
  413. ;;
  414. -*)
  415. usage
  416. ;;
  417. *)
  418. break
  419. ;;
  420. esac
  421. shift
  422. done
  423. git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch \
  424. $quiet \
  425. ${branch:+"$branch"} \
  426. $default \
  427. -- \
  428. "$@"
  429. }
  430. #
  431. # Configures a submodule's remote url
  432. #
  433. # $@ = requested path, requested url
  434. #
  435. cmd_set_url() {
  436. # parse $args after "submodule ... set-url".
  437. while test $# -ne 0
  438. do
  439. case "$1" in
  440. -q|--quiet)
  441. quiet=$1
  442. ;;
  443. --)
  444. shift
  445. break
  446. ;;
  447. -*)
  448. usage
  449. ;;
  450. *)
  451. break
  452. ;;
  453. esac
  454. shift
  455. done
  456. git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url \
  457. $quiet \
  458. -- \
  459. "$@"
  460. }
  461. #
  462. # Show commit summary for submodules in index or working tree
  463. #
  464. # If '--cached' is given, show summary between index and given commit,
  465. # or between working tree and given commit
  466. #
  467. # $@ = [commit (default 'HEAD'),] requested paths (default all)
  468. #
  469. cmd_summary() {
  470. # parse $args after "submodule ... summary".
  471. while test $# -ne 0
  472. do
  473. case "$1" in
  474. --cached)
  475. cached=$1
  476. ;;
  477. --files)
  478. files=$1
  479. ;;
  480. --for-status)
  481. for_status=$1
  482. ;;
  483. -n|--summary-limit)
  484. case "$2" in '') usage ;; esac
  485. summary_limit="--summary-limit=$2"
  486. shift
  487. ;;
  488. -n*|--summary-limit=*)
  489. summary_limit="$1"
  490. ;;
  491. --)
  492. shift
  493. break
  494. ;;
  495. -*)
  496. usage
  497. ;;
  498. *)
  499. break
  500. ;;
  501. esac
  502. shift
  503. done
  504. git ${wt_prefix:+-C "$wt_prefix"} submodule--helper summary \
  505. $files \
  506. $cached \
  507. $for_status \
  508. ${summary_limit:+"$summary_limit"} \
  509. -- \
  510. "$@"
  511. }
  512. #
  513. # List all submodules, prefixed with:
  514. # - submodule not initialized
  515. # + different revision checked out
  516. #
  517. # If --cached was specified the revision in the index will be printed
  518. # instead of the currently checked out revision.
  519. #
  520. # $@ = requested paths (default to all)
  521. #
  522. cmd_status()
  523. {
  524. # parse $args after "submodule ... status".
  525. while test $# -ne 0
  526. do
  527. case "$1" in
  528. -q|--quiet)
  529. quiet=$1
  530. ;;
  531. --cached)
  532. cached=$1
  533. ;;
  534. --recursive)
  535. recursive=$1
  536. ;;
  537. --)
  538. shift
  539. break
  540. ;;
  541. -*)
  542. usage
  543. ;;
  544. *)
  545. break
  546. ;;
  547. esac
  548. shift
  549. done
  550. git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status \
  551. $quiet \
  552. $cached \
  553. $recursive \
  554. -- \
  555. "$@"
  556. }
  557. #
  558. # Sync remote urls for submodules
  559. # This makes the value for remote.$remote.url match the value
  560. # specified in .gitmodules.
  561. #
  562. cmd_sync()
  563. {
  564. # parse $args after "submodule ... sync".
  565. while test $# -ne 0
  566. do
  567. case "$1" in
  568. -q|--quiet)
  569. quiet=$1
  570. shift
  571. ;;
  572. --recursive)
  573. recursive=$1
  574. shift
  575. ;;
  576. --)
  577. shift
  578. break
  579. ;;
  580. -*)
  581. usage
  582. ;;
  583. *)
  584. break
  585. ;;
  586. esac
  587. done
  588. git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync \
  589. $quiet \
  590. $recursive \
  591. -- \
  592. "$@"
  593. }
  594. cmd_absorbgitdirs()
  595. {
  596. git ${wt_prefix:+-C "$wt_prefix"} submodule--helper absorbgitdirs "$@"
  597. }
  598. # This loop parses the command line arguments to find the
  599. # subcommand name to dispatch. Parsing of the subcommand specific
  600. # options are primarily done by the subcommand implementations.
  601. # Subcommand specific options such as --branch and --cached are
  602. # parsed here as well, for backward compatibility.
  603. while test $# != 0 && test -z "$command"
  604. do
  605. case "$1" in
  606. add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs)
  607. command=$1
  608. ;;
  609. -q|--quiet)
  610. quiet=$1
  611. ;;
  612. --cached)
  613. cached=$1
  614. ;;
  615. --)
  616. break
  617. ;;
  618. -*)
  619. usage
  620. ;;
  621. *)
  622. break
  623. ;;
  624. esac
  625. shift
  626. done
  627. # No command word defaults to "status"
  628. if test -z "$command"
  629. then
  630. if test $# = 0
  631. then
  632. command=status
  633. else
  634. usage
  635. fi
  636. fi
  637. # "--cached" is accepted only by "status" and "summary"
  638. if test -n "$cached" && test "$command" != status && test "$command" != summary
  639. then
  640. usage
  641. fi
  642. "cmd_$(echo $command | sed -e s/-/_/g)" "$@"