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 | ;; |
Jeff King | 72c5f88 | 2016-09-22 01:24:46 -0400 | [diff] [blame] | 247 | --progress) |
Casey Fitzpatrick | c7199e3 | 2018-05-03 06:53:44 -0400 | [diff] [blame] | 248 | progress=1 |
Jeff King | 72c5f88 | 2016-09-22 01:24:46 -0400 | [diff] [blame] | 249 | ;; |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 250 | -i|--init) |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 251 | init=1 |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 252 | ;; |
Johannes Schindelin | 0060fd1 | 2019-09-12 14:20:39 +0200 | [diff] [blame] | 253 | --require-init) |
Johannes Schindelin | 0060fd1 | 2019-09-12 14:20:39 +0200 | [diff] [blame] | 254 | require_init=1 |
| 255 | ;; |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 256 | --remote) |
| 257 | remote=1 |
| 258 | ;; |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 259 | -N|--no-fetch) |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 260 | nofetch=1 |
| 261 | ;; |
Nicolas Morey-Chaisemartin | 9db31bd | 2011-04-01 11:42:03 +0200 | [diff] [blame] | 262 | -f|--force) |
| 263 | force=$1 |
| 264 | ;; |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 265 | -r|--rebase) |
Ævar Arnfjörð Bjarmason | 8f12108 | 2022-06-28 12:05:31 +0200 | [diff] [blame] | 266 | rebase=1 |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 267 | ;; |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 268 | --reference) |
| 269 | case "$2" in '') usage ;; esac |
| 270 | reference="--reference=$2" |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 271 | shift |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 272 | ;; |
| 273 | --reference=*) |
| 274 | reference="$1" |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 275 | ;; |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 276 | --dissociate) |
| 277 | dissociate=1 |
| 278 | ;; |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 279 | -m|--merge) |
Ævar Arnfjörð Bjarmason | 8f12108 | 2022-06-28 12:05:31 +0200 | [diff] [blame] | 280 | merge=1 |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 281 | ;; |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 282 | --recursive) |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 283 | recursive=1 |
| 284 | ;; |
Junio C Hamano | efc5fb6 | 2011-10-10 15:56:16 -0700 | [diff] [blame] | 285 | --checkout) |
Ævar Arnfjörð Bjarmason | 8f12108 | 2022-06-28 12:05:31 +0200 | [diff] [blame] | 286 | checkout=1 |
Junio C Hamano | efc5fb6 | 2011-10-10 15:56:16 -0700 | [diff] [blame] | 287 | ;; |
Stefan Beller | abed000 | 2016-05-26 14:59:43 -0700 | [diff] [blame] | 288 | --recommend-shallow) |
| 289 | recommend_shallow="--recommend-shallow" |
| 290 | ;; |
| 291 | --no-recommend-shallow) |
| 292 | recommend_shallow="--no-recommend-shallow" |
| 293 | ;; |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 294 | --depth) |
| 295 | case "$2" in '') usage ;; esac |
| 296 | depth="--depth=$2" |
| 297 | shift |
| 298 | ;; |
| 299 | --depth=*) |
| 300 | depth=$1 |
| 301 | ;; |
Stefan Beller | 2335b87 | 2016-02-29 18:07:19 -0800 | [diff] [blame] | 302 | -j|--jobs) |
| 303 | case "$2" in '') usage ;; esac |
| 304 | jobs="--jobs=$2" |
| 305 | shift |
| 306 | ;; |
| 307 | --jobs=*) |
| 308 | jobs=$1 |
| 309 | ;; |
Emily Shaffer | 132f600 | 2020-02-20 19:10:27 -0800 | [diff] [blame] | 310 | --single-branch) |
| 311 | single_branch="--single-branch" |
| 312 | ;; |
| 313 | --no-single-branch) |
| 314 | single_branch="--no-single-branch" |
| 315 | ;; |
Josh Steadmon | f05da2b | 2022-02-04 21:00:49 -0800 | [diff] [blame] | 316 | --filter) |
| 317 | case "$2" in '') usage ;; esac |
| 318 | filter="--filter=$2" |
| 319 | shift |
| 320 | ;; |
| 321 | --filter=*) |
| 322 | filter="$1" |
| 323 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 324 | --) |
| 325 | shift |
| 326 | break |
| 327 | ;; |
| 328 | -*) |
| 329 | usage |
| 330 | ;; |
| 331 | *) |
| 332 | break |
| 333 | ;; |
| 334 | esac |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 335 | shift |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 336 | done |
| 337 | |
Atharva Raykar | b3c5f5c | 2022-03-15 14:09:24 -0700 | [diff] [blame] | 338 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \ |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 339 | ${quiet:+--quiet} \ |
Atharva Raykar | b3c5f5c | 2022-03-15 14:09:24 -0700 | [diff] [blame] | 340 | ${force:+--force} \ |
Casey Fitzpatrick | c7199e3 | 2018-05-03 06:53:44 -0400 | [diff] [blame] | 341 | ${progress:+"--progress"} \ |
Atharva Raykar | b3c5f5c | 2022-03-15 14:09:24 -0700 | [diff] [blame] | 342 | ${remote:+--remote} \ |
| 343 | ${recursive:+--recursive} \ |
Glen Choo | 29a5e9e | 2022-03-04 16:13:58 -0800 | [diff] [blame] | 344 | ${init:+--init} \ |
Atharva Raykar | b3c5f5c | 2022-03-15 14:09:24 -0700 | [diff] [blame] | 345 | ${nofetch:+--no-fetch} \ |
Ævar Arnfjörð Bjarmason | 8f12108 | 2022-06-28 12:05:31 +0200 | [diff] [blame] | 346 | ${rebase:+--rebase} \ |
| 347 | ${merge:+--merge} \ |
| 348 | ${checkout:+--checkout} \ |
Stefan Beller | 5f50f33 | 2016-08-11 16:14:01 -0700 | [diff] [blame] | 349 | ${reference:+"$reference"} \ |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 350 | ${dissociate:+"--dissociate"} \ |
Glen Choo | c9911c9 | 2022-03-15 14:09:22 -0700 | [diff] [blame] | 351 | ${depth:+"$depth"} \ |
Johannes Schindelin | 0060fd1 | 2019-09-12 14:20:39 +0200 | [diff] [blame] | 352 | ${require_init:+--require-init} \ |
Atharva Raykar | b3c5f5c | 2022-03-15 14:09:24 -0700 | [diff] [blame] | 353 | ${dissociate:+"--dissociate"} \ |
Emily Shaffer | 132f600 | 2020-02-20 19:10:27 -0800 | [diff] [blame] | 354 | $single_branch \ |
Casey Fitzpatrick | c7199e3 | 2018-05-03 06:53:44 -0400 | [diff] [blame] | 355 | $recommend_shallow \ |
| 356 | $jobs \ |
Josh Steadmon | f05da2b | 2022-02-04 21:00:49 -0800 | [diff] [blame] | 357 | $filter \ |
Nguyễn Thái Ngọc Duy | a282f5a | 2019-04-12 17:08:19 +0700 | [diff] [blame] | 358 | -- \ |
Atharva Raykar | b3c5f5c | 2022-03-15 14:09:24 -0700 | [diff] [blame] | 359 | "$@" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 360 | } |
| 361 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 362 | # |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 363 | # Configures a submodule's default branch |
| 364 | # |
| 365 | # $@ = requested path |
| 366 | # |
| 367 | cmd_set_branch() { |
Shourya Shukla | 2964d6e | 2020-06-02 22:05:23 +0530 | [diff] [blame] | 368 | default= |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 369 | branch= |
| 370 | |
| 371 | while test $# -ne 0 |
| 372 | do |
| 373 | case "$1" in |
| 374 | -q|--quiet) |
| 375 | # we don't do anything with this but we need to accept it |
| 376 | ;; |
| 377 | -d|--default) |
Shourya Shukla | 2964d6e | 2020-06-02 22:05:23 +0530 | [diff] [blame] | 378 | default=1 |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 379 | ;; |
| 380 | -b|--branch) |
| 381 | case "$2" in '') usage ;; esac |
| 382 | branch=$2 |
| 383 | shift |
| 384 | ;; |
| 385 | --) |
| 386 | shift |
| 387 | break |
| 388 | ;; |
| 389 | -*) |
| 390 | usage |
| 391 | ;; |
| 392 | *) |
| 393 | break |
| 394 | ;; |
| 395 | esac |
| 396 | shift |
| 397 | done |
| 398 | |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 399 | 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] | 400 | } |
| 401 | |
| 402 | # |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 403 | # Configures a submodule's remote url |
| 404 | # |
| 405 | # $@ = requested path, requested url |
| 406 | # |
| 407 | cmd_set_url() { |
| 408 | while test $# -ne 0 |
| 409 | do |
| 410 | case "$1" in |
| 411 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 412 | quiet=1 |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 413 | ;; |
| 414 | --) |
| 415 | shift |
| 416 | break |
| 417 | ;; |
| 418 | -*) |
| 419 | usage |
| 420 | ;; |
| 421 | *) |
| 422 | break |
| 423 | ;; |
| 424 | esac |
| 425 | shift |
| 426 | done |
| 427 | |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 428 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${quiet:+--quiet} -- "$@" |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | # |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 432 | # Show commit summary for submodules in index or working tree |
| 433 | # |
| 434 | # If '--cached' is given, show summary between index and given commit, |
| 435 | # or between working tree and given commit |
| 436 | # |
| 437 | # $@ = [commit (default 'HEAD'),] requested paths (default all) |
| 438 | # |
| 439 | cmd_summary() { |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 440 | summary_limit=-1 |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 441 | for_status= |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 442 | diff_cmd=diff-index |
Emil Medve | bffe71f | 2007-06-26 18:40:58 -0500 | [diff] [blame] | 443 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 444 | # parse $args after "submodule ... summary". |
| 445 | while test $# -ne 0 |
| 446 | do |
| 447 | case "$1" in |
| 448 | --cached) |
Ævar Arnfjörð Bjarmason | 757d092 | 2022-06-28 12:05:25 +0200 | [diff] [blame] | 449 | cached=1 |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 450 | ;; |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 451 | --files) |
| 452 | files="$1" |
| 453 | ;; |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 454 | --for-status) |
| 455 | for_status="$1" |
| 456 | ;; |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 457 | -n|--summary-limit) |
René Scharfe | 862ae6c | 2013-04-01 15:06:27 +0200 | [diff] [blame] | 458 | summary_limit="$2" |
| 459 | isnumber "$summary_limit" || usage |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 460 | shift |
| 461 | ;; |
René Scharfe | 862ae6c | 2013-04-01 15:06:27 +0200 | [diff] [blame] | 462 | --summary-limit=*) |
| 463 | summary_limit="${1#--summary-limit=}" |
| 464 | isnumber "$summary_limit" || usage |
| 465 | ;; |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 466 | --) |
| 467 | shift |
| 468 | break |
| 469 | ;; |
| 470 | -*) |
| 471 | usage |
| 472 | ;; |
| 473 | *) |
| 474 | break |
| 475 | ;; |
| 476 | esac |
| 477 | shift |
| 478 | done |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 479 | |
Kaartic Sivaraam | 1cf823d | 2021-06-22 23:44:52 +0530 | [diff] [blame] | 480 | 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] | 481 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 482 | # |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 483 | # List all submodules, prefixed with: |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 484 | # - submodule not initialized |
| 485 | # + different revision checked out |
| 486 | # |
| 487 | # If --cached was specified the revision in the index will be printed |
| 488 | # instead of the currently checked out revision. |
| 489 | # |
| 490 | # $@ = requested paths (default to all) |
| 491 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 492 | cmd_status() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 493 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 494 | # parse $args after "submodule ... status". |
| 495 | while test $# -ne 0 |
| 496 | do |
| 497 | case "$1" in |
| 498 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 499 | quiet=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 500 | ;; |
| 501 | --cached) |
| 502 | cached=1 |
| 503 | ;; |
Johan Herland | 64b19ff | 2009-08-19 03:45:24 +0200 | [diff] [blame] | 504 | --recursive) |
| 505 | recursive=1 |
| 506 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 507 | --) |
| 508 | shift |
| 509 | break |
| 510 | ;; |
| 511 | -*) |
| 512 | usage |
| 513 | ;; |
| 514 | *) |
| 515 | break |
| 516 | ;; |
| 517 | esac |
| 518 | shift |
| 519 | done |
| 520 | |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 521 | 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] | 522 | } |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 523 | # |
| 524 | # Sync remote urls for submodules |
| 525 | # This makes the value for remote.$remote.url match the value |
| 526 | # specified in .gitmodules. |
| 527 | # |
| 528 | cmd_sync() |
| 529 | { |
| 530 | while test $# -ne 0 |
| 531 | do |
| 532 | case "$1" in |
| 533 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 534 | quiet=1 |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 535 | shift |
| 536 | ;; |
Phil Hord | 82f49f2 | 2012-10-26 15:44:42 -0400 | [diff] [blame] | 537 | --recursive) |
| 538 | recursive=1 |
| 539 | shift |
| 540 | ;; |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 541 | --) |
| 542 | shift |
| 543 | break |
| 544 | ;; |
| 545 | -*) |
| 546 | usage |
| 547 | ;; |
| 548 | *) |
| 549 | break |
| 550 | ;; |
| 551 | esac |
| 552 | done |
Brandon Williams | e7849a9 | 2017-03-16 15:29:45 -0700 | [diff] [blame] | 553 | |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 554 | 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] | 555 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 556 | |
Stefan Beller | f6f8586 | 2016-12-12 11:04:35 -0800 | [diff] [blame] | 557 | cmd_absorbgitdirs() |
| 558 | { |
Ævar Arnfjörð Bjarmason | 64f48ad | 2022-11-08 15:10:38 +0100 | [diff] [blame] | 559 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper absorbgitdirs "$@" |
Stefan Beller | f6f8586 | 2016-12-12 11:04:35 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 562 | # This loop parses the command line arguments to find the |
| 563 | # subcommand name to dispatch. Parsing of the subcommand specific |
| 564 | # options are primarily done by the subcommand implementations. |
| 565 | # Subcommand specific options such as --branch and --cached are |
| 566 | # parsed here as well, for backward compatibility. |
| 567 | |
| 568 | while test $# != 0 && test -z "$command" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 569 | do |
| 570 | case "$1" in |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 571 | 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] | 572 | command=$1 |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 573 | ;; |
| 574 | -q|--quiet) |
Ævar Arnfjörð Bjarmason | 2eec463 | 2022-06-28 12:05:33 +0200 | [diff] [blame] | 575 | quiet=1 |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 576 | ;; |
| 577 | --cached) |
Ævar Arnfjörð Bjarmason | 757d092 | 2022-06-28 12:05:25 +0200 | [diff] [blame] | 578 | cached=1 |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 579 | ;; |
| 580 | --) |
| 581 | break |
| 582 | ;; |
| 583 | -*) |
| 584 | usage |
| 585 | ;; |
| 586 | *) |
| 587 | break |
| 588 | ;; |
| 589 | esac |
| 590 | shift |
| 591 | done |
| 592 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 593 | # No command word defaults to "status" |
Ramkumar Ramachandra | af9c9f9 | 2012-09-22 16:57:59 +0530 | [diff] [blame] | 594 | if test -z "$command" |
| 595 | then |
| 596 | if test $# = 0 |
| 597 | then |
| 598 | command=status |
| 599 | else |
| 600 | usage |
| 601 | fi |
| 602 | fi |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 603 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 604 | # "--cached" is accepted only by "status" and "summary" |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 605 | if test -n "$cached" && test "$command" != status && test "$command" != summary |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 606 | then |
| 607 | usage |
| 608 | fi |
| 609 | |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 610 | "cmd_$(echo $command | sed -e s/-/_/g)" "$@" |