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