Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
Michał Górny | 4c8a9db | 2012-06-25 12:56:59 +0200 | [diff] [blame] | 3 | # git-submodule.sh: add, init, update or list git submodules |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 4 | # |
| 5 | # Copyright (c) 2007 Lars Hjemli |
| 6 | |
Johan Herland | 1d5bec8 | 2009-08-19 03:45:19 +0200 | [diff] [blame] | 7 | dashless=$(basename "$0" | sed -e 's/-/ /') |
Denton Liu | 68cabbf | 2019-02-15 01:26:41 -0800 | [diff] [blame] | 8 | USAGE="[--quiet] [--cached] |
| 9 | or: $dashless [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>] |
Johan Herland | 64b19ff | 2009-08-19 03:45:24 +0200 | [diff] [blame] | 10 | or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...] |
Johan Herland | 1d5bec8 | 2009-08-19 03:45:19 +0200 | [diff] [blame] | 11 | or: $dashless [--quiet] init [--] [<path>...] |
Stefan Beller | f6a5279 | 2016-05-05 12:52:32 -0700 | [diff] [blame] | 12 | or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...) |
Josh Steadmon | f05da2b | 2022-02-04 21:00:49 -0800 | [diff] [blame] | 13 | 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>...] |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 14 | or: $dashless [--quiet] set-branch (--default|--branch <branch>) [--] <path> |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 15 | or: $dashless [--quiet] set-url [--] <path> <newurl> |
Junio C Hamano | adc5423 | 2009-08-27 16:59:25 -0700 | [diff] [blame] | 16 | or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...] |
Johan Herland | 15fc56a | 2009-08-19 03:45:22 +0200 | [diff] [blame] | 17 | or: $dashless [--quiet] foreach [--recursive] <command> |
Stefan Beller | c32eaa8 | 2017-01-11 12:59:17 -0800 | [diff] [blame] | 18 | or: $dashless [--quiet] sync [--recursive] [--] [<path>...] |
| 19 | or: $dashless [--quiet] absorbgitdirs [--] [<path>...]" |
Junio C Hamano | 8f321a3 | 2007-11-06 01:50:02 -0800 | [diff] [blame] | 20 | OPTIONS_SPEC= |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 21 | SUBDIRECTORY_OK=Yes |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 22 | . git-sh-setup |
| 23 | require_work_tree |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 24 | wt_prefix=$(git rev-parse --show-prefix) |
| 25 | cd_to_toplevel |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 26 | |
Brandon Williams | f1762d7 | 2016-12-14 14:39:52 -0800 | [diff] [blame] | 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 |
Jeff King | 33cfccb | 2015-09-16 13:13:12 -0400 | [diff] [blame] | 31 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 32 | command= |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 33 | quiet= |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 34 | branch= |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 35 | force= |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 36 | reference= |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 37 | cached= |
Gerrit Pape | 48bb303 | 2010-04-26 11:50:39 +0200 | [diff] [blame] | 38 | recursive= |
| 39 | init= |
Johannes Schindelin | 0060fd1 | 2019-09-12 14:20:39 +0200 | [diff] [blame] | 40 | require_init= |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 41 | files= |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 42 | remote= |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 43 | nofetch= |
Ævar Arnfjörð Bjarmason | 8f12108 | 2022-06-28 12:05:31 +0200 | [diff] [blame] | 44 | rebase= |
| 45 | merge= |
| 46 | checkout= |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 47 | custom_name= |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 48 | depth= |
Jeff King | 72c5f88 | 2016-09-22 01:24:46 -0400 | [diff] [blame] | 49 | progress= |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 50 | dissociate= |
Emily Shaffer | 132f600 | 2020-02-20 19:10:27 -0800 | [diff] [blame] | 51 | single_branch= |
Li Xuejiang | 65d100c | 2020-04-02 16:42:51 +0800 | [diff] [blame] | 52 | jobs= |
| 53 | recommend_shallow= |
Josh Steadmon | f05da2b | 2022-02-04 21:00:49 -0800 | [diff] [blame] | 54 | filter= |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 55 | |
René Scharfe | 862ae6c | 2013-04-01 15:06:27 +0200 | [diff] [blame] | 56 | isnumber() |
| 57 | { |
| 58 | n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1" |
| 59 | } |
| 60 | |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 61 | # |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 62 | # Add a new submodule to the working tree, .gitmodules and the index |
| 63 | # |
Mark Levedahl | ec05df3 | 2008-07-09 21:05:40 -0400 | [diff] [blame] | 64 | # $@ = repo path |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 65 | # |
| 66 | # optional branch is stored in global branch variable |
| 67 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 68 | cmd_add() |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 69 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 70 | # parse $args after "submodule ... add". |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 71 | reference_path= |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 72 | while test $# -ne 0 |
| 73 | do |
| 74 | case "$1" in |
| 75 | -b | --branch) |
| 76 | case "$2" in '') usage ;; esac |
| 77 | branch=$2 |
| 78 | shift |
| 79 | ;; |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 80 | -f | --force) |
| 81 | force=$1 |
| 82 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 83 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 84 | quiet=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 85 | ;; |
Casey Fitzpatrick | 6d33e1c | 2018-05-03 06:53:45 -0400 | [diff] [blame] | 86 | --progress) |
| 87 | progress=1 |
| 88 | ;; |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 89 | --reference) |
| 90 | case "$2" in '') usage ;; esac |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 91 | reference_path=$2 |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 92 | shift |
| 93 | ;; |
| 94 | --reference=*) |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 95 | reference_path="${1#--reference=}" |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 96 | ;; |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 97 | --dissociate) |
| 98 | dissociate=1 |
| 99 | ;; |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 100 | --name) |
| 101 | case "$2" in '') usage ;; esac |
| 102 | custom_name=$2 |
| 103 | shift |
| 104 | ;; |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 105 | --depth) |
| 106 | case "$2" in '') usage ;; esac |
| 107 | depth="--depth=$2" |
| 108 | shift |
| 109 | ;; |
| 110 | --depth=*) |
| 111 | depth=$1 |
| 112 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 113 | --) |
| 114 | shift |
| 115 | break |
| 116 | ;; |
| 117 | -*) |
| 118 | usage |
| 119 | ;; |
| 120 | *) |
| 121 | break |
| 122 | ;; |
| 123 | esac |
| 124 | shift |
| 125 | done |
| 126 | |
Atharva Raykar | a6226fd | 2021-08-10 17:16:37 +0530 | [diff] [blame] | 127 | if test -z "$1" |
Antonio Ospite | 76e9bdc | 2018-10-25 18:18:12 +0200 | [diff] [blame] | 128 | then |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 129 | usage |
| 130 | fi |
| 131 | |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 132 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${quiet:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | # |
Mark Levedahl | 19a31f9 | 2008-08-10 19:10:04 -0400 | [diff] [blame] | 136 | # Execute an arbitrary command sequence in each checked out |
| 137 | # submodule |
| 138 | # |
| 139 | # $@ = command to execute |
| 140 | # |
| 141 | cmd_foreach() |
| 142 | { |
Johan Herland | 1d5bec8 | 2009-08-19 03:45:19 +0200 | [diff] [blame] | 143 | # parse $args after "submodule ... foreach". |
| 144 | while test $# -ne 0 |
| 145 | do |
| 146 | case "$1" in |
| 147 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 148 | quiet=1 |
Johan Herland | 1d5bec8 | 2009-08-19 03:45:19 +0200 | [diff] [blame] | 149 | ;; |
Johan Herland | 15fc56a | 2009-08-19 03:45:22 +0200 | [diff] [blame] | 150 | --recursive) |
| 151 | recursive=1 |
| 152 | ;; |
Johan Herland | 1d5bec8 | 2009-08-19 03:45:19 +0200 | [diff] [blame] | 153 | -*) |
| 154 | usage |
| 155 | ;; |
| 156 | *) |
| 157 | break |
| 158 | ;; |
| 159 | esac |
| 160 | shift |
| 161 | done |
| 162 | |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 163 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" |
Mark Levedahl | 19a31f9 | 2008-08-10 19:10:04 -0400 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | # |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 167 | # Register submodules in .git/config |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 168 | # |
| 169 | # $@ = requested paths (default to all) |
| 170 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 171 | cmd_init() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 172 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 173 | # parse $args after "submodule ... init". |
| 174 | while test $# -ne 0 |
| 175 | do |
| 176 | case "$1" in |
| 177 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 178 | quiet=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 179 | ;; |
| 180 | --) |
| 181 | shift |
| 182 | break |
| 183 | ;; |
| 184 | -*) |
| 185 | usage |
| 186 | ;; |
| 187 | *) |
| 188 | break |
| 189 | ;; |
| 190 | esac |
| 191 | shift |
| 192 | done |
| 193 | |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 194 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${quiet:+--quiet} -- "$@" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | # |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 198 | # Unregister submodules from .git/config and remove their work tree |
| 199 | # |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 200 | cmd_deinit() |
| 201 | { |
| 202 | # parse $args after "submodule ... deinit". |
Stefan Beller | f6a5279 | 2016-05-05 12:52:32 -0700 | [diff] [blame] | 203 | deinit_all= |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 204 | while test $# -ne 0 |
| 205 | do |
| 206 | case "$1" in |
| 207 | -f|--force) |
| 208 | force=$1 |
| 209 | ;; |
| 210 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 211 | quiet=1 |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 212 | ;; |
Stefan Beller | f6a5279 | 2016-05-05 12:52:32 -0700 | [diff] [blame] | 213 | --all) |
| 214 | deinit_all=t |
| 215 | ;; |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 216 | --) |
| 217 | shift |
| 218 | break |
| 219 | ;; |
| 220 | -*) |
| 221 | usage |
| 222 | ;; |
| 223 | *) |
| 224 | break |
| 225 | ;; |
| 226 | esac |
| 227 | shift |
| 228 | done |
| 229 | |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 230 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${quiet:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@" |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | # |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 234 | # Update each submodule path to correct revision, using clone and checkout as needed |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 235 | # |
| 236 | # $@ = requested paths (default to all) |
| 237 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 238 | cmd_update() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 239 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 240 | # parse $args after "submodule ... update". |
| 241 | while test $# -ne 0 |
| 242 | do |
| 243 | case "$1" in |
| 244 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 245 | quiet=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 246 | ;; |
Sven Strickroth | 6f65f84 | 2022-12-10 14:06:37 +0100 | [diff] [blame] | 247 | -v|--verbose) |
| 248 | quiet=0 |
| 249 | ;; |
Jeff King | 72c5f88 | 2016-09-22 01:24:46 -0400 | [diff] [blame] | 250 | --progress) |
Casey Fitzpatrick | c7199e3 | 2018-05-03 06:53:44 -0400 | [diff] [blame] | 251 | progress=1 |
Jeff King | 72c5f88 | 2016-09-22 01:24:46 -0400 | [diff] [blame] | 252 | ;; |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 253 | -i|--init) |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 254 | init=1 |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 255 | ;; |
Johannes Schindelin | 0060fd1 | 2019-09-12 14:20:39 +0200 | [diff] [blame] | 256 | --require-init) |
Johannes Schindelin | 0060fd1 | 2019-09-12 14:20:39 +0200 | [diff] [blame] | 257 | require_init=1 |
| 258 | ;; |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 259 | --remote) |
| 260 | remote=1 |
| 261 | ;; |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 262 | -N|--no-fetch) |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 263 | nofetch=1 |
| 264 | ;; |
Nicolas Morey-Chaisemartin | 9db31bd | 2011-04-01 11:42:03 +0200 | [diff] [blame] | 265 | -f|--force) |
| 266 | force=$1 |
| 267 | ;; |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 268 | -r|--rebase) |
Ævar Arnfjörð Bjarmason | 8f12108 | 2022-06-28 12:05:31 +0200 | [diff] [blame] | 269 | rebase=1 |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 270 | ;; |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 271 | --reference) |
| 272 | case "$2" in '') usage ;; esac |
| 273 | reference="--reference=$2" |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 274 | shift |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 275 | ;; |
| 276 | --reference=*) |
| 277 | reference="$1" |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 278 | ;; |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 279 | --dissociate) |
| 280 | dissociate=1 |
| 281 | ;; |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 282 | -m|--merge) |
Ævar Arnfjörð Bjarmason | 8f12108 | 2022-06-28 12:05:31 +0200 | [diff] [blame] | 283 | merge=1 |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 284 | ;; |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 285 | --recursive) |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 286 | recursive=1 |
| 287 | ;; |
Junio C Hamano | efc5fb6 | 2011-10-10 15:56:16 -0700 | [diff] [blame] | 288 | --checkout) |
Ævar Arnfjörð Bjarmason | 8f12108 | 2022-06-28 12:05:31 +0200 | [diff] [blame] | 289 | checkout=1 |
Junio C Hamano | efc5fb6 | 2011-10-10 15:56:16 -0700 | [diff] [blame] | 290 | ;; |
Stefan Beller | abed000 | 2016-05-26 14:59:43 -0700 | [diff] [blame] | 291 | --recommend-shallow) |
| 292 | recommend_shallow="--recommend-shallow" |
| 293 | ;; |
| 294 | --no-recommend-shallow) |
| 295 | recommend_shallow="--no-recommend-shallow" |
| 296 | ;; |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 297 | --depth) |
| 298 | case "$2" in '') usage ;; esac |
| 299 | depth="--depth=$2" |
| 300 | shift |
| 301 | ;; |
| 302 | --depth=*) |
| 303 | depth=$1 |
| 304 | ;; |
Stefan Beller | 2335b87 | 2016-02-29 18:07:19 -0800 | [diff] [blame] | 305 | -j|--jobs) |
| 306 | case "$2" in '') usage ;; esac |
| 307 | jobs="--jobs=$2" |
| 308 | shift |
| 309 | ;; |
| 310 | --jobs=*) |
| 311 | jobs=$1 |
| 312 | ;; |
Emily Shaffer | 132f600 | 2020-02-20 19:10:27 -0800 | [diff] [blame] | 313 | --single-branch) |
| 314 | single_branch="--single-branch" |
| 315 | ;; |
| 316 | --no-single-branch) |
| 317 | single_branch="--no-single-branch" |
| 318 | ;; |
Josh Steadmon | f05da2b | 2022-02-04 21:00:49 -0800 | [diff] [blame] | 319 | --filter) |
| 320 | case "$2" in '') usage ;; esac |
| 321 | filter="--filter=$2" |
| 322 | shift |
| 323 | ;; |
| 324 | --filter=*) |
| 325 | filter="$1" |
| 326 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 327 | --) |
| 328 | shift |
| 329 | break |
| 330 | ;; |
| 331 | -*) |
| 332 | usage |
| 333 | ;; |
| 334 | *) |
| 335 | break |
| 336 | ;; |
| 337 | esac |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 338 | shift |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 339 | done |
| 340 | |
Atharva Raykar | b3c5f5c | 2022-03-15 14:09:24 -0700 | [diff] [blame] | 341 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \ |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 342 | ${quiet:+--quiet} \ |
Atharva Raykar | b3c5f5c | 2022-03-15 14:09:24 -0700 | [diff] [blame] | 343 | ${force:+--force} \ |
Casey Fitzpatrick | c7199e3 | 2018-05-03 06:53:44 -0400 | [diff] [blame] | 344 | ${progress:+"--progress"} \ |
Atharva Raykar | b3c5f5c | 2022-03-15 14:09:24 -0700 | [diff] [blame] | 345 | ${remote:+--remote} \ |
| 346 | ${recursive:+--recursive} \ |
Glen Choo | 29a5e9e | 2022-03-04 16:13:58 -0800 | [diff] [blame] | 347 | ${init:+--init} \ |
Atharva Raykar | b3c5f5c | 2022-03-15 14:09:24 -0700 | [diff] [blame] | 348 | ${nofetch:+--no-fetch} \ |
Ævar Arnfjörð Bjarmason | 8f12108 | 2022-06-28 12:05:31 +0200 | [diff] [blame] | 349 | ${rebase:+--rebase} \ |
| 350 | ${merge:+--merge} \ |
| 351 | ${checkout:+--checkout} \ |
Stefan Beller | 5f50f33 | 2016-08-11 16:14:01 -0700 | [diff] [blame] | 352 | ${reference:+"$reference"} \ |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 353 | ${dissociate:+"--dissociate"} \ |
Glen Choo | c9911c9 | 2022-03-15 14:09:22 -0700 | [diff] [blame] | 354 | ${depth:+"$depth"} \ |
Johannes Schindelin | 0060fd1 | 2019-09-12 14:20:39 +0200 | [diff] [blame] | 355 | ${require_init:+--require-init} \ |
Atharva Raykar | b3c5f5c | 2022-03-15 14:09:24 -0700 | [diff] [blame] | 356 | ${dissociate:+"--dissociate"} \ |
Emily Shaffer | 132f600 | 2020-02-20 19:10:27 -0800 | [diff] [blame] | 357 | $single_branch \ |
Casey Fitzpatrick | c7199e3 | 2018-05-03 06:53:44 -0400 | [diff] [blame] | 358 | $recommend_shallow \ |
| 359 | $jobs \ |
Josh Steadmon | f05da2b | 2022-02-04 21:00:49 -0800 | [diff] [blame] | 360 | $filter \ |
Nguyễn Thái Ngọc Duy | a282f5a | 2019-04-12 17:08:19 +0700 | [diff] [blame] | 361 | -- \ |
Atharva Raykar | b3c5f5c | 2022-03-15 14:09:24 -0700 | [diff] [blame] | 362 | "$@" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 363 | } |
| 364 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 365 | # |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 366 | # Configures a submodule's default branch |
| 367 | # |
| 368 | # $@ = requested path |
| 369 | # |
| 370 | cmd_set_branch() { |
Shourya Shukla | 2964d6e | 2020-06-02 22:05:23 +0530 | [diff] [blame] | 371 | default= |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 372 | branch= |
| 373 | |
| 374 | while test $# -ne 0 |
| 375 | do |
| 376 | case "$1" in |
| 377 | -q|--quiet) |
| 378 | # we don't do anything with this but we need to accept it |
| 379 | ;; |
| 380 | -d|--default) |
Shourya Shukla | 2964d6e | 2020-06-02 22:05:23 +0530 | [diff] [blame] | 381 | default=1 |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 382 | ;; |
| 383 | -b|--branch) |
| 384 | case "$2" in '') usage ;; esac |
| 385 | branch=$2 |
| 386 | shift |
| 387 | ;; |
| 388 | --) |
| 389 | shift |
| 390 | break |
| 391 | ;; |
| 392 | -*) |
| 393 | usage |
| 394 | ;; |
| 395 | *) |
| 396 | break |
| 397 | ;; |
| 398 | esac |
| 399 | shift |
| 400 | done |
| 401 | |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 402 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${quiet:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@" |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | # |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 406 | # Configures a submodule's remote url |
| 407 | # |
| 408 | # $@ = requested path, requested url |
| 409 | # |
| 410 | cmd_set_url() { |
| 411 | while test $# -ne 0 |
| 412 | do |
| 413 | case "$1" in |
| 414 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 415 | quiet=1 |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 416 | ;; |
| 417 | --) |
| 418 | shift |
| 419 | break |
| 420 | ;; |
| 421 | -*) |
| 422 | usage |
| 423 | ;; |
| 424 | *) |
| 425 | break |
| 426 | ;; |
| 427 | esac |
| 428 | shift |
| 429 | done |
| 430 | |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 431 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${quiet:+--quiet} -- "$@" |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | # |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 435 | # Show commit summary for submodules in index or working tree |
| 436 | # |
| 437 | # If '--cached' is given, show summary between index and given commit, |
| 438 | # or between working tree and given commit |
| 439 | # |
| 440 | # $@ = [commit (default 'HEAD'),] requested paths (default all) |
| 441 | # |
| 442 | cmd_summary() { |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 443 | summary_limit=-1 |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 444 | for_status= |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 445 | diff_cmd=diff-index |
Emil Medve | bffe71f | 2007-06-26 18:40:58 -0500 | [diff] [blame] | 446 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 447 | # parse $args after "submodule ... summary". |
| 448 | while test $# -ne 0 |
| 449 | do |
| 450 | case "$1" in |
| 451 | --cached) |
Ævar Arnfjörð Bjarmason | 757d092 | 2022-06-28 12:05:25 +0200 | [diff] [blame] | 452 | cached=1 |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 453 | ;; |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 454 | --files) |
| 455 | files="$1" |
| 456 | ;; |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 457 | --for-status) |
| 458 | for_status="$1" |
| 459 | ;; |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 460 | -n|--summary-limit) |
René Scharfe | 862ae6c | 2013-04-01 15:06:27 +0200 | [diff] [blame] | 461 | summary_limit="$2" |
| 462 | isnumber "$summary_limit" || usage |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 463 | shift |
| 464 | ;; |
René Scharfe | 862ae6c | 2013-04-01 15:06:27 +0200 | [diff] [blame] | 465 | --summary-limit=*) |
| 466 | summary_limit="${1#--summary-limit=}" |
| 467 | isnumber "$summary_limit" || usage |
| 468 | ;; |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 469 | --) |
| 470 | shift |
| 471 | break |
| 472 | ;; |
| 473 | -*) |
| 474 | usage |
| 475 | ;; |
| 476 | *) |
| 477 | break |
| 478 | ;; |
| 479 | esac |
| 480 | shift |
| 481 | done |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 482 | |
Kaartic Sivaraam | 1cf823d | 2021-06-22 23:44:52 +0530 | [diff] [blame] | 483 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper summary ${files:+--files} ${cached:+--cached} ${for_status:+--for-status} ${summary_limit:+-n $summary_limit} -- "$@" |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 484 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 485 | # |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 486 | # List all submodules, prefixed with: |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 487 | # - submodule not initialized |
| 488 | # + different revision checked out |
| 489 | # |
| 490 | # If --cached was specified the revision in the index will be printed |
| 491 | # instead of the currently checked out revision. |
| 492 | # |
| 493 | # $@ = requested paths (default to all) |
| 494 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 495 | cmd_status() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 496 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 497 | # parse $args after "submodule ... status". |
| 498 | while test $# -ne 0 |
| 499 | do |
| 500 | case "$1" in |
| 501 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 502 | quiet=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 503 | ;; |
| 504 | --cached) |
| 505 | cached=1 |
| 506 | ;; |
Johan Herland | 64b19ff | 2009-08-19 03:45:24 +0200 | [diff] [blame] | 507 | --recursive) |
| 508 | recursive=1 |
| 509 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 510 | --) |
| 511 | shift |
| 512 | break |
| 513 | ;; |
| 514 | -*) |
| 515 | usage |
| 516 | ;; |
| 517 | *) |
| 518 | break |
| 519 | ;; |
| 520 | esac |
| 521 | shift |
| 522 | done |
| 523 | |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 524 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${quiet:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 525 | } |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 526 | # |
| 527 | # Sync remote urls for submodules |
| 528 | # This makes the value for remote.$remote.url match the value |
| 529 | # specified in .gitmodules. |
| 530 | # |
| 531 | cmd_sync() |
| 532 | { |
| 533 | while test $# -ne 0 |
| 534 | do |
| 535 | case "$1" in |
| 536 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 537 | quiet=1 |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 538 | shift |
| 539 | ;; |
Phil Hord | 82f49f2 | 2012-10-26 15:44:42 -0400 | [diff] [blame] | 540 | --recursive) |
| 541 | recursive=1 |
| 542 | shift |
| 543 | ;; |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 544 | --) |
| 545 | shift |
| 546 | break |
| 547 | ;; |
| 548 | -*) |
| 549 | usage |
| 550 | ;; |
| 551 | *) |
| 552 | break |
| 553 | ;; |
| 554 | esac |
| 555 | done |
Brandon Williams | e7849a9 | 2017-03-16 15:29:45 -0700 | [diff] [blame] | 556 | |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 557 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 558 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 559 | |
Stefan Beller | f6f8586 | 2016-12-12 11:04:35 -0800 | [diff] [blame] | 560 | cmd_absorbgitdirs() |
| 561 | { |
Ævar Arnfjörð Bjarmason | 64f48ad | 2022-11-08 15:10:38 +0100 | [diff] [blame] | 562 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper absorbgitdirs "$@" |
Stefan Beller | f6f8586 | 2016-12-12 11:04:35 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 565 | # This loop parses the command line arguments to find the |
| 566 | # subcommand name to dispatch. Parsing of the subcommand specific |
| 567 | # options are primarily done by the subcommand implementations. |
| 568 | # Subcommand specific options such as --branch and --cached are |
| 569 | # parsed here as well, for backward compatibility. |
| 570 | |
| 571 | while test $# != 0 && test -z "$command" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 572 | do |
| 573 | case "$1" in |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 574 | add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs) |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 575 | command=$1 |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 576 | ;; |
| 577 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 578 | quiet=1 |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 579 | ;; |
| 580 | --cached) |
Ævar Arnfjörð Bjarmason | 757d092 | 2022-06-28 12:05:25 +0200 | [diff] [blame] | 581 | cached=1 |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 582 | ;; |
| 583 | --) |
| 584 | break |
| 585 | ;; |
| 586 | -*) |
| 587 | usage |
| 588 | ;; |
| 589 | *) |
| 590 | break |
| 591 | ;; |
| 592 | esac |
| 593 | shift |
| 594 | done |
| 595 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 596 | # No command word defaults to "status" |
Ramkumar Ramachandra | af9c9f9 | 2012-09-22 16:57:59 +0530 | [diff] [blame] | 597 | if test -z "$command" |
| 598 | then |
| 599 | if test $# = 0 |
| 600 | then |
| 601 | command=status |
| 602 | else |
| 603 | usage |
| 604 | fi |
| 605 | fi |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 606 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 607 | # "--cached" is accepted only by "status" and "summary" |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 608 | if test -n "$cached" && test "$command" != status && test "$command" != summary |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 609 | then |
| 610 | usage |
| 611 | fi |
| 612 | |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 613 | "cmd_$(echo $command | sed -e s/-/_/g)" "$@" |