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>...) |
Stefan Beller | abed000 | 2016-05-26 14:59:43 -0700 | [diff] [blame] | 13 | or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...] |
Junio C Hamano | adc5423 | 2009-08-27 16:59:25 -0700 | [diff] [blame] | 14 | or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...] |
Johan Herland | 15fc56a | 2009-08-19 03:45:22 +0200 | [diff] [blame] | 15 | or: $dashless [--quiet] foreach [--recursive] <command> |
Stefan Beller | c32eaa8 | 2017-01-11 12:59:17 -0800 | [diff] [blame] | 16 | or: $dashless [--quiet] sync [--recursive] [--] [<path>...] |
| 17 | or: $dashless [--quiet] absorbgitdirs [--] [<path>...]" |
Junio C Hamano | 8f321a3 | 2007-11-06 01:50:02 -0800 | [diff] [blame] | 18 | OPTIONS_SPEC= |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 19 | SUBDIRECTORY_OK=Yes |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 20 | . git-sh-setup |
Mark Levedahl | 98fcf84 | 2008-08-24 14:46:10 -0400 | [diff] [blame] | 21 | . git-parse-remote |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 22 | require_work_tree |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 23 | wt_prefix=$(git rev-parse --show-prefix) |
| 24 | cd_to_toplevel |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 25 | |
Brandon Williams | f1762d7 | 2016-12-14 14:39:52 -0800 | [diff] [blame] | 26 | # Tell the rest of git that any URLs we get don't come |
| 27 | # directly from the user, so it can apply policy as appropriate. |
| 28 | GIT_PROTOCOL_FROM_USER=0 |
| 29 | export GIT_PROTOCOL_FROM_USER |
Jeff King | 33cfccb | 2015-09-16 13:13:12 -0400 | [diff] [blame] | 30 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 31 | command= |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 32 | branch= |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 33 | force= |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 34 | reference= |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 35 | cached= |
Gerrit Pape | 48bb303 | 2010-04-26 11:50:39 +0200 | [diff] [blame] | 36 | recursive= |
| 37 | init= |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 38 | files= |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 39 | remote= |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 40 | nofetch= |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 41 | update= |
Johan Herland | 15fc56a | 2009-08-19 03:45:22 +0200 | [diff] [blame] | 42 | prefix= |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 43 | custom_name= |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 44 | depth= |
Jeff King | 72c5f88 | 2016-09-22 01:24:46 -0400 | [diff] [blame] | 45 | progress= |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 46 | dissociate= |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 47 | |
Heiko Voigt | be9d0a3 | 2012-08-14 22:35:27 +0200 | [diff] [blame] | 48 | die_if_unmatched () |
| 49 | { |
| 50 | if test "$1" = "#unmatched" |
| 51 | then |
Johannes Sixt | c4c02bf | 2016-07-22 21:14:38 +0200 | [diff] [blame] | 52 | exit ${2:-1} |
Heiko Voigt | be9d0a3 | 2012-08-14 22:35:27 +0200 | [diff] [blame] | 53 | fi |
| 54 | } |
| 55 | |
David Aguilar | a7b3269 | 2008-08-22 00:30:50 -0700 | [diff] [blame] | 56 | # |
W. Trevor King | 88ce00c | 2012-12-11 13:58:15 -0500 | [diff] [blame] | 57 | # Print a submodule configuration setting |
| 58 | # |
| 59 | # $1 = submodule name |
| 60 | # $2 = option name |
| 61 | # $3 = default value |
| 62 | # |
| 63 | # Checks in the usual git-config places first (for overrides), |
| 64 | # otherwise it falls back on .gitmodules. This allows you to |
| 65 | # distribute project-wide defaults in .gitmodules, while still |
| 66 | # customizing individual repositories if necessary. If the option is |
| 67 | # not in .gitmodules either, print a default value. |
| 68 | # |
| 69 | get_submodule_config () { |
| 70 | name="$1" |
| 71 | option="$2" |
| 72 | default="$3" |
| 73 | value=$(git config submodule."$name"."$option") |
| 74 | if test -z "$value" |
| 75 | then |
Antonio Ospite | b2faad4 | 2018-10-05 15:05:57 +0200 | [diff] [blame] | 76 | value=$(git submodule--helper config submodule."$name"."$option") |
W. Trevor King | 88ce00c | 2012-12-11 13:58:15 -0500 | [diff] [blame] | 77 | fi |
| 78 | printf '%s' "${value:-$default}" |
| 79 | } |
| 80 | |
René Scharfe | 862ae6c | 2013-04-01 15:06:27 +0200 | [diff] [blame] | 81 | isnumber() |
| 82 | { |
| 83 | n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1" |
| 84 | } |
| 85 | |
brian m. carlson | dda6346 | 2018-10-15 00:02:01 +0000 | [diff] [blame] | 86 | # Given a full hex object ID, is this the zero OID? |
| 87 | is_zero_oid () { |
| 88 | echo "$1" | sane_egrep '^0+$' >/dev/null 2>&1 |
| 89 | } |
| 90 | |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 91 | # Sanitize the local git environment for use within a submodule. We |
| 92 | # can't simply use clear_local_git_env since we want to preserve some |
| 93 | # of the settings from GIT_CONFIG_PARAMETERS. |
| 94 | sanitize_submodule_env() |
| 95 | { |
Jeff King | 89044ba | 2016-05-04 21:22:19 -0400 | [diff] [blame] | 96 | save_config=$GIT_CONFIG_PARAMETERS |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 97 | clear_local_git_env |
Jeff King | 89044ba | 2016-05-04 21:22:19 -0400 | [diff] [blame] | 98 | GIT_CONFIG_PARAMETERS=$save_config |
Jeff King | 860cba6 | 2016-04-28 09:37:44 -0400 | [diff] [blame] | 99 | export GIT_CONFIG_PARAMETERS |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 102 | # |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 103 | # Add a new submodule to the working tree, .gitmodules and the index |
| 104 | # |
Mark Levedahl | ec05df3 | 2008-07-09 21:05:40 -0400 | [diff] [blame] | 105 | # $@ = repo path |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 106 | # |
| 107 | # optional branch is stored in global branch variable |
| 108 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 109 | cmd_add() |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 110 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 111 | # parse $args after "submodule ... add". |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 112 | reference_path= |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 113 | while test $# -ne 0 |
| 114 | do |
| 115 | case "$1" in |
| 116 | -b | --branch) |
| 117 | case "$2" in '') usage ;; esac |
| 118 | branch=$2 |
| 119 | shift |
| 120 | ;; |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 121 | -f | --force) |
| 122 | force=$1 |
| 123 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 124 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 125 | GIT_QUIET=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 126 | ;; |
Casey Fitzpatrick | 6d33e1c | 2018-05-03 06:53:45 -0400 | [diff] [blame] | 127 | --progress) |
| 128 | progress=1 |
| 129 | ;; |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 130 | --reference) |
| 131 | case "$2" in '') usage ;; esac |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 132 | reference_path=$2 |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 133 | shift |
| 134 | ;; |
| 135 | --reference=*) |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 136 | reference_path="${1#--reference=}" |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 137 | ;; |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 138 | --dissociate) |
| 139 | dissociate=1 |
| 140 | ;; |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 141 | --name) |
| 142 | case "$2" in '') usage ;; esac |
| 143 | custom_name=$2 |
| 144 | shift |
| 145 | ;; |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 146 | --depth) |
| 147 | case "$2" in '') usage ;; esac |
| 148 | depth="--depth=$2" |
| 149 | shift |
| 150 | ;; |
| 151 | --depth=*) |
| 152 | depth=$1 |
| 153 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 154 | --) |
| 155 | shift |
| 156 | break |
| 157 | ;; |
| 158 | -*) |
| 159 | usage |
| 160 | ;; |
| 161 | *) |
| 162 | break |
| 163 | ;; |
| 164 | esac |
| 165 | shift |
| 166 | done |
| 167 | |
Antonio Ospite | 76e9bdc | 2018-10-25 18:18:12 +0200 | [diff] [blame] | 168 | if ! git submodule--helper config --check-writeable >/dev/null 2>&1 |
| 169 | then |
| 170 | die "$(eval_gettext "please make sure that the .gitmodules file is in the working tree")" |
| 171 | fi |
| 172 | |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 173 | if test -n "$reference_path" |
| 174 | then |
| 175 | is_absolute_path "$reference_path" || |
| 176 | reference_path="$wt_prefix$reference_path" |
| 177 | |
| 178 | reference="--reference=$reference_path" |
| 179 | fi |
| 180 | |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 181 | repo=$1 |
Ramsay Jones | 64394e3 | 2012-04-17 19:00:58 +0100 | [diff] [blame] | 182 | sm_path=$2 |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 183 | |
Ramsay Jones | 64394e3 | 2012-04-17 19:00:58 +0100 | [diff] [blame] | 184 | if test -z "$sm_path"; then |
Junio C Hamano | 6a06623 | 2014-06-10 08:33:39 -0700 | [diff] [blame] | 185 | sm_path=$(printf '%s\n' "$repo" | |
Jens Lehmann | 1414e57 | 2009-09-22 17:10:12 +0200 | [diff] [blame] | 186 | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g') |
| 187 | fi |
| 188 | |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 189 | if test -z "$repo" || test -z "$sm_path"; then |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 190 | usage |
| 191 | fi |
| 192 | |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 193 | is_absolute_path "$sm_path" || sm_path="$wt_prefix$sm_path" |
| 194 | |
Mark Levedahl | ec05df3 | 2008-07-09 21:05:40 -0400 | [diff] [blame] | 195 | # assure repo is absolute or relative to parent |
| 196 | case "$repo" in |
| 197 | ./*|../*) |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 198 | test -z "$wt_prefix" || |
| 199 | die "$(gettext "Relative path can only be used from the toplevel of the working tree")" |
| 200 | |
Mark Levedahl | ec05df3 | 2008-07-09 21:05:40 -0400 | [diff] [blame] | 201 | # dereference source url relative to parent's url |
Stefan Beller | 63e95be | 2016-04-15 17:50:12 -0700 | [diff] [blame] | 202 | realrepo=$(git submodule--helper resolve-relative-url "$repo") || exit |
Mark Levedahl | ec05df3 | 2008-07-09 21:05:40 -0400 | [diff] [blame] | 203 | ;; |
| 204 | *:*|/*) |
| 205 | # absolute url |
| 206 | realrepo=$repo |
| 207 | ;; |
| 208 | *) |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 209 | die "$(eval_gettext "repo URL: '\$repo' must be absolute or begin with ./|../")" |
Mark Levedahl | ec05df3 | 2008-07-09 21:05:40 -0400 | [diff] [blame] | 210 | ;; |
| 211 | esac |
| 212 | |
Michael J Gruber | db75ada | 2009-03-03 16:08:21 +0100 | [diff] [blame] | 213 | # normalize path: |
| 214 | # multiple //; leading ./; /./; /../; trailing / |
Ramsay Jones | 64394e3 | 2012-04-17 19:00:58 +0100 | [diff] [blame] | 215 | sm_path=$(printf '%s/\n' "$sm_path" | |
Michael J Gruber | db75ada | 2009-03-03 16:08:21 +0100 | [diff] [blame] | 216 | sed -e ' |
| 217 | s|//*|/|g |
| 218 | s|^\(\./\)*|| |
Patrick Steinhardt | 8196e72 | 2015-01-30 16:14:03 +0100 | [diff] [blame] | 219 | s|/\(\./\)*|/|g |
Michael J Gruber | db75ada | 2009-03-03 16:08:21 +0100 | [diff] [blame] | 220 | :start |
| 221 | s|\([^/]*\)/\.\./|| |
| 222 | tstart |
| 223 | s|/*$|| |
| 224 | ') |
Stefan Beller | 619acfc | 2016-10-06 12:37:24 -0700 | [diff] [blame] | 225 | if test -z "$force" |
| 226 | then |
| 227 | git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 && |
| 228 | die "$(eval_gettext "'\$sm_path' already exists in the index")" |
| 229 | else |
| 230 | git ls-files -s "$sm_path" | sane_grep -v "^160000" > /dev/null 2>&1 && |
| 231 | die "$(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")" |
| 232 | fi |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 233 | |
Jeff King | 5321399 | 2017-06-14 06:58:22 -0400 | [diff] [blame] | 234 | if test -z "$force" && |
| 235 | ! git add --dry-run --ignore-missing --no-warn-embedded-repo "$sm_path" > /dev/null 2>&1 |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 236 | then |
Jon Seymour | 6ff875c | 2011-08-07 21:58:17 +1000 | [diff] [blame] | 237 | eval_gettextln "The following path is ignored by one of your .gitignore files: |
Ramsay Jones | 64394e3 | 2012-04-17 19:00:58 +0100 | [diff] [blame] | 238 | \$sm_path |
Jon Seymour | 6ff875c | 2011-08-07 21:58:17 +1000 | [diff] [blame] | 239 | Use -f if you really want to add it." >&2 |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 240 | exit 1 |
| 241 | fi |
| 242 | |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 243 | if test -n "$custom_name" |
| 244 | then |
| 245 | sm_name="$custom_name" |
| 246 | else |
| 247 | sm_name="$sm_path" |
| 248 | fi |
| 249 | |
Jeff King | 0383bbb | 2018-04-30 03:25:25 -0400 | [diff] [blame] | 250 | if ! git submodule--helper check-name "$sm_name" |
| 251 | then |
| 252 | die "$(eval_gettext "'$sm_name' is not a valid submodule name")" |
| 253 | fi |
| 254 | |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 255 | # perhaps the path exists and is already a git repo, else clone it |
Ramsay Jones | 64394e3 | 2012-04-17 19:00:58 +0100 | [diff] [blame] | 256 | if test -e "$sm_path" |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 257 | then |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 258 | if test -d "$sm_path"/.git || test -f "$sm_path"/.git |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 259 | then |
Ramsay Jones | 64394e3 | 2012-04-17 19:00:58 +0100 | [diff] [blame] | 260 | eval_gettextln "Adding existing repo at '\$sm_path' to the index" |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 261 | else |
Ramsay Jones | 64394e3 | 2012-04-17 19:00:58 +0100 | [diff] [blame] | 262 | die "$(eval_gettext "'\$sm_path' already exists and is not a valid git repo")" |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 263 | fi |
Mark Levedahl | c2f9391 | 2008-07-09 21:05:41 -0400 | [diff] [blame] | 264 | |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 265 | else |
Jens Lehmann | 4b7c286 | 2012-09-30 23:01:29 +0200 | [diff] [blame] | 266 | if test -d ".git/modules/$sm_name" |
| 267 | then |
| 268 | if test -z "$force" |
| 269 | then |
Vasco Almeida | 0d71dbf | 2016-06-17 21:54:12 +0000 | [diff] [blame] | 270 | eval_gettextln >&2 "A git directory for '\$sm_name' is found locally with remote(s):" |
Jens Lehmann | 4b7c286 | 2012-09-30 23:01:29 +0200 | [diff] [blame] | 271 | GIT_DIR=".git/modules/$sm_name" GIT_WORK_TREE=. git remote -v | grep '(fetch)' | sed -e s,^," ", -e s,' (fetch)',, >&2 |
Vasco Almeida | 0d71dbf | 2016-06-17 21:54:12 +0000 | [diff] [blame] | 272 | die "$(eval_gettextln "\ |
| 273 | If you want to reuse this local git directory instead of cloning again from |
| 274 | \$realrepo |
| 275 | use the '--force' option. If the local git directory is not the correct repo |
| 276 | or you are unsure what this means choose another name with the '--name' option.")" |
Jens Lehmann | 4b7c286 | 2012-09-30 23:01:29 +0200 | [diff] [blame] | 277 | else |
Vasco Almeida | 0d71dbf | 2016-06-17 21:54:12 +0000 | [diff] [blame] | 278 | eval_gettextln "Reactivating local git directory for submodule '\$sm_name'." |
Jens Lehmann | 4b7c286 | 2012-09-30 23:01:29 +0200 | [diff] [blame] | 279 | fi |
| 280 | fi |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 281 | git submodule--helper clone ${GIT_QUIET:+--quiet} ${progress:+"--progress"} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${dissociate:+"--dissociate"} ${depth:+"$depth"} || exit |
Junio C Hamano | d851ffb | 2014-04-02 14:15:36 -0700 | [diff] [blame] | 282 | ( |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 283 | sanitize_submodule_env |
Junio C Hamano | d851ffb | 2014-04-02 14:15:36 -0700 | [diff] [blame] | 284 | cd "$sm_path" && |
| 285 | # ash fails to wordsplit ${branch:+-b "$branch"...} |
| 286 | case "$branch" in |
| 287 | '') git checkout -f -q ;; |
| 288 | ?*) git checkout -f -q -B "$branch" "origin/$branch" ;; |
| 289 | esac |
| 290 | ) || die "$(eval_gettext "Unable to checkout submodule '\$sm_path'")" |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 291 | fi |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 292 | git config submodule."$sm_name".url "$realrepo" |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 293 | |
Jeff King | 5321399 | 2017-06-14 06:58:22 -0400 | [diff] [blame] | 294 | git add --no-warn-embedded-repo $force "$sm_path" || |
Ramsay Jones | 64394e3 | 2012-04-17 19:00:58 +0100 | [diff] [blame] | 295 | die "$(eval_gettext "Failed to add submodule '\$sm_path'")" |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 296 | |
Antonio Ospite | b2faad4 | 2018-10-05 15:05:57 +0200 | [diff] [blame] | 297 | git submodule--helper config submodule."$sm_name".path "$sm_path" && |
| 298 | git submodule--helper config submodule."$sm_name".url "$repo" && |
W. Trevor King | b928922 | 2012-12-19 11:03:33 -0500 | [diff] [blame] | 299 | if test -n "$branch" |
| 300 | then |
Antonio Ospite | b2faad4 | 2018-10-05 15:05:57 +0200 | [diff] [blame] | 301 | git submodule--helper config submodule."$sm_name".branch "$branch" |
W. Trevor King | b928922 | 2012-12-19 11:03:33 -0500 | [diff] [blame] | 302 | fi && |
Ævar Arnfjörð Bjarmason | 31991b0 | 2010-07-05 17:33:03 +0000 | [diff] [blame] | 303 | git add --force .gitmodules || |
Ramsay Jones | 64394e3 | 2012-04-17 19:00:58 +0100 | [diff] [blame] | 304 | die "$(eval_gettext "Failed to register submodule '\$sm_path'")" |
Brandon Williams | 1b614c0 | 2017-03-17 15:38:05 -0700 | [diff] [blame] | 305 | |
| 306 | # NEEDSWORK: In a multi-working-tree world, this needs to be |
| 307 | # set in the per-worktree config. |
| 308 | if git config --get submodule.active >/dev/null |
| 309 | then |
| 310 | # If the submodule being adding isn't already covered by the |
| 311 | # current configured pathspec, set the submodule's active flag |
| 312 | if ! git submodule--helper is-active "$sm_path" |
| 313 | then |
| 314 | git config submodule."$sm_name".active "true" |
| 315 | fi |
| 316 | else |
| 317 | git config submodule."$sm_name".active "true" |
| 318 | fi |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | # |
Mark Levedahl | 19a31f9 | 2008-08-10 19:10:04 -0400 | [diff] [blame] | 322 | # Execute an arbitrary command sequence in each checked out |
| 323 | # submodule |
| 324 | # |
| 325 | # $@ = command to execute |
| 326 | # |
| 327 | cmd_foreach() |
| 328 | { |
Johan Herland | 1d5bec8 | 2009-08-19 03:45:19 +0200 | [diff] [blame] | 329 | # parse $args after "submodule ... foreach". |
| 330 | while test $# -ne 0 |
| 331 | do |
| 332 | case "$1" in |
| 333 | -q|--quiet) |
| 334 | GIT_QUIET=1 |
| 335 | ;; |
Johan Herland | 15fc56a | 2009-08-19 03:45:22 +0200 | [diff] [blame] | 336 | --recursive) |
| 337 | recursive=1 |
| 338 | ;; |
Johan Herland | 1d5bec8 | 2009-08-19 03:45:19 +0200 | [diff] [blame] | 339 | -*) |
| 340 | usage |
| 341 | ;; |
| 342 | *) |
| 343 | break |
| 344 | ;; |
| 345 | esac |
| 346 | shift |
| 347 | done |
| 348 | |
Prathamesh Chavan | fc1b924 | 2018-05-10 14:25:01 -0700 | [diff] [blame] | 349 | git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} "$@" |
Mark Levedahl | 19a31f9 | 2008-08-10 19:10:04 -0400 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | # |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 353 | # Register submodules in .git/config |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 354 | # |
| 355 | # $@ = requested paths (default to all) |
| 356 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 357 | cmd_init() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 358 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 359 | # parse $args after "submodule ... init". |
| 360 | while test $# -ne 0 |
| 361 | do |
| 362 | case "$1" in |
| 363 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 364 | GIT_QUIET=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 365 | ;; |
| 366 | --) |
| 367 | shift |
| 368 | break |
| 369 | ;; |
| 370 | -*) |
| 371 | usage |
| 372 | ;; |
| 373 | *) |
| 374 | break |
| 375 | ;; |
| 376 | esac |
| 377 | shift |
| 378 | done |
| 379 | |
Stefan Beller | 6e7c14e | 2017-01-06 16:19:53 -0800 | [diff] [blame] | 380 | 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] | 381 | } |
| 382 | |
| 383 | # |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 384 | # Unregister submodules from .git/config and remove their work tree |
| 385 | # |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 386 | cmd_deinit() |
| 387 | { |
| 388 | # parse $args after "submodule ... deinit". |
Stefan Beller | f6a5279 | 2016-05-05 12:52:32 -0700 | [diff] [blame] | 389 | deinit_all= |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 390 | while test $# -ne 0 |
| 391 | do |
| 392 | case "$1" in |
| 393 | -f|--force) |
| 394 | force=$1 |
| 395 | ;; |
| 396 | -q|--quiet) |
| 397 | GIT_QUIET=1 |
| 398 | ;; |
Stefan Beller | f6a5279 | 2016-05-05 12:52:32 -0700 | [diff] [blame] | 399 | --all) |
| 400 | deinit_all=t |
| 401 | ;; |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 402 | --) |
| 403 | shift |
| 404 | break |
| 405 | ;; |
| 406 | -*) |
| 407 | usage |
| 408 | ;; |
| 409 | *) |
| 410 | break |
| 411 | ;; |
| 412 | esac |
| 413 | shift |
| 414 | done |
| 415 | |
Prathamesh Chavan | 2e61273 | 2018-01-15 02:45:29 +0530 | [diff] [blame] | 416 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${prefix:+--prefix "$prefix"} ${force:+--force} ${deinit_all:+--all} "$@" |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 417 | } |
| 418 | |
Stefan Beller | fb43e31 | 2016-02-23 19:32:13 -0800 | [diff] [blame] | 419 | is_tip_reachable () ( |
Junio C Hamano | 01e1d54 | 2016-04-06 11:39:12 -0700 | [diff] [blame] | 420 | sanitize_submodule_env && |
Stefan Beller | fb43e31 | 2016-02-23 19:32:13 -0800 | [diff] [blame] | 421 | cd "$1" && |
| 422 | rev=$(git rev-list -n 1 "$2" --not --all 2>/dev/null) && |
| 423 | test -z "$rev" |
| 424 | ) |
| 425 | |
| 426 | fetch_in_submodule () ( |
Junio C Hamano | 01e1d54 | 2016-04-06 11:39:12 -0700 | [diff] [blame] | 427 | sanitize_submodule_env && |
Stefan Beller | fb43e31 | 2016-02-23 19:32:13 -0800 | [diff] [blame] | 428 | cd "$1" && |
| 429 | case "$2" in |
| 430 | '') |
| 431 | git fetch ;; |
| 432 | *) |
Stefan Beller | 6cbf454 | 2016-07-28 17:44:04 -0700 | [diff] [blame] | 433 | shift |
| 434 | git fetch $(get_default_remote) "$@" ;; |
Stefan Beller | fb43e31 | 2016-02-23 19:32:13 -0800 | [diff] [blame] | 435 | esac |
| 436 | ) |
| 437 | |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 438 | # |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 439 | # 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] | 440 | # |
| 441 | # $@ = requested paths (default to all) |
| 442 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 443 | cmd_update() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 444 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 445 | # parse $args after "submodule ... update". |
| 446 | while test $# -ne 0 |
| 447 | do |
| 448 | case "$1" in |
| 449 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 450 | GIT_QUIET=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 451 | ;; |
Stefan Beller | e84c3cf | 2018-08-14 11:22:02 -0700 | [diff] [blame] | 452 | -v) |
| 453 | GIT_QUIET=0 |
| 454 | ;; |
Jeff King | 72c5f88 | 2016-09-22 01:24:46 -0400 | [diff] [blame] | 455 | --progress) |
Casey Fitzpatrick | c7199e3 | 2018-05-03 06:53:44 -0400 | [diff] [blame] | 456 | progress=1 |
Jeff King | 72c5f88 | 2016-09-22 01:24:46 -0400 | [diff] [blame] | 457 | ;; |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 458 | -i|--init) |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 459 | init=1 |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 460 | ;; |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 461 | --remote) |
| 462 | remote=1 |
| 463 | ;; |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 464 | -N|--no-fetch) |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 465 | nofetch=1 |
| 466 | ;; |
Nicolas Morey-Chaisemartin | 9db31bd | 2011-04-01 11:42:03 +0200 | [diff] [blame] | 467 | -f|--force) |
| 468 | force=$1 |
| 469 | ;; |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 470 | -r|--rebase) |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 471 | update="rebase" |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 472 | ;; |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 473 | --reference) |
| 474 | case "$2" in '') usage ;; esac |
| 475 | reference="--reference=$2" |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 476 | shift |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 477 | ;; |
| 478 | --reference=*) |
| 479 | reference="$1" |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 480 | ;; |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 481 | --dissociate) |
| 482 | dissociate=1 |
| 483 | ;; |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 484 | -m|--merge) |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 485 | update="merge" |
| 486 | ;; |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 487 | --recursive) |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 488 | recursive=1 |
| 489 | ;; |
Junio C Hamano | efc5fb6 | 2011-10-10 15:56:16 -0700 | [diff] [blame] | 490 | --checkout) |
| 491 | update="checkout" |
| 492 | ;; |
Stefan Beller | abed000 | 2016-05-26 14:59:43 -0700 | [diff] [blame] | 493 | --recommend-shallow) |
| 494 | recommend_shallow="--recommend-shallow" |
| 495 | ;; |
| 496 | --no-recommend-shallow) |
| 497 | recommend_shallow="--no-recommend-shallow" |
| 498 | ;; |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 499 | --depth) |
| 500 | case "$2" in '') usage ;; esac |
| 501 | depth="--depth=$2" |
| 502 | shift |
| 503 | ;; |
| 504 | --depth=*) |
| 505 | depth=$1 |
| 506 | ;; |
Stefan Beller | 2335b87 | 2016-02-29 18:07:19 -0800 | [diff] [blame] | 507 | -j|--jobs) |
| 508 | case "$2" in '') usage ;; esac |
| 509 | jobs="--jobs=$2" |
| 510 | shift |
| 511 | ;; |
| 512 | --jobs=*) |
| 513 | jobs=$1 |
| 514 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 515 | --) |
| 516 | shift |
| 517 | break |
| 518 | ;; |
| 519 | -*) |
| 520 | usage |
| 521 | ;; |
| 522 | *) |
| 523 | break |
| 524 | ;; |
| 525 | esac |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 526 | shift |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 527 | done |
| 528 | |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 529 | if test -n "$init" |
| 530 | then |
| 531 | cmd_init "--" "$@" || return |
| 532 | fi |
| 533 | |
Stefan Beller | 4830868 | 2016-02-29 18:07:17 -0800 | [diff] [blame] | 534 | { |
| 535 | git submodule--helper update-clone ${GIT_QUIET:+--quiet} \ |
Casey Fitzpatrick | c7199e3 | 2018-05-03 06:53:44 -0400 | [diff] [blame] | 536 | ${progress:+"--progress"} \ |
Stefan Beller | 4830868 | 2016-02-29 18:07:17 -0800 | [diff] [blame] | 537 | ${wt_prefix:+--prefix "$wt_prefix"} \ |
| 538 | ${prefix:+--recursive-prefix "$prefix"} \ |
| 539 | ${update:+--update "$update"} \ |
Stefan Beller | 5f50f33 | 2016-08-11 16:14:01 -0700 | [diff] [blame] | 540 | ${reference:+"$reference"} \ |
Casey Fitzpatrick | a0ef293 | 2018-05-03 06:53:46 -0400 | [diff] [blame] | 541 | ${dissociate:+"--dissociate"} \ |
Stefan Beller | 4830868 | 2016-02-29 18:07:17 -0800 | [diff] [blame] | 542 | ${depth:+--depth "$depth"} \ |
Casey Fitzpatrick | c7199e3 | 2018-05-03 06:53:44 -0400 | [diff] [blame] | 543 | $recommend_shallow \ |
| 544 | $jobs \ |
Johannes Sixt | c4c02bf | 2016-07-22 21:14:38 +0200 | [diff] [blame] | 545 | "$@" || echo "#unmatched" $? |
Stefan Beller | 4830868 | 2016-02-29 18:07:17 -0800 | [diff] [blame] | 546 | } | { |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 547 | err= |
Stefan Beller | 9eca701 | 2018-08-03 15:23:17 -0700 | [diff] [blame] | 548 | while read -r quickabort sha1 just_cloned sm_path |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 549 | do |
Stefan Beller | 9eca701 | 2018-08-03 15:23:17 -0700 | [diff] [blame] | 550 | die_if_unmatched "$quickabort" "$sha1" |
Stefan Beller | 4830868 | 2016-02-29 18:07:17 -0800 | [diff] [blame] | 551 | |
Stefan Beller | 5d124f4 | 2019-01-18 13:55:19 -0800 | [diff] [blame] | 552 | git submodule--helper ensure-core-worktree "$sm_path" || exit 1 |
Stefan Beller | 74d4731 | 2018-08-13 15:42:34 -0700 | [diff] [blame] | 553 | |
Stefan Beller | ee69b2a | 2018-08-13 15:42:35 -0700 | [diff] [blame] | 554 | update_module=$(git submodule--helper update-module-mode $just_cloned "$sm_path" $update) |
Junio C Hamano | efc5fb6 | 2011-10-10 15:56:16 -0700 | [diff] [blame] | 555 | |
Stefan Beller | 44431df | 2016-05-31 17:27:59 -0700 | [diff] [blame] | 556 | displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 557 | |
Stefan Beller | 4830868 | 2016-02-29 18:07:17 -0800 | [diff] [blame] | 558 | if test $just_cloned -eq 1 |
Junio C Hamano | d851ffb | 2014-04-02 14:15:36 -0700 | [diff] [blame] | 559 | then |
Lars Hjemli | bf2d824 | 2007-06-11 21:12:22 +0200 | [diff] [blame] | 560 | subsha1= |
| 561 | else |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 562 | subsha1=$(sanitize_submodule_env; cd "$sm_path" && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 563 | git rev-parse --verify HEAD) || |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 564 | die "$(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")" |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 565 | fi |
| 566 | |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 567 | if test -n "$remote" |
| 568 | then |
Stefan Beller | 92bbe7c | 2016-08-03 13:44:03 -0700 | [diff] [blame] | 569 | branch=$(git submodule--helper remote-branch "$sm_path") |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 570 | if test -z "$nofetch" |
| 571 | then |
| 572 | # Fetch remote before determining tracking $sha1 |
Stefan Beller | 6cbf454 | 2016-07-28 17:44:04 -0700 | [diff] [blame] | 573 | fetch_in_submodule "$sm_path" $depth || |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 574 | die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")" |
| 575 | fi |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 576 | remote_name=$(sanitize_submodule_env; cd "$sm_path" && get_default_remote) |
| 577 | sha1=$(sanitize_submodule_env; cd "$sm_path" && |
W. Trevor King | 06b1abb | 2012-12-19 11:03:32 -0500 | [diff] [blame] | 578 | git rev-parse --verify "${remote_name}/${branch}") || |
Vasco Almeida | c87302b | 2016-06-17 21:54:13 +0000 | [diff] [blame] | 579 | die "$(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] | 580 | fi |
| 581 | |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 582 | if test "$subsha1" != "$sha1" || test -n "$force" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 583 | then |
Nicolas Morey-Chaisemartin | 9db31bd | 2011-04-01 11:42:03 +0200 | [diff] [blame] | 584 | subforce=$force |
| 585 | # If we don't already have a -f flag and the submodule has never been checked out |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 586 | if test -z "$subsha1" && test -z "$force" |
Ping Yin | b9b378a | 2008-09-26 23:33:23 +0800 | [diff] [blame] | 587 | then |
Nicolas Morey-Chaisemartin | 9db31bd | 2011-04-01 11:42:03 +0200 | [diff] [blame] | 588 | subforce="-f" |
Ping Yin | b9b378a | 2008-09-26 23:33:23 +0800 | [diff] [blame] | 589 | fi |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 590 | |
| 591 | if test -z "$nofetch" |
| 592 | then |
Jens Lehmann | e5f522d | 2011-03-06 23:13:36 +0100 | [diff] [blame] | 593 | # Run fetch only if $sha1 isn't present or it |
| 594 | # is not reachable from a ref. |
Stefan Beller | fb43e31 | 2016-02-23 19:32:13 -0800 | [diff] [blame] | 595 | is_tip_reachable "$sm_path" "$sha1" || |
Stefan Beller | 6cbf454 | 2016-07-28 17:44:04 -0700 | [diff] [blame] | 596 | fetch_in_submodule "$sm_path" $depth || |
Stefan Beller | e30d833 | 2018-05-15 12:40:54 -0700 | [diff] [blame] | 597 | say "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")" |
Stefan Beller | fb43e31 | 2016-02-23 19:32:13 -0800 | [diff] [blame] | 598 | |
| 599 | # Now we tried the usual fetch, but $sha1 may |
| 600 | # not be reachable from any of the refs |
| 601 | is_tip_reachable "$sm_path" "$sha1" || |
Stefan Beller | 6cbf454 | 2016-07-28 17:44:04 -0700 | [diff] [blame] | 602 | fetch_in_submodule "$sm_path" $depth "$sha1" || |
Vasco Almeida | c87302b | 2016-06-17 21:54:13 +0000 | [diff] [blame] | 603 | die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain \$sha1. Direct fetching of that commit failed.")" |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 604 | fi |
| 605 | |
Junio C Hamano | 877449c | 2011-06-13 12:17:52 -0700 | [diff] [blame] | 606 | must_die_on_failure= |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 607 | case "$update_module" in |
W. Trevor King | a2aed08 | 2014-01-15 20:10:22 -0800 | [diff] [blame] | 608 | checkout) |
| 609 | command="git checkout $subforce -q" |
| 610 | die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$displaypath'")" |
| 611 | say_msg="$(eval_gettext "Submodule path '\$displaypath': checked out '\$sha1'")" |
| 612 | ;; |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 613 | rebase) |
| 614 | command="git rebase" |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 615 | die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$displaypath'")" |
| 616 | say_msg="$(eval_gettext "Submodule path '\$displaypath': rebased into '\$sha1'")" |
Junio C Hamano | 877449c | 2011-06-13 12:17:52 -0700 | [diff] [blame] | 617 | must_die_on_failure=yes |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 618 | ;; |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 619 | merge) |
| 620 | command="git merge" |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 621 | die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$displaypath'")" |
| 622 | say_msg="$(eval_gettext "Submodule path '\$displaypath': merged in '\$sha1'")" |
Junio C Hamano | 877449c | 2011-06-13 12:17:52 -0700 | [diff] [blame] | 623 | must_die_on_failure=yes |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 624 | ;; |
Chris Packham | 6cb5728 | 2013-07-03 21:02:02 +1200 | [diff] [blame] | 625 | !*) |
| 626 | command="${update_module#!}" |
Stefan Beller | b08238a | 2016-03-29 18:27:44 -0700 | [diff] [blame] | 627 | die_msg="$(eval_gettext "Execution of '\$command \$sha1' failed in submodule path '\$displaypath'")" |
| 628 | say_msg="$(eval_gettext "Submodule path '\$displaypath': '\$command \$sha1'")" |
Chris Packham | 6cb5728 | 2013-07-03 21:02:02 +1200 | [diff] [blame] | 629 | must_die_on_failure=yes |
| 630 | ;; |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 631 | *) |
Stefan Beller | ff03d93 | 2018-08-03 15:23:16 -0700 | [diff] [blame] | 632 | die "$(eval_gettext "Invalid update mode '$update_module' for submodule path '$path'")" |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 633 | esac |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 634 | |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 635 | if (sanitize_submodule_env; cd "$sm_path" && $command "$sha1") |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 636 | then |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 637 | say "$say_msg" |
Junio C Hamano | 877449c | 2011-06-13 12:17:52 -0700 | [diff] [blame] | 638 | elif test -n "$must_die_on_failure" |
| 639 | then |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 640 | die_with_status 2 "$die_msg" |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 641 | else |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 642 | err="${err};$die_msg" |
Junio C Hamano | 877449c | 2011-06-13 12:17:52 -0700 | [diff] [blame] | 643 | continue |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 644 | fi |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 645 | fi |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 646 | |
| 647 | if test -n "$recursive" |
| 648 | then |
William Entriken | 75bf5e6 | 2013-03-02 14:44:59 -0500 | [diff] [blame] | 649 | ( |
Stefan Beller | 44431df | 2016-05-31 17:27:59 -0700 | [diff] [blame] | 650 | prefix=$(git submodule--helper relative-path "$prefix$sm_path/" "$wt_prefix") |
Stefan Beller | 3604242 | 2016-04-15 17:50:13 -0700 | [diff] [blame] | 651 | wt_prefix= |
Jacob Keller | 14111fc | 2016-02-29 14:58:35 -0800 | [diff] [blame] | 652 | sanitize_submodule_env |
William Entriken | 75bf5e6 | 2013-03-02 14:44:59 -0500 | [diff] [blame] | 653 | cd "$sm_path" && |
Jens Lehmann | 3614128 | 2013-11-11 21:55:52 +0100 | [diff] [blame] | 654 | eval cmd_update |
William Entriken | 75bf5e6 | 2013-03-02 14:44:59 -0500 | [diff] [blame] | 655 | ) |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 656 | res=$? |
| 657 | if test $res -gt 0 |
| 658 | then |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 659 | die_msg="$(eval_gettext "Failed to recurse into submodule path '\$displaypath'")" |
Stefan Beller | bb9d91b | 2016-06-09 12:06:37 -0700 | [diff] [blame] | 660 | if test $res -ne 2 |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 661 | then |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 662 | err="${err};$die_msg" |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 663 | continue |
| 664 | else |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 665 | die_with_status $res "$die_msg" |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 666 | fi |
| 667 | fi |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 668 | fi |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 669 | done |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 670 | |
| 671 | if test -n "$err" |
| 672 | then |
| 673 | OIFS=$IFS |
| 674 | IFS=';' |
| 675 | for e in $err |
| 676 | do |
| 677 | if test -n "$e" |
| 678 | then |
| 679 | echo >&2 "$e" |
| 680 | fi |
| 681 | done |
| 682 | IFS=$OIFS |
| 683 | exit 1 |
| 684 | fi |
| 685 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 686 | } |
| 687 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 688 | # |
| 689 | # Show commit summary for submodules in index or working tree |
| 690 | # |
| 691 | # If '--cached' is given, show summary between index and given commit, |
| 692 | # or between working tree and given commit |
| 693 | # |
| 694 | # $@ = [commit (default 'HEAD'),] requested paths (default all) |
| 695 | # |
| 696 | cmd_summary() { |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 697 | summary_limit=-1 |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 698 | for_status= |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 699 | diff_cmd=diff-index |
Emil Medve | bffe71f | 2007-06-26 18:40:58 -0500 | [diff] [blame] | 700 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 701 | # parse $args after "submodule ... summary". |
| 702 | while test $# -ne 0 |
| 703 | do |
| 704 | case "$1" in |
| 705 | --cached) |
| 706 | cached="$1" |
| 707 | ;; |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 708 | --files) |
| 709 | files="$1" |
| 710 | ;; |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 711 | --for-status) |
| 712 | for_status="$1" |
| 713 | ;; |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 714 | -n|--summary-limit) |
René Scharfe | 862ae6c | 2013-04-01 15:06:27 +0200 | [diff] [blame] | 715 | summary_limit="$2" |
| 716 | isnumber "$summary_limit" || usage |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 717 | shift |
| 718 | ;; |
René Scharfe | 862ae6c | 2013-04-01 15:06:27 +0200 | [diff] [blame] | 719 | --summary-limit=*) |
| 720 | summary_limit="${1#--summary-limit=}" |
| 721 | isnumber "$summary_limit" || usage |
| 722 | ;; |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 723 | --) |
| 724 | shift |
| 725 | break |
| 726 | ;; |
| 727 | -*) |
| 728 | usage |
| 729 | ;; |
| 730 | *) |
| 731 | break |
| 732 | ;; |
| 733 | esac |
| 734 | shift |
| 735 | done |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 736 | |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 737 | test $summary_limit = 0 && return |
| 738 | |
Johan Herland | 3deea89 | 2010-02-16 11:21:14 +0100 | [diff] [blame] | 739 | if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"}) |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 740 | then |
| 741 | head=$rev |
Jeff King | caa9c3c | 2010-03-03 14:19:09 -0800 | [diff] [blame] | 742 | test $# = 0 || shift |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 743 | elif test -z "$1" || test "$1" = "HEAD" |
Johan Herland | 3deea89 | 2010-02-16 11:21:14 +0100 | [diff] [blame] | 744 | then |
Junio C Hamano | 14e940d | 2010-03-03 14:19:10 -0800 | [diff] [blame] | 745 | # before the first commit: compare with an empty tree |
| 746 | head=$(git hash-object -w -t tree --stdin </dev/null) |
Jens Lehmann | 2ea6c2c | 2010-03-09 15:55:32 +0100 | [diff] [blame] | 747 | test -z "$1" || shift |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 748 | else |
Johan Herland | 3deea89 | 2010-02-16 11:21:14 +0100 | [diff] [blame] | 749 | head="HEAD" |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 750 | fi |
| 751 | |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 752 | if [ -n "$files" ] |
| 753 | then |
| 754 | test -n "$cached" && |
Jiang Xin | 465d6a0 | 2012-07-25 22:53:09 +0800 | [diff] [blame] | 755 | die "$(gettext "The --cached option cannot be used with the --files option")" |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 756 | diff_cmd=diff-files |
| 757 | head= |
| 758 | fi |
| 759 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 760 | cd_to_toplevel |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 761 | eval "set $(git rev-parse --sq --prefix "$wt_prefix" -- "$@")" |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 762 | # Get modified modules cared by user |
Jens Lehmann | 1807650 | 2010-06-25 16:56:02 +0200 | [diff] [blame] | 763 | modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" | |
Junio C Hamano | e1622bf | 2009-11-23 15:56:32 -0800 | [diff] [blame] | 764 | sane_egrep '^:([0-7]* )?160000' | |
Brandon Williams | cf9e55f | 2017-04-07 10:23:06 -0700 | [diff] [blame] | 765 | while read -r mod_src mod_dst sha1_src sha1_dst status sm_path |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 766 | do |
| 767 | # Always show modules deleted or type-changed (blob<->module) |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 768 | if test "$status" = D || test "$status" = T |
| 769 | then |
Junio C Hamano | 6a06623 | 2014-06-10 08:33:39 -0700 | [diff] [blame] | 770 | printf '%s\n' "$sm_path" |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 771 | continue |
| 772 | fi |
Brian M. Carlson | 927b26f | 2013-09-01 20:06:49 +0000 | [diff] [blame] | 773 | # Respect the ignore setting for --for-status. |
| 774 | if test -n "$for_status" |
| 775 | then |
Stefan Beller | 0ea306e | 2015-09-02 14:42:25 -0700 | [diff] [blame] | 776 | name=$(git submodule--helper name "$sm_path") |
Brian M. Carlson | 927b26f | 2013-09-01 20:06:49 +0000 | [diff] [blame] | 777 | ignore_config=$(get_submodule_config "$name" ignore none) |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 778 | test $status != A && test $ignore_config = all && continue |
Brian M. Carlson | 927b26f | 2013-09-01 20:06:49 +0000 | [diff] [blame] | 779 | fi |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 780 | # Also show added or modified modules which are checked out |
Michael Forney | 974ce80 | 2017-08-04 23:49:05 -0700 | [diff] [blame] | 781 | GIT_DIR="$sm_path/.git" git rev-parse --git-dir >/dev/null 2>&1 && |
Junio C Hamano | 6a06623 | 2014-06-10 08:33:39 -0700 | [diff] [blame] | 782 | printf '%s\n' "$sm_path" |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 783 | done |
| 784 | ) |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 785 | |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 786 | test -z "$modules" && return |
| 787 | |
Jens Lehmann | 1807650 | 2010-06-25 16:56:02 +0200 | [diff] [blame] | 788 | git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules | |
Junio C Hamano | e1622bf | 2009-11-23 15:56:32 -0800 | [diff] [blame] | 789 | sane_egrep '^:([0-7]* )?160000' | |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 790 | cut -c2- | |
Brandon Williams | cf9e55f | 2017-04-07 10:23:06 -0700 | [diff] [blame] | 791 | while read -r mod_src mod_dst sha1_src sha1_dst status name |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 792 | do |
| 793 | if test -z "$cached" && |
brian m. carlson | dda6346 | 2018-10-15 00:02:01 +0000 | [diff] [blame] | 794 | is_zero_oid $sha1_dst |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 795 | then |
| 796 | case "$mod_dst" in |
| 797 | 160000) |
| 798 | sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD) |
| 799 | ;; |
| 800 | 100644 | 100755 | 120000) |
| 801 | sha1_dst=$(git hash-object $name) |
| 802 | ;; |
| 803 | 000000) |
| 804 | ;; # removed |
| 805 | *) |
| 806 | # unexpected type |
Jon Seymour | 6ff875c | 2011-08-07 21:58:17 +1000 | [diff] [blame] | 807 | eval_gettextln "unexpected mode \$mod_dst" >&2 |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 808 | continue ;; |
| 809 | esac |
| 810 | fi |
| 811 | missing_src= |
| 812 | missing_dst= |
| 813 | |
| 814 | test $mod_src = 160000 && |
Michael Forney | 974ce80 | 2017-08-04 23:49:05 -0700 | [diff] [blame] | 815 | ! GIT_DIR="$name/.git" git rev-parse -q --verify $sha1_src^0 >/dev/null && |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 816 | missing_src=t |
| 817 | |
| 818 | test $mod_dst = 160000 && |
Michael Forney | 974ce80 | 2017-08-04 23:49:05 -0700 | [diff] [blame] | 819 | ! GIT_DIR="$name/.git" git rev-parse -q --verify $sha1_dst^0 >/dev/null && |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 820 | missing_dst=t |
| 821 | |
Stefan Beller | 44431df | 2016-05-31 17:27:59 -0700 | [diff] [blame] | 822 | display_name=$(git submodule--helper relative-path "$name" "$wt_prefix") |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 823 | |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 824 | total_commits= |
| 825 | case "$missing_src,$missing_dst" in |
| 826 | t,) |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 827 | errmsg="$(eval_gettext " Warn: \$display_name doesn't contain commit \$sha1_src")" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 828 | ;; |
| 829 | ,t) |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 830 | errmsg="$(eval_gettext " Warn: \$display_name doesn't contain commit \$sha1_dst")" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 831 | ;; |
| 832 | t,t) |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 833 | errmsg="$(eval_gettext " Warn: \$display_name doesn't contain commits \$sha1_src and \$sha1_dst")" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 834 | ;; |
| 835 | *) |
| 836 | errmsg= |
| 837 | total_commits=$( |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 838 | if test $mod_src = 160000 && test $mod_dst = 160000 |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 839 | then |
| 840 | range="$sha1_src...$sha1_dst" |
| 841 | elif test $mod_src = 160000 |
| 842 | then |
| 843 | range=$sha1_src |
| 844 | else |
| 845 | range=$sha1_dst |
| 846 | fi |
| 847 | GIT_DIR="$name/.git" \ |
Jeff King | b0e621a | 2010-04-08 15:42:37 -0400 | [diff] [blame] | 848 | git rev-list --first-parent $range -- | wc -l |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 849 | ) |
Johannes Sixt | eed3559 | 2008-03-12 09:30:01 +0100 | [diff] [blame] | 850 | total_commits=" ($(($total_commits + 0)))" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 851 | ;; |
| 852 | esac |
| 853 | |
Sven van Haastregt | 0586a43 | 2019-02-03 21:00:27 +0000 | [diff] [blame] | 854 | sha1_abbr_src=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_src 2>/dev/null || |
| 855 | echo $sha1_src | cut -c1-7) |
| 856 | sha1_abbr_dst=$(GIT_DIR="$name/.git" git rev-parse --short $sha1_dst 2>/dev/null || |
| 857 | echo $sha1_dst | cut -c1-7) |
| 858 | |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 859 | if test $status = T |
| 860 | then |
Ævar Arnfjörð Bjarmason | b3e7344 | 2011-05-21 18:44:09 +0000 | [diff] [blame] | 861 | blob="$(gettext "blob")" |
| 862 | submodule="$(gettext "submodule")" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 863 | if test $mod_dst = 160000 |
| 864 | then |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 865 | echo "* $display_name $sha1_abbr_src($blob)->$sha1_abbr_dst($submodule)$total_commits:" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 866 | else |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 867 | echo "* $display_name $sha1_abbr_src($submodule)->$sha1_abbr_dst($blob)$total_commits:" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 868 | fi |
| 869 | else |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 870 | echo "* $display_name $sha1_abbr_src...$sha1_abbr_dst$total_commits:" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 871 | fi |
| 872 | if test -n "$errmsg" |
| 873 | then |
| 874 | # Don't give error msg for modification whose dst is not submodule |
| 875 | # i.e. deleted or changed to blob |
| 876 | test $mod_dst = 160000 && echo "$errmsg" |
| 877 | else |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 878 | if test $mod_src = 160000 && test $mod_dst = 160000 |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 879 | then |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 880 | limit= |
| 881 | test $summary_limit -gt 0 && limit="-$summary_limit" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 882 | GIT_DIR="$name/.git" \ |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 883 | git log $limit --pretty='format: %m %s' \ |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 884 | --first-parent $sha1_src...$sha1_dst |
| 885 | elif test $mod_dst = 160000 |
| 886 | then |
| 887 | GIT_DIR="$name/.git" \ |
| 888 | git log --pretty='format: > %s' -1 $sha1_dst |
| 889 | else |
| 890 | GIT_DIR="$name/.git" \ |
| 891 | git log --pretty='format: < %s' -1 $sha1_src |
| 892 | fi |
| 893 | echo |
| 894 | fi |
| 895 | echo |
Matthieu Moy | 3ba7407 | 2013-09-06 19:43:06 +0200 | [diff] [blame] | 896 | done |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 897 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 898 | # |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 899 | # List all submodules, prefixed with: |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 900 | # - submodule not initialized |
| 901 | # + different revision checked out |
| 902 | # |
| 903 | # If --cached was specified the revision in the index will be printed |
| 904 | # instead of the currently checked out revision. |
| 905 | # |
| 906 | # $@ = requested paths (default to all) |
| 907 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 908 | cmd_status() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 909 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 910 | # parse $args after "submodule ... status". |
| 911 | while test $# -ne 0 |
| 912 | do |
| 913 | case "$1" in |
| 914 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 915 | GIT_QUIET=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 916 | ;; |
| 917 | --cached) |
| 918 | cached=1 |
| 919 | ;; |
Johan Herland | 64b19ff | 2009-08-19 03:45:24 +0200 | [diff] [blame] | 920 | --recursive) |
| 921 | recursive=1 |
| 922 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 923 | --) |
| 924 | shift |
| 925 | break |
| 926 | ;; |
| 927 | -*) |
| 928 | usage |
| 929 | ;; |
| 930 | *) |
| 931 | break |
| 932 | ;; |
| 933 | esac |
| 934 | shift |
| 935 | done |
| 936 | |
Prathamesh Chavan | a9f8a37 | 2017-10-06 18:54:15 +0530 | [diff] [blame] | 937 | git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} "$@" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 938 | } |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 939 | # |
| 940 | # Sync remote urls for submodules |
| 941 | # This makes the value for remote.$remote.url match the value |
| 942 | # specified in .gitmodules. |
| 943 | # |
| 944 | cmd_sync() |
| 945 | { |
| 946 | while test $# -ne 0 |
| 947 | do |
| 948 | case "$1" in |
| 949 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 950 | GIT_QUIET=1 |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 951 | shift |
| 952 | ;; |
Phil Hord | 82f49f2 | 2012-10-26 15:44:42 -0400 | [diff] [blame] | 953 | --recursive) |
| 954 | recursive=1 |
| 955 | shift |
| 956 | ;; |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 957 | --) |
| 958 | shift |
| 959 | break |
| 960 | ;; |
| 961 | -*) |
| 962 | usage |
| 963 | ;; |
| 964 | *) |
| 965 | break |
| 966 | ;; |
| 967 | esac |
| 968 | done |
Brandon Williams | e7849a9 | 2017-03-16 15:29:45 -0700 | [diff] [blame] | 969 | |
Prathamesh Chavan | 1342476 | 2018-01-15 02:45:28 +0530 | [diff] [blame] | 970 | git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} "$@" |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 971 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 972 | |
Stefan Beller | f6f8586 | 2016-12-12 11:04:35 -0800 | [diff] [blame] | 973 | cmd_absorbgitdirs() |
| 974 | { |
| 975 | git submodule--helper absorb-git-dirs --prefix "$wt_prefix" "$@" |
| 976 | } |
| 977 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 978 | # This loop parses the command line arguments to find the |
| 979 | # subcommand name to dispatch. Parsing of the subcommand specific |
| 980 | # options are primarily done by the subcommand implementations. |
| 981 | # Subcommand specific options such as --branch and --cached are |
| 982 | # parsed here as well, for backward compatibility. |
| 983 | |
| 984 | while test $# != 0 && test -z "$command" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 985 | do |
| 986 | case "$1" in |
Stefan Beller | f6f8586 | 2016-12-12 11:04:35 -0800 | [diff] [blame] | 987 | add | foreach | init | deinit | update | status | summary | sync | absorbgitdirs) |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 988 | command=$1 |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 989 | ;; |
| 990 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 991 | GIT_QUIET=1 |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 992 | ;; |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 993 | -b|--branch) |
| 994 | case "$2" in |
| 995 | '') |
| 996 | usage |
| 997 | ;; |
| 998 | esac |
| 999 | branch="$2"; shift |
| 1000 | ;; |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 1001 | --cached) |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 1002 | cached="$1" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 1003 | ;; |
| 1004 | --) |
| 1005 | break |
| 1006 | ;; |
| 1007 | -*) |
| 1008 | usage |
| 1009 | ;; |
| 1010 | *) |
| 1011 | break |
| 1012 | ;; |
| 1013 | esac |
| 1014 | shift |
| 1015 | done |
| 1016 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 1017 | # No command word defaults to "status" |
Ramkumar Ramachandra | af9c9f9 | 2012-09-22 16:57:59 +0530 | [diff] [blame] | 1018 | if test -z "$command" |
| 1019 | then |
| 1020 | if test $# = 0 |
| 1021 | then |
| 1022 | command=status |
| 1023 | else |
| 1024 | usage |
| 1025 | fi |
| 1026 | fi |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 1027 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 1028 | # "-b branch" is accepted only by "add" |
| 1029 | if test -n "$branch" && test "$command" != add |
| 1030 | then |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 1031 | usage |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 1032 | fi |
| 1033 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 1034 | # "--cached" is accepted only by "status" and "summary" |
Elia Pinto | 496eeeb | 2014-06-10 05:28:33 -0700 | [diff] [blame] | 1035 | if test -n "$cached" && test "$command" != status && test "$command" != summary |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 1036 | then |
| 1037 | usage |
| 1038 | fi |
| 1039 | |
| 1040 | "cmd_$command" "$@" |