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>...) |
Emily Shaffer | 132f600 | 2020-02-20 19:10:27 -0800 | [diff] [blame] | 13 | or: $dashless [--quiet] update [--init] [--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= |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 33 | branch= |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 34 | force= |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 35 | reference= |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 36 | cached= |
Gerrit Pape | 48bb303 | 2010-04-26 11:50:39 +0200 | [diff] [blame] | 37 | recursive= |
| 38 | init= |
Johannes Schindelin | 0060fd1 | 2019-09-12 14:20:39 +0200 | [diff] [blame] | 39 | require_init= |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 40 | files= |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 41 | remote= |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 42 | nofetch= |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 43 | update= |
Johan Herland | 15fc56a | 2009-08-19 03:45:22 +0200 | [diff] [blame] | 44 | prefix= |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 45 | custom_name= |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 46 | depth= |
Jeff King | 72c5f88 | 2016-09-22 01:24:46 -0400 | [diff] [blame] | 47 | progress= |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 48 | dissociate= |
Emily Shaffer | 132f600 | 2020-02-20 19:10:27 -0800 | [diff] [blame] | 49 | single_branch= |
Li Xuejiang | 65d100c | 2020-04-02 16:42:51 +0800 | [diff] [blame] | 50 | jobs= |
| 51 | recommend_shallow= |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 52 | |
Heiko Voigt | be9d0a3 | 2012-08-14 22:35:27 +0200 | [diff] [blame] | 53 | die_if_unmatched () |
| 54 | { |
| 55 | if test "$1" = "#unmatched" |
| 56 | then |
Johannes Sixt | c4c02bf | 2016-07-22 21:14:38 +0200 | [diff] [blame] | 57 | exit ${2:-1} |
Heiko Voigt | be9d0a3 | 2012-08-14 22:35:27 +0200 | [diff] [blame] | 58 | fi |
| 59 | } |
| 60 | |
René Scharfe | 862ae6c | 2013-04-01 15:06:27 +0200 | [diff] [blame] | 61 | isnumber() |
| 62 | { |
| 63 | n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1" |
| 64 | } |
| 65 | |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 66 | # Sanitize the local git environment for use within a submodule. We |
| 67 | # can't simply use clear_local_git_env since we want to preserve some |
| 68 | # of the settings from GIT_CONFIG_PARAMETERS. |
| 69 | sanitize_submodule_env() |
| 70 | { |
Jeff King | 89044ba | 2016-05-04 21:22:19 -0400 | [diff] [blame] | 71 | save_config=$GIT_CONFIG_PARAMETERS |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 72 | clear_local_git_env |
Jeff King | 89044ba | 2016-05-04 21:22:19 -0400 | [diff] [blame] | 73 | GIT_CONFIG_PARAMETERS=$save_config |
Jeff King | 860cba6 | 2016-04-28 09:37:44 -0400 | [diff] [blame] | 74 | export GIT_CONFIG_PARAMETERS |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 77 | # |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 78 | # Add a new submodule to the working tree, .gitmodules and the index |
| 79 | # |
Mark Levedahl | ec05df3 | 2008-07-09 21:05:40 -0400 | [diff] [blame] | 80 | # $@ = repo path |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 81 | # |
| 82 | # optional branch is stored in global branch variable |
| 83 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 84 | cmd_add() |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 85 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 86 | # parse $args after "submodule ... add". |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 87 | reference_path= |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 88 | while test $# -ne 0 |
| 89 | do |
| 90 | case "$1" in |
| 91 | -b | --branch) |
| 92 | case "$2" in '') usage ;; esac |
| 93 | branch=$2 |
| 94 | shift |
| 95 | ;; |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 96 | -f | --force) |
| 97 | force=$1 |
| 98 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 99 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 100 | GIT_QUIET=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 101 | ;; |
Casey Fitzpatrick | 6d33e1c | 2018-05-03 06:53:45 -0400 | [diff] [blame] | 102 | --progress) |
| 103 | progress=1 |
| 104 | ;; |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 105 | --reference) |
| 106 | case "$2" in '') usage ;; esac |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 107 | reference_path=$2 |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 108 | shift |
| 109 | ;; |
| 110 | --reference=*) |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 111 | reference_path="${1#--reference=}" |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 112 | ;; |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 113 | --dissociate) |
| 114 | dissociate=1 |
| 115 | ;; |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 116 | --name) |
| 117 | case "$2" in '') usage ;; esac |
| 118 | custom_name=$2 |
| 119 | shift |
| 120 | ;; |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 121 | --depth) |
| 122 | case "$2" in '') usage ;; esac |
| 123 | depth="--depth=$2" |
| 124 | shift |
| 125 | ;; |
| 126 | --depth=*) |
| 127 | depth=$1 |
| 128 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 129 | --) |
| 130 | shift |
| 131 | break |
| 132 | ;; |
| 133 | -*) |
| 134 | usage |
| 135 | ;; |
| 136 | *) |
| 137 | break |
| 138 | ;; |
| 139 | esac |
| 140 | shift |
| 141 | done |
| 142 | |
Atharva Raykar | a6226fd | 2021-08-10 17:16:37 +0530 | [diff] [blame] | 143 | if test -z "$1" |
Antonio Ospite | 76e9bdc | 2018-10-25 18:18:12 +0200 | [diff] [blame] | 144 | then |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 145 | usage |
| 146 | fi |
| 147 | |
Atharva Raykar | a6226fd | 2021-08-10 17:16:37 +0530 | [diff] [blame] | 148 | git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper add ${GIT_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] | 149 | } |
| 150 | |
| 151 | # |
Mark Levedahl | 19a31f9 | 2008-08-10 19:10:04 -0400 | [diff] [blame] | 152 | # Execute an arbitrary command sequence in each checked out |
| 153 | # submodule |
| 154 | # |
| 155 | # $@ = command to execute |
| 156 | # |
| 157 | cmd_foreach() |
| 158 | { |
Johan Herland | 1d5bec8 | 2009-08-19 03:45:19 +0200 | [diff] [blame] | 159 | # parse $args after "submodule ... foreach". |
| 160 | while test $# -ne 0 |
| 161 | do |
| 162 | case "$1" in |
| 163 | -q|--quiet) |
| 164 | GIT_QUIET=1 |
| 165 | ;; |
Johan Herland | 15fc56a | 2009-08-19 03:45:22 +0200 | [diff] [blame] | 166 | --recursive) |
| 167 | recursive=1 |
| 168 | ;; |
Johan Herland | 1d5bec8 | 2009-08-19 03:45:19 +0200 | [diff] [blame] | 169 | -*) |
| 170 | usage |
| 171 | ;; |
| 172 | *) |
| 173 | break |
| 174 | ;; |
| 175 | esac |
| 176 | shift |
| 177 | done |
| 178 | |
Kaartic Sivaraam | 1cf823d | 2021-06-22 23:44:52 +0530 | [diff] [blame] | 179 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" |
Mark Levedahl | 19a31f9 | 2008-08-10 19:10:04 -0400 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | # |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 183 | # Register submodules in .git/config |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 184 | # |
| 185 | # $@ = requested paths (default to all) |
| 186 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 187 | cmd_init() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 188 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 189 | # parse $args after "submodule ... init". |
| 190 | while test $# -ne 0 |
| 191 | do |
| 192 | case "$1" in |
| 193 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 194 | GIT_QUIET=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 195 | ;; |
| 196 | --) |
| 197 | shift |
| 198 | break |
| 199 | ;; |
| 200 | -*) |
| 201 | usage |
| 202 | ;; |
| 203 | *) |
| 204 | break |
| 205 | ;; |
| 206 | esac |
| 207 | shift |
| 208 | done |
| 209 | |
Nguyễn Thái Ngọc Duy | a282f5a | 2019-04-12 17:08:19 +0700 | [diff] [blame] | 210 | git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | # |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 214 | # Unregister submodules from .git/config and remove their work tree |
| 215 | # |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 216 | cmd_deinit() |
| 217 | { |
| 218 | # parse $args after "submodule ... deinit". |
Stefan Beller | f6a5279 | 2016-05-05 12:52:32 -0700 | [diff] [blame] | 219 | deinit_all= |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 220 | while test $# -ne 0 |
| 221 | do |
| 222 | case "$1" in |
| 223 | -f|--force) |
| 224 | force=$1 |
| 225 | ;; |
| 226 | -q|--quiet) |
| 227 | GIT_QUIET=1 |
| 228 | ;; |
Stefan Beller | f6a5279 | 2016-05-05 12:52:32 -0700 | [diff] [blame] | 229 | --all) |
| 230 | deinit_all=t |
| 231 | ;; |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 232 | --) |
| 233 | shift |
| 234 | break |
| 235 | ;; |
| 236 | -*) |
| 237 | usage |
| 238 | ;; |
| 239 | *) |
| 240 | break |
| 241 | ;; |
| 242 | esac |
| 243 | shift |
| 244 | done |
| 245 | |
Kaartic Sivaraam | 1cf823d | 2021-06-22 23:44:52 +0530 | [diff] [blame] | 246 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@" |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 247 | } |
| 248 | |
Jeff King | 66d36b9 | 2020-11-24 04:06:05 -0500 | [diff] [blame] | 249 | # usage: fetch_in_submodule <module_path> [<depth>] [<sha1>] |
| 250 | # Because arguments are positional, use an empty string to omit <depth> |
| 251 | # but include <sha1>. |
Stefan Beller | fb43e31 | 2016-02-23 19:32:13 -0800 | [diff] [blame] | 252 | fetch_in_submodule () ( |
Junio C Hamano | 01e1d54 | 2016-04-06 11:39:12 -0700 | [diff] [blame] | 253 | sanitize_submodule_env && |
Stefan Beller | fb43e31 | 2016-02-23 19:32:13 -0800 | [diff] [blame] | 254 | cd "$1" && |
Ævar Arnfjörð Bjarmason | 1c15180 | 2020-11-14 13:21:30 +0100 | [diff] [blame] | 255 | if test $# -eq 3 |
| 256 | then |
Nicholas Clark | 62af4bd | 2021-04-30 09:59:06 +0000 | [diff] [blame] | 257 | echo "$3" | git fetch ${GIT_QUIET:+--quiet} --stdin ${2:+"$2"} |
Ævar Arnfjörð Bjarmason | 1c15180 | 2020-11-14 13:21:30 +0100 | [diff] [blame] | 258 | else |
Nicholas Clark | 62af4bd | 2021-04-30 09:59:06 +0000 | [diff] [blame] | 259 | git fetch ${GIT_QUIET:+--quiet} ${2:+"$2"} |
Ævar Arnfjörð Bjarmason | 1c15180 | 2020-11-14 13:21:30 +0100 | [diff] [blame] | 260 | fi |
Stefan Beller | fb43e31 | 2016-02-23 19:32:13 -0800 | [diff] [blame] | 261 | ) |
| 262 | |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 263 | # |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 264 | # 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] | 265 | # |
| 266 | # $@ = requested paths (default to all) |
| 267 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 268 | cmd_update() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 269 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 270 | # parse $args after "submodule ... update". |
| 271 | while test $# -ne 0 |
| 272 | do |
| 273 | case "$1" in |
| 274 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 275 | GIT_QUIET=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 276 | ;; |
Stefan Beller | e84c3cf | 2018-08-14 11:22:02 -0700 | [diff] [blame] | 277 | -v) |
Theodore Dubois | 3ad0401 | 2020-09-30 12:50:53 -0700 | [diff] [blame] | 278 | unset GIT_QUIET |
Stefan Beller | e84c3cf | 2018-08-14 11:22:02 -0700 | [diff] [blame] | 279 | ;; |
Jeff King | 72c5f88 | 2016-09-22 01:24:46 -0400 | [diff] [blame] | 280 | --progress) |
Casey Fitzpatrick | c7199e3 | 2018-05-03 06:53:44 -0400 | [diff] [blame] | 281 | progress=1 |
Jeff King | 72c5f88 | 2016-09-22 01:24:46 -0400 | [diff] [blame] | 282 | ;; |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 283 | -i|--init) |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 284 | init=1 |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 285 | ;; |
Johannes Schindelin | 0060fd1 | 2019-09-12 14:20:39 +0200 | [diff] [blame] | 286 | --require-init) |
| 287 | init=1 |
| 288 | require_init=1 |
| 289 | ;; |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 290 | --remote) |
| 291 | remote=1 |
| 292 | ;; |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 293 | -N|--no-fetch) |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 294 | nofetch=1 |
| 295 | ;; |
Nicolas Morey-Chaisemartin | 9db31bd | 2011-04-01 11:42:03 +0200 | [diff] [blame] | 296 | -f|--force) |
| 297 | force=$1 |
| 298 | ;; |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 299 | -r|--rebase) |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 300 | update="rebase" |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 301 | ;; |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 302 | --reference) |
| 303 | case "$2" in '') usage ;; esac |
| 304 | reference="--reference=$2" |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 305 | shift |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 306 | ;; |
| 307 | --reference=*) |
| 308 | reference="$1" |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 309 | ;; |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 310 | --dissociate) |
| 311 | dissociate=1 |
| 312 | ;; |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 313 | -m|--merge) |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 314 | update="merge" |
| 315 | ;; |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 316 | --recursive) |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 317 | recursive=1 |
| 318 | ;; |
Junio C Hamano | efc5fb6 | 2011-10-10 15:56:16 -0700 | [diff] [blame] | 319 | --checkout) |
| 320 | update="checkout" |
| 321 | ;; |
Stefan Beller | abed000 | 2016-05-26 14:59:43 -0700 | [diff] [blame] | 322 | --recommend-shallow) |
| 323 | recommend_shallow="--recommend-shallow" |
| 324 | ;; |
| 325 | --no-recommend-shallow) |
| 326 | recommend_shallow="--no-recommend-shallow" |
| 327 | ;; |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 328 | --depth) |
| 329 | case "$2" in '') usage ;; esac |
| 330 | depth="--depth=$2" |
| 331 | shift |
| 332 | ;; |
| 333 | --depth=*) |
| 334 | depth=$1 |
| 335 | ;; |
Stefan Beller | 2335b87 | 2016-02-29 18:07:19 -0800 | [diff] [blame] | 336 | -j|--jobs) |
| 337 | case "$2" in '') usage ;; esac |
| 338 | jobs="--jobs=$2" |
| 339 | shift |
| 340 | ;; |
| 341 | --jobs=*) |
| 342 | jobs=$1 |
| 343 | ;; |
Emily Shaffer | 132f600 | 2020-02-20 19:10:27 -0800 | [diff] [blame] | 344 | --single-branch) |
| 345 | single_branch="--single-branch" |
| 346 | ;; |
| 347 | --no-single-branch) |
| 348 | single_branch="--no-single-branch" |
| 349 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 350 | --) |
| 351 | shift |
| 352 | break |
| 353 | ;; |
| 354 | -*) |
| 355 | usage |
| 356 | ;; |
| 357 | *) |
| 358 | break |
| 359 | ;; |
| 360 | esac |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 361 | shift |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 362 | done |
| 363 | |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 364 | if test -n "$init" |
| 365 | then |
| 366 | cmd_init "--" "$@" || return |
| 367 | fi |
| 368 | |
Stefan Beller | 4830868 | 2016-02-29 18:07:17 -0800 | [diff] [blame] | 369 | { |
| 370 | git submodule--helper update-clone ${GIT_QUIET:+--quiet} \ |
Casey Fitzpatrick | c7199e3 | 2018-05-03 06:53:44 -0400 | [diff] [blame] | 371 | ${progress:+"--progress"} \ |
Stefan Beller | 4830868 | 2016-02-29 18:07:17 -0800 | [diff] [blame] | 372 | ${wt_prefix:+--prefix "$wt_prefix"} \ |
| 373 | ${prefix:+--recursive-prefix "$prefix"} \ |
| 374 | ${update:+--update "$update"} \ |
Stefan Beller | 5f50f33 | 2016-08-11 16:14:01 -0700 | [diff] [blame] | 375 | ${reference:+"$reference"} \ |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 376 | ${dissociate:+"--dissociate"} \ |
Stefan Beller | 4830868 | 2016-02-29 18:07:17 -0800 | [diff] [blame] | 377 | ${depth:+--depth "$depth"} \ |
Johannes Schindelin | 0060fd1 | 2019-09-12 14:20:39 +0200 | [diff] [blame] | 378 | ${require_init:+--require-init} \ |
Emily Shaffer | 132f600 | 2020-02-20 19:10:27 -0800 | [diff] [blame] | 379 | $single_branch \ |
Casey Fitzpatrick | c7199e3 | 2018-05-03 06:53:44 -0400 | [diff] [blame] | 380 | $recommend_shallow \ |
| 381 | $jobs \ |
Nguyễn Thái Ngọc Duy | a282f5a | 2019-04-12 17:08:19 +0700 | [diff] [blame] | 382 | -- \ |
Johannes Sixt | c4c02bf | 2016-07-22 21:14:38 +0200 | [diff] [blame] | 383 | "$@" || echo "#unmatched" $? |
Stefan Beller | 4830868 | 2016-02-29 18:07:17 -0800 | [diff] [blame] | 384 | } | { |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 385 | err= |
Stefan Beller | 9eca701 | 2018-08-03 15:23:17 -0700 | [diff] [blame] | 386 | while read -r quickabort sha1 just_cloned sm_path |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 387 | do |
Stefan Beller | 9eca701 | 2018-08-03 15:23:17 -0700 | [diff] [blame] | 388 | die_if_unmatched "$quickabort" "$sha1" |
Stefan Beller | 4830868 | 2016-02-29 18:07:17 -0800 | [diff] [blame] | 389 | |
Stefan Beller | 5d124f4 | 2019-01-18 13:55:19 -0800 | [diff] [blame] | 390 | git submodule--helper ensure-core-worktree "$sm_path" || exit 1 |
Stefan Beller | 74d4731 | 2018-08-13 15:42:34 -0700 | [diff] [blame] | 391 | |
Stefan Beller | 44431df | 2016-05-31 17:27:59 -0700 | [diff] [blame] | 392 | displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 393 | |
Stefan Beller | 4830868 | 2016-02-29 18:07:17 -0800 | [diff] [blame] | 394 | if test $just_cloned -eq 1 |
Junio C Hamano | d851ffb | 2014-04-02 14:15:36 -0700 | [diff] [blame] | 395 | then |
Lars Hjemli | bf2d824 | 2007-06-11 21:12:22 +0200 | [diff] [blame] | 396 | subsha1= |
| 397 | else |
Atharva Raykar | c51f8f9 | 2021-08-24 19:36:09 +0530 | [diff] [blame] | 398 | just_cloned= |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 399 | subsha1=$(sanitize_submodule_env; cd "$sm_path" && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 400 | git rev-parse --verify HEAD) || |
Atharva Raykar | 0008d12 | 2021-07-10 13:17:59 +0530 | [diff] [blame] | 401 | die "fatal: $(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")" |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 402 | fi |
| 403 | |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 404 | if test -n "$remote" |
| 405 | then |
Stefan Beller | 92bbe7c | 2016-08-03 13:44:03 -0700 | [diff] [blame] | 406 | branch=$(git submodule--helper remote-branch "$sm_path") |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 407 | if test -z "$nofetch" |
| 408 | then |
| 409 | # Fetch remote before determining tracking $sha1 |
Stefan Beller | 6cbf454 | 2016-07-28 17:44:04 -0700 | [diff] [blame] | 410 | fetch_in_submodule "$sm_path" $depth || |
Atharva Raykar | 0008d12 | 2021-07-10 13:17:59 +0530 | [diff] [blame] | 411 | die "fatal: $(eval_gettext "Unable to fetch in submodule path '\$sm_path'")" |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 412 | fi |
Ævar Arnfjörð Bjarmason | e63f7b0 | 2020-11-14 13:21:31 +0100 | [diff] [blame] | 413 | remote_name=$(sanitize_submodule_env; cd "$sm_path" && git submodule--helper print-default-remote) |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 414 | sha1=$(sanitize_submodule_env; cd "$sm_path" && |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 415 | git rev-parse --verify "${remote_name}/${branch}") || |
Atharva Raykar | 0008d12 | 2021-07-10 13:17:59 +0530 | [diff] [blame] | 416 | die "fatal: $(eval_gettext "Unable to find current \${remote_name}/\${branch} revision in submodule path '\$sm_path'")" |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 417 | fi |
| 418 | |
Atharva Raykar | c51f8f9 | 2021-08-24 19:36:09 +0530 | [diff] [blame] | 419 | out=$(git submodule--helper run-update-procedure \ |
| 420 | ${wt_prefix:+--prefix "$wt_prefix"} \ |
| 421 | ${GIT_QUIET:+--quiet} \ |
| 422 | ${force:+--force} \ |
| 423 | ${just_cloned:+--just-cloned} \ |
| 424 | ${nofetch:+--no-fetch} \ |
| 425 | ${depth:+"$depth"} \ |
| 426 | ${update:+--update "$update"} \ |
| 427 | ${prefix:+--recursive-prefix "$prefix"} \ |
| 428 | ${sha1:+--oid "$sha1"} \ |
| 429 | ${subsha1:+--suboid "$subsha1"} \ |
| 430 | "--" \ |
| 431 | "$sm_path") |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 432 | |
Atharva Raykar | c51f8f9 | 2021-08-24 19:36:09 +0530 | [diff] [blame] | 433 | # exit codes for run-update-procedure: |
| 434 | # 0: update was successful, say command output |
| 435 | # 1: update procedure failed, but should not die |
| 436 | # 2 or 128: subcommand died during execution |
| 437 | # 3: no update procedure was run |
| 438 | res="$?" |
| 439 | case $res in |
| 440 | 0) |
| 441 | say "$out" |
| 442 | ;; |
| 443 | 1) |
| 444 | err="${err};fatal: $out" |
| 445 | continue |
| 446 | ;; |
| 447 | 2|128) |
| 448 | die_with_status $res "fatal: $out" |
| 449 | ;; |
| 450 | esac |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 451 | |
| 452 | if test -n "$recursive" |
| 453 | then |
William Entriken | 75bf5e6 | 2013-03-02 14:44:59 -0500 | [diff] [blame] | 454 | ( |
Stefan Beller | 44431df | 2016-05-31 17:27:59 -0700 | [diff] [blame] | 455 | prefix=$(git submodule--helper relative-path "$prefix$sm_path/" "$wt_prefix") |
Stefan Beller | 3604242 | 2016-04-15 17:50:13 -0700 | [diff] [blame] | 456 | wt_prefix= |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 457 | sanitize_submodule_env |
William Entriken | 75bf5e6 | 2013-03-02 14:44:59 -0500 | [diff] [blame] | 458 | cd "$sm_path" && |
Jens Lehmann | 3614128 | 2013-11-11 21:55:52 +0100 | [diff] [blame] | 459 | eval cmd_update |
William Entriken | 75bf5e6 | 2013-03-02 14:44:59 -0500 | [diff] [blame] | 460 | ) |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 461 | res=$? |
| 462 | if test $res -gt 0 |
| 463 | then |
Atharva Raykar | 0008d12 | 2021-07-10 13:17:59 +0530 | [diff] [blame] | 464 | die_msg="fatal: $(eval_gettext "Failed to recurse into submodule path '\$displaypath'")" |
Stefan Beller | bb9d91b | 2016-06-09 12:06:37 -0700 | [diff] [blame] | 465 | if test $res -ne 2 |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 466 | then |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 467 | err="${err};$die_msg" |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 468 | continue |
| 469 | else |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 470 | die_with_status $res "$die_msg" |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 471 | fi |
| 472 | fi |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 473 | fi |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 474 | done |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 475 | |
| 476 | if test -n "$err" |
| 477 | then |
| 478 | OIFS=$IFS |
| 479 | IFS=';' |
| 480 | for e in $err |
| 481 | do |
| 482 | if test -n "$e" |
| 483 | then |
| 484 | echo >&2 "$e" |
| 485 | fi |
| 486 | done |
| 487 | IFS=$OIFS |
| 488 | exit 1 |
| 489 | fi |
| 490 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 491 | } |
| 492 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 493 | # |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 494 | # Configures a submodule's default branch |
| 495 | # |
| 496 | # $@ = requested path |
| 497 | # |
| 498 | cmd_set_branch() { |
Shourya Shukla | 2964d6e | 2020-06-02 22:05:23 +0530 | [diff] [blame] | 499 | default= |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 500 | branch= |
| 501 | |
| 502 | while test $# -ne 0 |
| 503 | do |
| 504 | case "$1" in |
| 505 | -q|--quiet) |
| 506 | # we don't do anything with this but we need to accept it |
| 507 | ;; |
| 508 | -d|--default) |
Shourya Shukla | 2964d6e | 2020-06-02 22:05:23 +0530 | [diff] [blame] | 509 | default=1 |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 510 | ;; |
| 511 | -b|--branch) |
| 512 | case "$2" in '') usage ;; esac |
| 513 | branch=$2 |
| 514 | shift |
| 515 | ;; |
| 516 | --) |
| 517 | shift |
| 518 | break |
| 519 | ;; |
| 520 | -*) |
| 521 | usage |
| 522 | ;; |
| 523 | *) |
| 524 | break |
| 525 | ;; |
| 526 | esac |
| 527 | shift |
| 528 | done |
| 529 | |
Kaartic Sivaraam | 1cf823d | 2021-06-22 23:44:52 +0530 | [diff] [blame] | 530 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${GIT_QUIET:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@" |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | # |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 534 | # Configures a submodule's remote url |
| 535 | # |
| 536 | # $@ = requested path, requested url |
| 537 | # |
| 538 | cmd_set_url() { |
| 539 | while test $# -ne 0 |
| 540 | do |
| 541 | case "$1" in |
| 542 | -q|--quiet) |
| 543 | GIT_QUIET=1 |
| 544 | ;; |
| 545 | --) |
| 546 | shift |
| 547 | break |
| 548 | ;; |
| 549 | -*) |
| 550 | usage |
| 551 | ;; |
| 552 | *) |
| 553 | break |
| 554 | ;; |
| 555 | esac |
| 556 | shift |
| 557 | done |
| 558 | |
Kaartic Sivaraam | 1cf823d | 2021-06-22 23:44:52 +0530 | [diff] [blame] | 559 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@" |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | # |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 563 | # Show commit summary for submodules in index or working tree |
| 564 | # |
| 565 | # If '--cached' is given, show summary between index and given commit, |
| 566 | # or between working tree and given commit |
| 567 | # |
| 568 | # $@ = [commit (default 'HEAD'),] requested paths (default all) |
| 569 | # |
| 570 | cmd_summary() { |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 571 | summary_limit=-1 |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 572 | for_status= |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 573 | diff_cmd=diff-index |
Emil Medve | bffe71f | 2007-06-26 18:40:58 -0500 | [diff] [blame] | 574 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 575 | # parse $args after "submodule ... summary". |
| 576 | while test $# -ne 0 |
| 577 | do |
| 578 | case "$1" in |
| 579 | --cached) |
| 580 | cached="$1" |
| 581 | ;; |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 582 | --files) |
| 583 | files="$1" |
| 584 | ;; |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 585 | --for-status) |
| 586 | for_status="$1" |
| 587 | ;; |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 588 | -n|--summary-limit) |
René Scharfe | 862ae6c | 2013-04-01 15:06:27 +0200 | [diff] [blame] | 589 | summary_limit="$2" |
| 590 | isnumber "$summary_limit" || usage |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 591 | shift |
| 592 | ;; |
René Scharfe | 862ae6c | 2013-04-01 15:06:27 +0200 | [diff] [blame] | 593 | --summary-limit=*) |
| 594 | summary_limit="${1#--summary-limit=}" |
| 595 | isnumber "$summary_limit" || usage |
| 596 | ;; |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 597 | --) |
| 598 | shift |
| 599 | break |
| 600 | ;; |
| 601 | -*) |
| 602 | usage |
| 603 | ;; |
| 604 | *) |
| 605 | break |
| 606 | ;; |
| 607 | esac |
| 608 | shift |
| 609 | done |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 610 | |
Kaartic Sivaraam | 1cf823d | 2021-06-22 23:44:52 +0530 | [diff] [blame] | 611 | 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] | 612 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 613 | # |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 614 | # List all submodules, prefixed with: |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 615 | # - submodule not initialized |
| 616 | # + different revision checked out |
| 617 | # |
| 618 | # If --cached was specified the revision in the index will be printed |
| 619 | # instead of the currently checked out revision. |
| 620 | # |
| 621 | # $@ = requested paths (default to all) |
| 622 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 623 | cmd_status() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 624 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 625 | # parse $args after "submodule ... status". |
| 626 | while test $# -ne 0 |
| 627 | do |
| 628 | case "$1" in |
| 629 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 630 | GIT_QUIET=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 631 | ;; |
| 632 | --cached) |
| 633 | cached=1 |
| 634 | ;; |
Johan Herland | 64b19ff | 2009-08-19 03:45:24 +0200 | [diff] [blame] | 635 | --recursive) |
| 636 | recursive=1 |
| 637 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 638 | --) |
| 639 | shift |
| 640 | break |
| 641 | ;; |
| 642 | -*) |
| 643 | usage |
| 644 | ;; |
| 645 | *) |
| 646 | break |
| 647 | ;; |
| 648 | esac |
| 649 | shift |
| 650 | done |
| 651 | |
Kaartic Sivaraam | 1cf823d | 2021-06-22 23:44:52 +0530 | [diff] [blame] | 652 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 653 | } |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 654 | # |
| 655 | # Sync remote urls for submodules |
| 656 | # This makes the value for remote.$remote.url match the value |
| 657 | # specified in .gitmodules. |
| 658 | # |
| 659 | cmd_sync() |
| 660 | { |
| 661 | while test $# -ne 0 |
| 662 | do |
| 663 | case "$1" in |
| 664 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 665 | GIT_QUIET=1 |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 666 | shift |
| 667 | ;; |
Phil Hord | 82f49f2 | 2012-10-26 15:44:42 -0400 | [diff] [blame] | 668 | --recursive) |
| 669 | recursive=1 |
| 670 | shift |
| 671 | ;; |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 672 | --) |
| 673 | shift |
| 674 | break |
| 675 | ;; |
| 676 | -*) |
| 677 | usage |
| 678 | ;; |
| 679 | *) |
| 680 | break |
| 681 | ;; |
| 682 | esac |
| 683 | done |
Brandon Williams | e7849a9 | 2017-03-16 15:29:45 -0700 | [diff] [blame] | 684 | |
Kaartic Sivaraam | 1cf823d | 2021-06-22 23:44:52 +0530 | [diff] [blame] | 685 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 686 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 687 | |
Stefan Beller | f6f8586 | 2016-12-12 11:04:35 -0800 | [diff] [blame] | 688 | cmd_absorbgitdirs() |
| 689 | { |
| 690 | git submodule--helper absorb-git-dirs --prefix "$wt_prefix" "$@" |
| 691 | } |
| 692 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 693 | # This loop parses the command line arguments to find the |
| 694 | # subcommand name to dispatch. Parsing of the subcommand specific |
| 695 | # options are primarily done by the subcommand implementations. |
| 696 | # Subcommand specific options such as --branch and --cached are |
| 697 | # parsed here as well, for backward compatibility. |
| 698 | |
| 699 | while test $# != 0 && test -z "$command" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 700 | do |
| 701 | case "$1" in |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 702 | 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] | 703 | command=$1 |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 704 | ;; |
| 705 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 706 | GIT_QUIET=1 |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 707 | ;; |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 708 | -b|--branch) |
| 709 | case "$2" in |
| 710 | '') |
| 711 | usage |
| 712 | ;; |
| 713 | esac |
| 714 | branch="$2"; shift |
| 715 | ;; |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 716 | --cached) |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 717 | cached="$1" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 718 | ;; |
| 719 | --) |
| 720 | break |
| 721 | ;; |
| 722 | -*) |
| 723 | usage |
| 724 | ;; |
| 725 | *) |
| 726 | break |
| 727 | ;; |
| 728 | esac |
| 729 | shift |
| 730 | done |
| 731 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 732 | # No command word defaults to "status" |
Ramkumar Ramachandra | af9c9f9 | 2012-09-22 16:57:59 +0530 | [diff] [blame] | 733 | if test -z "$command" |
| 734 | then |
| 735 | if test $# = 0 |
| 736 | then |
| 737 | command=status |
| 738 | else |
| 739 | usage |
| 740 | fi |
| 741 | fi |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 742 | |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 743 | # "-b branch" is accepted only by "add" and "set-branch" |
| 744 | if test -n "$branch" && (test "$command" != add || test "$command" != set-branch) |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 745 | then |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 746 | usage |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 747 | fi |
| 748 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 749 | # "--cached" is accepted only by "status" and "summary" |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 750 | if test -n "$cached" && test "$command" != status && test "$command" != summary |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 751 | then |
| 752 | usage |
| 753 | fi |
| 754 | |
Denton Liu | b57e811 | 2019-02-08 03:21:34 -0800 | [diff] [blame] | 755 | "cmd_$(echo $command | sed -e s/-/_/g)" "$@" |