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