Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 3 | # git-submodules.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/-/ /') |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 8 | USAGE="[--quiet] add [-b branch] [-f|--force] [--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>...] |
Nicolas Morey-Chaisemartin | 9db31bd | 2011-04-01 11:42:03 +0200 | [diff] [blame] | 11 | or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...] |
Junio C Hamano | adc5423 | 2009-08-27 16:59:25 -0700 | [diff] [blame] | 12 | or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...] |
Johan Herland | 15fc56a | 2009-08-19 03:45:22 +0200 | [diff] [blame] | 13 | or: $dashless [--quiet] foreach [--recursive] <command> |
Johan Herland | 1d5bec8 | 2009-08-19 03:45:19 +0200 | [diff] [blame] | 14 | or: $dashless [--quiet] sync [--] [<path>...]" |
Junio C Hamano | 8f321a3 | 2007-11-06 01:50:02 -0800 | [diff] [blame] | 15 | OPTIONS_SPEC= |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 16 | . git-sh-setup |
Ævar Arnfjörð Bjarmason | d0ad825 | 2011-05-21 18:43:58 +0000 | [diff] [blame] | 17 | . git-sh-i18n |
Mark Levedahl | 98fcf84 | 2008-08-24 14:46:10 -0400 | [diff] [blame] | 18 | . git-parse-remote |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 19 | require_work_tree |
| 20 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 21 | command= |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 22 | branch= |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 23 | force= |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 24 | reference= |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 25 | cached= |
Gerrit Pape | 48bb303 | 2010-04-26 11:50:39 +0200 | [diff] [blame] | 26 | recursive= |
| 27 | init= |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 28 | files= |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 29 | nofetch= |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 30 | update= |
Johan Herland | 15fc56a | 2009-08-19 03:45:22 +0200 | [diff] [blame] | 31 | prefix= |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 32 | |
Mark Levedahl | f31a522 | 2007-09-23 22:19:42 -0400 | [diff] [blame] | 33 | # Resolve relative url by appending to parent's url |
| 34 | resolve_relative_url () |
| 35 | { |
Mark Levedahl | 98fcf84 | 2008-08-24 14:46:10 -0400 | [diff] [blame] | 36 | remote=$(get_default_remote) |
Mark Levedahl | 8e7e6f3 | 2008-06-14 13:09:41 -0400 | [diff] [blame] | 37 | remoteurl=$(git config "remote.$remote.url") || |
Jens Lehmann | 4d68932 | 2011-06-06 21:58:04 +0200 | [diff] [blame] | 38 | remoteurl=$(pwd) # the repository is its own authoritative upstream |
Mark Levedahl | f31a522 | 2007-09-23 22:19:42 -0400 | [diff] [blame] | 39 | url="$1" |
Mark Levedahl | 99b120a | 2008-08-21 19:54:01 -0400 | [diff] [blame] | 40 | remoteurl=${remoteurl%/} |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 41 | sep=/ |
Mark Levedahl | f31a522 | 2007-09-23 22:19:42 -0400 | [diff] [blame] | 42 | while test -n "$url" |
| 43 | do |
| 44 | case "$url" in |
| 45 | ../*) |
| 46 | url="${url#../}" |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 47 | case "$remoteurl" in |
| 48 | */*) |
| 49 | remoteurl="${remoteurl%/*}" |
| 50 | ;; |
| 51 | *:*) |
| 52 | remoteurl="${remoteurl%:*}" |
| 53 | sep=: |
| 54 | ;; |
| 55 | *) |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 56 | die "$(eval_gettext "cannot strip one component off url '\$remoteurl'")" |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 57 | ;; |
| 58 | esac |
Mark Levedahl | f31a522 | 2007-09-23 22:19:42 -0400 | [diff] [blame] | 59 | ;; |
| 60 | ./*) |
| 61 | url="${url#./}" |
| 62 | ;; |
| 63 | *) |
| 64 | break;; |
| 65 | esac |
| 66 | done |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 67 | echo "$remoteurl$sep${url%/}" |
Mark Levedahl | f31a522 | 2007-09-23 22:19:42 -0400 | [diff] [blame] | 68 | } |
| 69 | |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 70 | # |
David Aguilar | a7b3269 | 2008-08-22 00:30:50 -0700 | [diff] [blame] | 71 | # Get submodule info for registered submodules |
| 72 | # $@ = path to limit submodule list |
| 73 | # |
| 74 | module_list() |
| 75 | { |
Nicolas Morey-Chaisemartin | 313ee0d | 2011-03-30 07:20:02 +0200 | [diff] [blame] | 76 | git ls-files --error-unmatch --stage -- "$@" | |
| 77 | perl -e ' |
| 78 | my %unmerged = (); |
| 79 | my ($null_sha1) = ("0" x 40); |
| 80 | while (<STDIN>) { |
| 81 | chomp; |
| 82 | my ($mode, $sha1, $stage, $path) = |
| 83 | /^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/; |
| 84 | next unless $mode eq "160000"; |
| 85 | if ($stage ne "0") { |
| 86 | if (!$unmerged{$path}++) { |
| 87 | print "$mode $null_sha1 U\t$path\n"; |
| 88 | } |
| 89 | next; |
| 90 | } |
| 91 | print "$_\n"; |
| 92 | } |
| 93 | ' |
David Aguilar | a7b3269 | 2008-08-22 00:30:50 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | # |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 97 | # Map submodule path to submodule name |
| 98 | # |
| 99 | # $1 = path |
| 100 | # |
| 101 | module_name() |
| 102 | { |
Junio C Hamano | 537601a | 2007-07-25 15:51:26 -0700 | [diff] [blame] | 103 | # Do we have "submodule.<something>.path = $1" defined in .gitmodules file? |
Chris Ridd | fe22e54 | 2008-06-11 14:09:19 +0100 | [diff] [blame] | 104 | re=$(printf '%s\n' "$1" | sed -e 's/[].[^$\\*]/\\&/g') |
Imran M Yousuf | a5099bb | 2008-05-15 13:42:58 +0600 | [diff] [blame] | 105 | name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' | |
Junio C Hamano | 537601a | 2007-07-25 15:51:26 -0700 | [diff] [blame] | 106 | sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' ) |
Tay Ray Chuan | 1e42258 | 2011-10-21 21:49:35 +0800 | [diff] [blame] | 107 | test -z "$name" && |
| 108 | die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$path'")" |
| 109 | echo "$name" |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 110 | } |
Lars Hjemli | 33aa6ff | 2007-06-06 11:13:01 +0200 | [diff] [blame] | 111 | |
| 112 | # |
| 113 | # Clone a submodule |
| 114 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 115 | # Prior to calling, cmd_update checks that a possibly existing |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 116 | # path is not a git repository. |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 117 | # Likewise, cmd_add checks that path does not exist at all, |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 118 | # since it is the location of a new submodule. |
| 119 | # |
Lars Hjemli | 33aa6ff | 2007-06-06 11:13:01 +0200 | [diff] [blame] | 120 | module_clone() |
| 121 | { |
| 122 | path=$1 |
| 123 | url=$2 |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 124 | reference="$3" |
Jens Lehmann | 7e60407 | 2011-07-26 23:39:03 +0200 | [diff] [blame] | 125 | quiet= |
| 126 | if test -n "$GIT_QUIET" |
| 127 | then |
| 128 | quiet=-q |
| 129 | fi |
Lars Hjemli | 33aa6ff | 2007-06-06 11:13:01 +0200 | [diff] [blame] | 130 | |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 131 | gitdir= |
| 132 | gitdir_base= |
Tay Ray Chuan | 9e76d4a | 2011-10-21 21:49:36 +0800 | [diff] [blame] | 133 | name=$(module_name "$path" 2>/dev/null) |
Jens Lehmann | 1017c1a | 2012-01-24 22:49:56 +0100 | [diff] [blame] | 134 | test -n "$name" || name="$path" |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 135 | base_path=$(dirname "$path") |
Lars Hjemli | 33aa6ff | 2007-06-06 11:13:01 +0200 | [diff] [blame] | 136 | |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 137 | gitdir=$(git rev-parse --git-dir) |
| 138 | gitdir_base="$gitdir/modules/$base_path" |
| 139 | gitdir="$gitdir/modules/$path" |
| 140 | |
| 141 | case $gitdir in |
| 142 | /*) |
| 143 | a="$(cd_to_toplevel && pwd)/" |
| 144 | b=$gitdir |
| 145 | while [ "$b" ] && [ "${a%%/*}" = "${b%%/*}" ] |
| 146 | do |
| 147 | a=${a#*/} b=${b#*/}; |
| 148 | done |
| 149 | |
| 150 | rel="$a$name" |
| 151 | rel=`echo $rel | sed -e 's|[^/]*|..|g'` |
| 152 | rel_gitdir="$rel/$b" |
| 153 | ;; |
| 154 | *) |
| 155 | rel=`echo $name | sed -e 's|[^/]*|..|g'` |
| 156 | rel_gitdir="$rel/$gitdir" |
| 157 | ;; |
| 158 | esac |
| 159 | |
| 160 | if test -d "$gitdir" |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 161 | then |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 162 | mkdir -p "$path" |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 163 | rm -f "$gitdir/index" |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 164 | else |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 165 | mkdir -p "$gitdir_base" |
Jens Lehmann | ea115a0 | 2012-03-04 22:14:30 +0100 | [diff] [blame^] | 166 | git clone $quiet -n ${reference:+"$reference"} \ |
| 167 | --separate-git-dir "$gitdir" "$url" "$path" || |
Fredrik Gustafsson | 501770e | 2011-08-15 23:17:47 +0200 | [diff] [blame] | 168 | die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")" |
| 169 | fi |
Jens Lehmann | ea115a0 | 2012-03-04 22:14:30 +0100 | [diff] [blame^] | 170 | |
| 171 | echo "gitdir: $rel_gitdir" >"$path/.git" |
Lars Hjemli | 33aa6ff | 2007-06-06 11:13:01 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 174 | # |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 175 | # Add a new submodule to the working tree, .gitmodules and the index |
| 176 | # |
Mark Levedahl | ec05df3 | 2008-07-09 21:05:40 -0400 | [diff] [blame] | 177 | # $@ = repo path |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 178 | # |
| 179 | # optional branch is stored in global branch variable |
| 180 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 181 | cmd_add() |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 182 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 183 | # parse $args after "submodule ... add". |
| 184 | while test $# -ne 0 |
| 185 | do |
| 186 | case "$1" in |
| 187 | -b | --branch) |
| 188 | case "$2" in '') usage ;; esac |
| 189 | branch=$2 |
| 190 | shift |
| 191 | ;; |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 192 | -f | --force) |
| 193 | force=$1 |
| 194 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 195 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 196 | GIT_QUIET=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 197 | ;; |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 198 | --reference) |
| 199 | case "$2" in '') usage ;; esac |
| 200 | reference="--reference=$2" |
| 201 | shift |
| 202 | ;; |
| 203 | --reference=*) |
| 204 | reference="$1" |
| 205 | shift |
| 206 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 207 | --) |
| 208 | shift |
| 209 | break |
| 210 | ;; |
| 211 | -*) |
| 212 | usage |
| 213 | ;; |
| 214 | *) |
| 215 | break |
| 216 | ;; |
| 217 | esac |
| 218 | shift |
| 219 | done |
| 220 | |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 221 | repo=$1 |
| 222 | path=$2 |
| 223 | |
Jens Lehmann | 1414e57 | 2009-09-22 17:10:12 +0200 | [diff] [blame] | 224 | if test -z "$path"; then |
| 225 | path=$(echo "$repo" | |
| 226 | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g') |
| 227 | fi |
| 228 | |
Mark Levedahl | ec05df3 | 2008-07-09 21:05:40 -0400 | [diff] [blame] | 229 | if test -z "$repo" -o -z "$path"; then |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 230 | usage |
| 231 | fi |
| 232 | |
Mark Levedahl | ec05df3 | 2008-07-09 21:05:40 -0400 | [diff] [blame] | 233 | # assure repo is absolute or relative to parent |
| 234 | case "$repo" in |
| 235 | ./*|../*) |
| 236 | # dereference source url relative to parent's url |
| 237 | realrepo=$(resolve_relative_url "$repo") || exit |
| 238 | ;; |
| 239 | *:*|/*) |
| 240 | # absolute url |
| 241 | realrepo=$repo |
| 242 | ;; |
| 243 | *) |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 244 | die "$(eval_gettext "repo URL: '\$repo' must be absolute or begin with ./|../")" |
Mark Levedahl | ec05df3 | 2008-07-09 21:05:40 -0400 | [diff] [blame] | 245 | ;; |
| 246 | esac |
| 247 | |
Michael J Gruber | db75ada | 2009-03-03 16:08:21 +0100 | [diff] [blame] | 248 | # normalize path: |
| 249 | # multiple //; leading ./; /./; /../; trailing / |
| 250 | path=$(printf '%s/\n' "$path" | |
| 251 | sed -e ' |
| 252 | s|//*|/|g |
| 253 | s|^\(\./\)*|| |
| 254 | s|/\./|/|g |
| 255 | :start |
| 256 | s|\([^/]*\)/\.\./|| |
| 257 | tstart |
| 258 | s|/*$|| |
| 259 | ') |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 260 | git ls-files --error-unmatch "$path" > /dev/null 2>&1 && |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 261 | die "$(eval_gettext "'\$path' already exists in the index")" |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 262 | |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 263 | if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1 |
| 264 | then |
Jon Seymour | 6ff875c | 2011-08-07 21:58:17 +1000 | [diff] [blame] | 265 | eval_gettextln "The following path is ignored by one of your .gitignore files: |
Ævar Arnfjörð Bjarmason | 3a4c3ed | 2011-05-21 18:44:07 +0000 | [diff] [blame] | 266 | \$path |
Jon Seymour | 6ff875c | 2011-08-07 21:58:17 +1000 | [diff] [blame] | 267 | Use -f if you really want to add it." >&2 |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 268 | exit 1 |
| 269 | fi |
| 270 | |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 271 | # perhaps the path exists and is already a git repo, else clone it |
| 272 | if test -e "$path" |
| 273 | then |
Mark Levedahl | e965647 | 2008-07-07 22:36:40 -0400 | [diff] [blame] | 274 | if test -d "$path"/.git -o -f "$path"/.git |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 275 | then |
Jon Seymour | 6ff875c | 2011-08-07 21:58:17 +1000 | [diff] [blame] | 276 | eval_gettextln "Adding existing repo at '\$path' to the index" |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 277 | else |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 278 | die "$(eval_gettext "'\$path' already exists and is not a valid git repo")" |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 279 | fi |
Mark Levedahl | c2f9391 | 2008-07-09 21:05:41 -0400 | [diff] [blame] | 280 | |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 281 | else |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 282 | |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 283 | module_clone "$path" "$realrepo" "$reference" || exit |
Ben Jackson | ea10b60 | 2009-04-18 20:42:07 -0700 | [diff] [blame] | 284 | ( |
Giuseppe Bilotta | 74ae141 | 2010-02-25 00:34:17 +0100 | [diff] [blame] | 285 | clear_local_git_env |
Ben Jackson | ea10b60 | 2009-04-18 20:42:07 -0700 | [diff] [blame] | 286 | cd "$path" && |
| 287 | # ash fails to wordsplit ${branch:+-b "$branch"...} |
| 288 | case "$branch" in |
| 289 | '') git checkout -f -q ;; |
Jonathan Nieder | 502dc5b | 2010-12-01 12:50:46 -0600 | [diff] [blame] | 290 | ?*) git checkout -f -q -B "$branch" "origin/$branch" ;; |
Ben Jackson | ea10b60 | 2009-04-18 20:42:07 -0700 | [diff] [blame] | 291 | esac |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 292 | ) || die "$(eval_gettext "Unable to checkout submodule '\$path'")" |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 293 | fi |
Junio C Hamano | c56dce3 | 2011-07-22 14:24:35 -0700 | [diff] [blame] | 294 | git config submodule."$path".url "$realrepo" |
Mark Levedahl | d4264ca | 2008-03-04 20:15:02 -0500 | [diff] [blame] | 295 | |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 296 | git add $force "$path" || |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 297 | die "$(eval_gettext "Failed to add submodule '\$path'")" |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 298 | |
Imran M Yousuf | a5099bb | 2008-05-15 13:42:58 +0600 | [diff] [blame] | 299 | git config -f .gitmodules submodule."$path".path "$path" && |
| 300 | git config -f .gitmodules submodule."$path".url "$repo" && |
Ævar Arnfjörð Bjarmason | 31991b0 | 2010-07-05 17:33:03 +0000 | [diff] [blame] | 301 | git add --force .gitmodules || |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 302 | die "$(eval_gettext "Failed to register submodule '\$path'")" |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | # |
Mark Levedahl | 19a31f9 | 2008-08-10 19:10:04 -0400 | [diff] [blame] | 306 | # Execute an arbitrary command sequence in each checked out |
| 307 | # submodule |
| 308 | # |
| 309 | # $@ = command to execute |
| 310 | # |
| 311 | cmd_foreach() |
| 312 | { |
Johan Herland | 1d5bec8 | 2009-08-19 03:45:19 +0200 | [diff] [blame] | 313 | # parse $args after "submodule ... foreach". |
| 314 | while test $# -ne 0 |
| 315 | do |
| 316 | case "$1" in |
| 317 | -q|--quiet) |
| 318 | GIT_QUIET=1 |
| 319 | ;; |
Johan Herland | 15fc56a | 2009-08-19 03:45:22 +0200 | [diff] [blame] | 320 | --recursive) |
| 321 | recursive=1 |
| 322 | ;; |
Johan Herland | 1d5bec8 | 2009-08-19 03:45:19 +0200 | [diff] [blame] | 323 | -*) |
| 324 | usage |
| 325 | ;; |
| 326 | *) |
| 327 | break |
| 328 | ;; |
| 329 | esac |
| 330 | shift |
| 331 | done |
| 332 | |
Ævar Arnfjörð Bjarmason | f030c96 | 2010-05-21 16:10:10 +0000 | [diff] [blame] | 333 | toplevel=$(pwd) |
| 334 | |
Brandon Casey | 4dca1aa | 2011-06-29 19:34:58 -0500 | [diff] [blame] | 335 | # dup stdin so that it can be restored when running the external |
| 336 | # command in the subshell (and a recursive call to this function) |
| 337 | exec 3<&0 |
| 338 | |
David Aguilar | a7b3269 | 2008-08-22 00:30:50 -0700 | [diff] [blame] | 339 | module_list | |
Mark Levedahl | 19a31f9 | 2008-08-10 19:10:04 -0400 | [diff] [blame] | 340 | while read mode sha1 stage path |
| 341 | do |
| 342 | if test -e "$path"/.git |
| 343 | then |
Ævar Arnfjörð Bjarmason | 490b6d5 | 2011-05-21 18:44:06 +0000 | [diff] [blame] | 344 | say "$(eval_gettext "Entering '\$prefix\$path'")" |
Johan Herland | 1e7f2aa | 2009-08-16 03:10:08 +0200 | [diff] [blame] | 345 | name=$(module_name "$path") |
Johan Herland | 15fc56a | 2009-08-19 03:45:22 +0200 | [diff] [blame] | 346 | ( |
| 347 | prefix="$prefix$path/" |
Giuseppe Bilotta | 74ae141 | 2010-02-25 00:34:17 +0100 | [diff] [blame] | 348 | clear_local_git_env |
Johan Herland | 15fc56a | 2009-08-19 03:45:22 +0200 | [diff] [blame] | 349 | cd "$path" && |
| 350 | eval "$@" && |
| 351 | if test -n "$recursive" |
| 352 | then |
| 353 | cmd_foreach "--recursive" "$@" |
| 354 | fi |
Brandon Casey | 4dca1aa | 2011-06-29 19:34:58 -0500 | [diff] [blame] | 355 | ) <&3 3<&- || |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 356 | die "$(eval_gettext "Stopping at '\$path'; script returned non-zero status.")" |
Mark Levedahl | 19a31f9 | 2008-08-10 19:10:04 -0400 | [diff] [blame] | 357 | fi |
| 358 | done |
| 359 | } |
| 360 | |
| 361 | # |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 362 | # Register submodules in .git/config |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 363 | # |
| 364 | # $@ = requested paths (default to all) |
| 365 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 366 | cmd_init() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 367 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 368 | # parse $args after "submodule ... init". |
| 369 | while test $# -ne 0 |
| 370 | do |
| 371 | case "$1" in |
| 372 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 373 | GIT_QUIET=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 374 | ;; |
| 375 | --) |
| 376 | shift |
| 377 | break |
| 378 | ;; |
| 379 | -*) |
| 380 | usage |
| 381 | ;; |
| 382 | *) |
| 383 | break |
| 384 | ;; |
| 385 | esac |
| 386 | shift |
| 387 | done |
| 388 | |
David Aguilar | a7b3269 | 2008-08-22 00:30:50 -0700 | [diff] [blame] | 389 | module_list "$@" | |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 390 | while read mode sha1 stage path |
| 391 | do |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 392 | # Skip already registered paths |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 393 | name=$(module_name "$path") || exit |
Jens Lehmann | 2cd9de3 | 2011-06-26 01:26:02 +0200 | [diff] [blame] | 394 | if test -z "$(git config "submodule.$name.url")" |
| 395 | then |
| 396 | url=$(git config -f .gitmodules submodule."$name".url) |
| 397 | test -z "$url" && |
Junio C Hamano | 0591c0a | 2011-07-19 09:45:37 -0700 | [diff] [blame] | 398 | die "$(eval_gettext "No url found for submodule path '\$path' in .gitmodules")" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 399 | |
Jens Lehmann | 2cd9de3 | 2011-06-26 01:26:02 +0200 | [diff] [blame] | 400 | # Possibly a url relative to parent |
| 401 | case "$url" in |
| 402 | ./*|../*) |
| 403 | url=$(resolve_relative_url "$url") || exit |
| 404 | ;; |
| 405 | esac |
| 406 | git config submodule."$name".url "$url" || |
Junio C Hamano | 0591c0a | 2011-07-19 09:45:37 -0700 | [diff] [blame] | 407 | die "$(eval_gettext "Failed to register url for submodule path '\$path'")" |
Jens Lehmann | 2cd9de3 | 2011-06-26 01:26:02 +0200 | [diff] [blame] | 408 | fi |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 409 | |
Jens Lehmann | 2cd9de3 | 2011-06-26 01:26:02 +0200 | [diff] [blame] | 410 | # Copy "update" setting when it is not set yet |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 411 | upd="$(git config -f .gitmodules submodule."$name".update)" |
| 412 | test -z "$upd" || |
Jens Lehmann | 2cd9de3 | 2011-06-26 01:26:02 +0200 | [diff] [blame] | 413 | test -n "$(git config submodule."$name".update)" || |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 414 | git config submodule."$name".update "$upd" || |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 415 | die "$(eval_gettext "Failed to register update mode for submodule path '\$path'")" |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 416 | |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 417 | say "$(eval_gettext "Submodule '\$name' (\$url) registered for path '\$path'")" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 418 | done |
| 419 | } |
| 420 | |
| 421 | # |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 422 | # 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] | 423 | # |
| 424 | # $@ = requested paths (default to all) |
| 425 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 426 | cmd_update() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 427 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 428 | # parse $args after "submodule ... update". |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 429 | orig_flags= |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 430 | while test $# -ne 0 |
| 431 | do |
| 432 | case "$1" in |
| 433 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 434 | GIT_QUIET=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 435 | ;; |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 436 | -i|--init) |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 437 | init=1 |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 438 | ;; |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 439 | -N|--no-fetch) |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 440 | nofetch=1 |
| 441 | ;; |
Nicolas Morey-Chaisemartin | 9db31bd | 2011-04-01 11:42:03 +0200 | [diff] [blame] | 442 | -f|--force) |
| 443 | force=$1 |
| 444 | ;; |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 445 | -r|--rebase) |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 446 | update="rebase" |
Peter Hutterer | ca2cedb | 2009-04-24 09:06:38 +1000 | [diff] [blame] | 447 | ;; |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 448 | --reference) |
| 449 | case "$2" in '') usage ;; esac |
| 450 | reference="--reference=$2" |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 451 | orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")" |
| 452 | shift |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 453 | ;; |
| 454 | --reference=*) |
| 455 | reference="$1" |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 456 | ;; |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 457 | -m|--merge) |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 458 | update="merge" |
| 459 | ;; |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 460 | --recursive) |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 461 | recursive=1 |
| 462 | ;; |
Junio C Hamano | efc5fb6 | 2011-10-10 15:56:16 -0700 | [diff] [blame] | 463 | --checkout) |
| 464 | update="checkout" |
| 465 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 466 | --) |
| 467 | shift |
| 468 | break |
| 469 | ;; |
| 470 | -*) |
| 471 | usage |
| 472 | ;; |
| 473 | *) |
| 474 | break |
| 475 | ;; |
| 476 | esac |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 477 | orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")" |
| 478 | shift |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 479 | done |
| 480 | |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 481 | if test -n "$init" |
| 482 | then |
| 483 | cmd_init "--" "$@" || return |
| 484 | fi |
| 485 | |
Spencer E. Olson | 1b4735d | 2011-02-17 09:18:45 -0700 | [diff] [blame] | 486 | cloned_modules= |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 487 | module_list "$@" | { |
| 488 | err= |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 489 | while read mode sha1 stage path |
| 490 | do |
Nicolas Morey-Chaisemartin | 313ee0d | 2011-03-30 07:20:02 +0200 | [diff] [blame] | 491 | if test "$stage" = U |
| 492 | then |
| 493 | echo >&2 "Skipping unmerged submodule $path" |
| 494 | continue |
| 495 | fi |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 496 | name=$(module_name "$path") || exit |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 497 | url=$(git config submodule."$name".url) |
Junio C Hamano | efc5fb6 | 2011-10-10 15:56:16 -0700 | [diff] [blame] | 498 | if ! test -z "$update" |
| 499 | then |
| 500 | update_module=$update |
| 501 | else |
| 502 | update_module=$(git config submodule."$name".update) |
| 503 | fi |
| 504 | |
| 505 | if test "$update_module" = "none" |
| 506 | then |
| 507 | echo "Skipping submodule '$path'" |
| 508 | continue |
| 509 | fi |
| 510 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 511 | if test -z "$url" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 512 | then |
| 513 | # Only mention uninitialized submodules when its |
| 514 | # path have been specified |
| 515 | test "$#" != "0" && |
Ævar Arnfjörð Bjarmason | 1c2ef66 | 2011-05-21 18:44:08 +0000 | [diff] [blame] | 516 | say "$(eval_gettext "Submodule path '\$path' not initialized |
| 517 | Maybe you want to use 'update --init'?")" |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 518 | continue |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 519 | fi |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 520 | |
Lars Hjemli | ba88a1f | 2008-02-20 23:13:15 +0100 | [diff] [blame] | 521 | if ! test -d "$path"/.git -o -f "$path"/.git |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 522 | then |
Michael S. Tsirkin | d92a395 | 2009-05-04 22:30:01 +0300 | [diff] [blame] | 523 | module_clone "$path" "$url" "$reference"|| exit |
Spencer E. Olson | 1b4735d | 2011-02-17 09:18:45 -0700 | [diff] [blame] | 524 | cloned_modules="$cloned_modules;$name" |
Lars Hjemli | bf2d824 | 2007-06-11 21:12:22 +0200 | [diff] [blame] | 525 | subsha1= |
| 526 | else |
Giuseppe Bilotta | 74ae141 | 2010-02-25 00:34:17 +0100 | [diff] [blame] | 527 | subsha1=$(clear_local_git_env; cd "$path" && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 528 | git rev-parse --verify HEAD) || |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 529 | die "$(eval_gettext "Unable to find current revision in submodule path '\$path'")" |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 530 | fi |
| 531 | |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 532 | if test "$subsha1" != "$sha1" |
| 533 | then |
Nicolas Morey-Chaisemartin | 9db31bd | 2011-04-01 11:42:03 +0200 | [diff] [blame] | 534 | subforce=$force |
| 535 | # If we don't already have a -f flag and the submodule has never been checked out |
| 536 | if test -z "$subsha1" -a -z "$force" |
Ping Yin | b9b378a | 2008-09-26 23:33:23 +0800 | [diff] [blame] | 537 | then |
Nicolas Morey-Chaisemartin | 9db31bd | 2011-04-01 11:42:03 +0200 | [diff] [blame] | 538 | subforce="-f" |
Ping Yin | b9b378a | 2008-09-26 23:33:23 +0800 | [diff] [blame] | 539 | fi |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 540 | |
| 541 | if test -z "$nofetch" |
| 542 | then |
Jens Lehmann | e5f522d | 2011-03-06 23:13:36 +0100 | [diff] [blame] | 543 | # Run fetch only if $sha1 isn't present or it |
| 544 | # is not reachable from a ref. |
Giuseppe Bilotta | 74ae141 | 2010-02-25 00:34:17 +0100 | [diff] [blame] | 545 | (clear_local_git_env; cd "$path" && |
Brandon Casey | f5799e0 | 2011-05-26 13:52:04 -0700 | [diff] [blame] | 546 | ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) && |
Jens Lehmann | e5f522d | 2011-03-06 23:13:36 +0100 | [diff] [blame] | 547 | test -z "$rev") || git-fetch)) || |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 548 | die "$(eval_gettext "Unable to fetch in submodule path '\$path'")" |
Fabian Franz | 31ca3ac | 2009-02-05 20:18:32 -0200 | [diff] [blame] | 549 | fi |
| 550 | |
Spencer E. Olson | 1b4735d | 2011-02-17 09:18:45 -0700 | [diff] [blame] | 551 | # Is this something we just cloned? |
| 552 | case ";$cloned_modules;" in |
| 553 | *";$name;"*) |
| 554 | # then there is no local change to integrate |
| 555 | update_module= ;; |
| 556 | esac |
| 557 | |
Junio C Hamano | 877449c | 2011-06-13 12:17:52 -0700 | [diff] [blame] | 558 | must_die_on_failure= |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 559 | case "$update_module" in |
| 560 | rebase) |
| 561 | command="git rebase" |
Ævar Arnfjörð Bjarmason | ee653c8 | 2011-05-21 18:44:02 +0000 | [diff] [blame] | 562 | die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$path'")" |
| 563 | say_msg="$(eval_gettext "Submodule path '\$path': rebased into '\$sha1'")" |
Junio C Hamano | 877449c | 2011-06-13 12:17:52 -0700 | [diff] [blame] | 564 | must_die_on_failure=yes |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 565 | ;; |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 566 | merge) |
| 567 | command="git merge" |
Ævar Arnfjörð Bjarmason | ee653c8 | 2011-05-21 18:44:02 +0000 | [diff] [blame] | 568 | die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$path'")" |
| 569 | say_msg="$(eval_gettext "Submodule path '\$path': merged in '\$sha1'")" |
Junio C Hamano | 877449c | 2011-06-13 12:17:52 -0700 | [diff] [blame] | 570 | must_die_on_failure=yes |
Johan Herland | 42b4917 | 2009-06-03 00:59:12 +0200 | [diff] [blame] | 571 | ;; |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 572 | *) |
Nicolas Morey-Chaisemartin | 9db31bd | 2011-04-01 11:42:03 +0200 | [diff] [blame] | 573 | command="git checkout $subforce -q" |
Ævar Arnfjörð Bjarmason | ee653c8 | 2011-05-21 18:44:02 +0000 | [diff] [blame] | 574 | die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$path'")" |
| 575 | say_msg="$(eval_gettext "Submodule path '\$path': checked out '\$sha1'")" |
Johan Herland | 3294842 | 2009-06-03 08:27:06 +0200 | [diff] [blame] | 576 | ;; |
| 577 | esac |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 578 | |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 579 | if (clear_local_git_env; cd "$path" && $command "$sha1") |
| 580 | then |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 581 | say "$say_msg" |
Junio C Hamano | 877449c | 2011-06-13 12:17:52 -0700 | [diff] [blame] | 582 | elif test -n "$must_die_on_failure" |
| 583 | then |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 584 | die_with_status 2 "$die_msg" |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 585 | else |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 586 | err="${err};$die_msg" |
Junio C Hamano | 877449c | 2011-06-13 12:17:52 -0700 | [diff] [blame] | 587 | continue |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 588 | fi |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 589 | fi |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 590 | |
| 591 | if test -n "$recursive" |
| 592 | then |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 593 | (clear_local_git_env; cd "$path" && eval cmd_update "$orig_flags") |
| 594 | res=$? |
| 595 | if test $res -gt 0 |
| 596 | then |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 597 | die_msg="$(eval_gettext "Failed to recurse into submodule path '\$path'")" |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 598 | if test $res -eq 1 |
| 599 | then |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 600 | err="${err};$die_msg" |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 601 | continue |
| 602 | else |
Junio C Hamano | ff968f0 | 2011-07-13 14:31:35 -0700 | [diff] [blame] | 603 | die_with_status $res "$die_msg" |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 604 | fi |
| 605 | fi |
Johan Herland | b13fd5c | 2009-08-19 03:45:23 +0200 | [diff] [blame] | 606 | fi |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 607 | done |
Fredrik Gustafsson | 15ffb7c | 2011-06-13 19:15:26 +0200 | [diff] [blame] | 608 | |
| 609 | if test -n "$err" |
| 610 | then |
| 611 | OIFS=$IFS |
| 612 | IFS=';' |
| 613 | for e in $err |
| 614 | do |
| 615 | if test -n "$e" |
| 616 | then |
| 617 | echo >&2 "$e" |
| 618 | fi |
| 619 | done |
| 620 | IFS=$OIFS |
| 621 | exit 1 |
| 622 | fi |
| 623 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 624 | } |
| 625 | |
Emil Medve | bffe71f | 2007-06-26 18:40:58 -0500 | [diff] [blame] | 626 | set_name_rev () { |
| 627 | revname=$( ( |
Giuseppe Bilotta | 74ae141 | 2010-02-25 00:34:17 +0100 | [diff] [blame] | 628 | clear_local_git_env |
Emil Medve | bffe71f | 2007-06-26 18:40:58 -0500 | [diff] [blame] | 629 | cd "$1" && { |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 630 | git describe "$2" 2>/dev/null || |
| 631 | git describe --tags "$2" 2>/dev/null || |
Mark Levedahl | f669ac0 | 2008-04-14 22:48:06 -0400 | [diff] [blame] | 632 | git describe --contains "$2" 2>/dev/null || |
| 633 | git describe --all --always "$2" |
Emil Medve | bffe71f | 2007-06-26 18:40:58 -0500 | [diff] [blame] | 634 | } |
| 635 | ) ) |
| 636 | test -z "$revname" || revname=" ($revname)" |
| 637 | } |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 638 | # |
| 639 | # Show commit summary for submodules in index or working tree |
| 640 | # |
| 641 | # If '--cached' is given, show summary between index and given commit, |
| 642 | # or between working tree and given commit |
| 643 | # |
| 644 | # $@ = [commit (default 'HEAD'),] requested paths (default all) |
| 645 | # |
| 646 | cmd_summary() { |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 647 | summary_limit=-1 |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 648 | for_status= |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 649 | diff_cmd=diff-index |
Emil Medve | bffe71f | 2007-06-26 18:40:58 -0500 | [diff] [blame] | 650 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 651 | # parse $args after "submodule ... summary". |
| 652 | while test $# -ne 0 |
| 653 | do |
| 654 | case "$1" in |
| 655 | --cached) |
| 656 | cached="$1" |
| 657 | ;; |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 658 | --files) |
| 659 | files="$1" |
| 660 | ;; |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 661 | --for-status) |
| 662 | for_status="$1" |
| 663 | ;; |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 664 | -n|--summary-limit) |
| 665 | if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2" |
| 666 | then |
| 667 | : |
| 668 | else |
| 669 | usage |
| 670 | fi |
| 671 | shift |
| 672 | ;; |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 673 | --) |
| 674 | shift |
| 675 | break |
| 676 | ;; |
| 677 | -*) |
| 678 | usage |
| 679 | ;; |
| 680 | *) |
| 681 | break |
| 682 | ;; |
| 683 | esac |
| 684 | shift |
| 685 | done |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 686 | |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 687 | test $summary_limit = 0 && return |
| 688 | |
Johan Herland | 3deea89 | 2010-02-16 11:21:14 +0100 | [diff] [blame] | 689 | if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"}) |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 690 | then |
| 691 | head=$rev |
Jeff King | caa9c3c | 2010-03-03 14:19:09 -0800 | [diff] [blame] | 692 | test $# = 0 || shift |
Johan Herland | 3deea89 | 2010-02-16 11:21:14 +0100 | [diff] [blame] | 693 | elif test -z "$1" -o "$1" = "HEAD" |
| 694 | then |
Junio C Hamano | 14e940d | 2010-03-03 14:19:10 -0800 | [diff] [blame] | 695 | # before the first commit: compare with an empty tree |
| 696 | head=$(git hash-object -w -t tree --stdin </dev/null) |
Jens Lehmann | 2ea6c2c | 2010-03-09 15:55:32 +0100 | [diff] [blame] | 697 | test -z "$1" || shift |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 698 | else |
Johan Herland | 3deea89 | 2010-02-16 11:21:14 +0100 | [diff] [blame] | 699 | head="HEAD" |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 700 | fi |
| 701 | |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 702 | if [ -n "$files" ] |
| 703 | then |
| 704 | test -n "$cached" && |
Ævar Arnfjörð Bjarmason | b9b9c22 | 2011-05-21 18:44:03 +0000 | [diff] [blame] | 705 | die "$(gettext -- "--cached cannot be used with --files")" |
Jens Lehmann | 1c244f6 | 2009-08-13 21:32:50 +0200 | [diff] [blame] | 706 | diff_cmd=diff-files |
| 707 | head= |
| 708 | fi |
| 709 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 710 | cd_to_toplevel |
| 711 | # Get modified modules cared by user |
Jens Lehmann | 1807650 | 2010-06-25 16:56:02 +0200 | [diff] [blame] | 712 | modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" | |
Junio C Hamano | e1622bf | 2009-11-23 15:56:32 -0800 | [diff] [blame] | 713 | sane_egrep '^:([0-7]* )?160000' | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 714 | while read mod_src mod_dst sha1_src sha1_dst status name |
| 715 | do |
| 716 | # Always show modules deleted or type-changed (blob<->module) |
| 717 | test $status = D -o $status = T && echo "$name" && continue |
| 718 | # Also show added or modified modules which are checked out |
| 719 | GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 && |
| 720 | echo "$name" |
| 721 | done |
| 722 | ) |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 723 | |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 724 | test -z "$modules" && return |
| 725 | |
Jens Lehmann | 1807650 | 2010-06-25 16:56:02 +0200 | [diff] [blame] | 726 | git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules | |
Junio C Hamano | e1622bf | 2009-11-23 15:56:32 -0800 | [diff] [blame] | 727 | sane_egrep '^:([0-7]* )?160000' | |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 728 | cut -c2- | |
| 729 | while read mod_src mod_dst sha1_src sha1_dst status name |
| 730 | do |
| 731 | if test -z "$cached" && |
| 732 | test $sha1_dst = 0000000000000000000000000000000000000000 |
| 733 | then |
| 734 | case "$mod_dst" in |
| 735 | 160000) |
| 736 | sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD) |
| 737 | ;; |
| 738 | 100644 | 100755 | 120000) |
| 739 | sha1_dst=$(git hash-object $name) |
| 740 | ;; |
| 741 | 000000) |
| 742 | ;; # removed |
| 743 | *) |
| 744 | # unexpected type |
Jon Seymour | 6ff875c | 2011-08-07 21:58:17 +1000 | [diff] [blame] | 745 | eval_gettextln "unexpected mode \$mod_dst" >&2 |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 746 | continue ;; |
| 747 | esac |
| 748 | fi |
| 749 | missing_src= |
| 750 | missing_dst= |
| 751 | |
| 752 | test $mod_src = 160000 && |
Miklos Vajna | 30353a4 | 2008-12-03 14:26:52 +0100 | [diff] [blame] | 753 | ! 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] | 754 | missing_src=t |
| 755 | |
| 756 | test $mod_dst = 160000 && |
Miklos Vajna | 30353a4 | 2008-12-03 14:26:52 +0100 | [diff] [blame] | 757 | ! 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] | 758 | missing_dst=t |
| 759 | |
| 760 | total_commits= |
| 761 | case "$missing_src,$missing_dst" in |
| 762 | t,) |
Ævar Arnfjörð Bjarmason | f62f821 | 2011-05-21 18:44:05 +0000 | [diff] [blame] | 763 | errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \$sha1_src")" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 764 | ;; |
| 765 | ,t) |
Ævar Arnfjörð Bjarmason | f62f821 | 2011-05-21 18:44:05 +0000 | [diff] [blame] | 766 | errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \$sha1_dst")" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 767 | ;; |
| 768 | t,t) |
Ævar Arnfjörð Bjarmason | f62f821 | 2011-05-21 18:44:05 +0000 | [diff] [blame] | 769 | errmsg="$(eval_gettext " Warn: \$name doesn't contain commits \$sha1_src and \$sha1_dst")" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 770 | ;; |
| 771 | *) |
| 772 | errmsg= |
| 773 | total_commits=$( |
| 774 | if test $mod_src = 160000 -a $mod_dst = 160000 |
| 775 | then |
| 776 | range="$sha1_src...$sha1_dst" |
| 777 | elif test $mod_src = 160000 |
| 778 | then |
| 779 | range=$sha1_src |
| 780 | else |
| 781 | range=$sha1_dst |
| 782 | fi |
| 783 | GIT_DIR="$name/.git" \ |
Jeff King | b0e621a | 2010-04-08 15:42:37 -0400 | [diff] [blame] | 784 | git rev-list --first-parent $range -- | wc -l |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 785 | ) |
Johannes Sixt | eed3559 | 2008-03-12 09:30:01 +0100 | [diff] [blame] | 786 | total_commits=" ($(($total_commits + 0)))" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 787 | ;; |
| 788 | esac |
| 789 | |
| 790 | sha1_abbr_src=$(echo $sha1_src | cut -c1-7) |
| 791 | sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7) |
| 792 | if test $status = T |
| 793 | then |
Ævar Arnfjörð Bjarmason | b3e7344 | 2011-05-21 18:44:09 +0000 | [diff] [blame] | 794 | blob="$(gettext "blob")" |
| 795 | submodule="$(gettext "submodule")" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 796 | if test $mod_dst = 160000 |
| 797 | then |
Ævar Arnfjörð Bjarmason | b3e7344 | 2011-05-21 18:44:09 +0000 | [diff] [blame] | 798 | echo "* $name $sha1_abbr_src($blob)->$sha1_abbr_dst($submodule)$total_commits:" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 799 | else |
Ævar Arnfjörð Bjarmason | b3e7344 | 2011-05-21 18:44:09 +0000 | [diff] [blame] | 800 | echo "* $name $sha1_abbr_src($submodule)->$sha1_abbr_dst($blob)$total_commits:" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 801 | fi |
| 802 | else |
| 803 | echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:" |
| 804 | fi |
| 805 | if test -n "$errmsg" |
| 806 | then |
| 807 | # Don't give error msg for modification whose dst is not submodule |
| 808 | # i.e. deleted or changed to blob |
| 809 | test $mod_dst = 160000 && echo "$errmsg" |
| 810 | else |
| 811 | if test $mod_src = 160000 -a $mod_dst = 160000 |
| 812 | then |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 813 | limit= |
| 814 | test $summary_limit -gt 0 && limit="-$summary_limit" |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 815 | GIT_DIR="$name/.git" \ |
Ping Yin | f2dc06a | 2008-03-11 21:52:17 +0800 | [diff] [blame] | 816 | git log $limit --pretty='format: %m %s' \ |
Ping Yin | 1cb639e | 2008-03-11 21:52:16 +0800 | [diff] [blame] | 817 | --first-parent $sha1_src...$sha1_dst |
| 818 | elif test $mod_dst = 160000 |
| 819 | then |
| 820 | GIT_DIR="$name/.git" \ |
| 821 | git log --pretty='format: > %s' -1 $sha1_dst |
| 822 | else |
| 823 | GIT_DIR="$name/.git" \ |
| 824 | git log --pretty='format: < %s' -1 $sha1_src |
| 825 | fi |
| 826 | echo |
| 827 | fi |
| 828 | echo |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 829 | done | |
| 830 | if test -n "$for_status"; then |
Jens Lehmann | f17a5d3 | 2010-01-17 20:42:31 +0100 | [diff] [blame] | 831 | if [ -n "$files" ]; then |
Jon Seymour | 6ff875c | 2011-08-07 21:58:17 +1000 | [diff] [blame] | 832 | gettextln "# Submodules changed but not updated:" |
Jens Lehmann | f17a5d3 | 2010-01-17 20:42:31 +0100 | [diff] [blame] | 833 | else |
Jon Seymour | 6ff875c | 2011-08-07 21:58:17 +1000 | [diff] [blame] | 834 | gettextln "# Submodule changes to be committed:" |
Jens Lehmann | f17a5d3 | 2010-01-17 20:42:31 +0100 | [diff] [blame] | 835 | fi |
Ping Yin | d0f64dd | 2008-04-12 23:05:31 +0800 | [diff] [blame] | 836 | echo "#" |
| 837 | sed -e 's|^|# |' -e 's|^# $|#|' |
| 838 | else |
| 839 | cat |
| 840 | fi |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 841 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 842 | # |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 843 | # List all submodules, prefixed with: |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 844 | # - submodule not initialized |
| 845 | # + different revision checked out |
| 846 | # |
| 847 | # If --cached was specified the revision in the index will be printed |
| 848 | # instead of the currently checked out revision. |
| 849 | # |
| 850 | # $@ = requested paths (default to all) |
| 851 | # |
Junio C Hamano | 23a485e | 2008-01-15 02:35:49 -0800 | [diff] [blame] | 852 | cmd_status() |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 853 | { |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 854 | # parse $args after "submodule ... status". |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 855 | orig_flags= |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 856 | while test $# -ne 0 |
| 857 | do |
| 858 | case "$1" in |
| 859 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 860 | GIT_QUIET=1 |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 861 | ;; |
| 862 | --cached) |
| 863 | cached=1 |
| 864 | ;; |
Johan Herland | 64b19ff | 2009-08-19 03:45:24 +0200 | [diff] [blame] | 865 | --recursive) |
| 866 | recursive=1 |
| 867 | ;; |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 868 | --) |
| 869 | shift |
| 870 | break |
| 871 | ;; |
| 872 | -*) |
| 873 | usage |
| 874 | ;; |
| 875 | *) |
| 876 | break |
| 877 | ;; |
| 878 | esac |
Kevin Ballard | 98dbe63 | 2010-11-02 23:26:25 -0700 | [diff] [blame] | 879 | orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")" |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 880 | shift |
| 881 | done |
| 882 | |
David Aguilar | a7b3269 | 2008-08-22 00:30:50 -0700 | [diff] [blame] | 883 | module_list "$@" | |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 884 | while read mode sha1 stage path |
| 885 | do |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 886 | name=$(module_name "$path") || exit |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 887 | url=$(git config submodule."$name".url) |
Johan Herland | 64b19ff | 2009-08-19 03:45:24 +0200 | [diff] [blame] | 888 | displaypath="$prefix$path" |
Nicolas Morey-Chaisemartin | 313ee0d | 2011-03-30 07:20:02 +0200 | [diff] [blame] | 889 | if test "$stage" = U |
| 890 | then |
| 891 | say "U$sha1 $displaypath" |
| 892 | continue |
| 893 | fi |
Lars Hjemli | ba88a1f | 2008-02-20 23:13:15 +0100 | [diff] [blame] | 894 | if test -z "$url" || ! test -d "$path"/.git -o -f "$path"/.git |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 895 | then |
Johan Herland | 64b19ff | 2009-08-19 03:45:24 +0200 | [diff] [blame] | 896 | say "-$sha1 $displaypath" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 897 | continue; |
| 898 | fi |
CJ van den Berg | 41c7c1b | 2007-07-04 18:22:14 +0200 | [diff] [blame] | 899 | set_name_rev "$path" "$sha1" |
Jens Lehmann | 1807650 | 2010-06-25 16:56:02 +0200 | [diff] [blame] | 900 | if git diff-files --ignore-submodules=dirty --quiet -- "$path" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 901 | then |
Johan Herland | 64b19ff | 2009-08-19 03:45:24 +0200 | [diff] [blame] | 902 | say " $sha1 $displaypath$revname" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 903 | else |
| 904 | if test -z "$cached" |
| 905 | then |
Giuseppe Bilotta | 74ae141 | 2010-02-25 00:34:17 +0100 | [diff] [blame] | 906 | sha1=$(clear_local_git_env; cd "$path" && git rev-parse --verify HEAD) |
CJ van den Berg | 41c7c1b | 2007-07-04 18:22:14 +0200 | [diff] [blame] | 907 | set_name_rev "$path" "$sha1" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 908 | fi |
Johan Herland | 64b19ff | 2009-08-19 03:45:24 +0200 | [diff] [blame] | 909 | say "+$sha1 $displaypath$revname" |
| 910 | fi |
| 911 | |
| 912 | if test -n "$recursive" |
| 913 | then |
| 914 | ( |
| 915 | prefix="$displaypath/" |
Giuseppe Bilotta | 74ae141 | 2010-02-25 00:34:17 +0100 | [diff] [blame] | 916 | clear_local_git_env |
Johan Herland | 64b19ff | 2009-08-19 03:45:24 +0200 | [diff] [blame] | 917 | cd "$path" && |
Kevin Ballard | a7eff1a | 2010-11-02 23:26:24 -0700 | [diff] [blame] | 918 | eval cmd_status "$orig_args" |
Johan Herland | 64b19ff | 2009-08-19 03:45:24 +0200 | [diff] [blame] | 919 | ) || |
Ævar Arnfjörð Bjarmason | 497ee87 | 2011-05-21 18:44:01 +0000 | [diff] [blame] | 920 | die "$(eval_gettext "Failed to recurse into submodule path '\$path'")" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 921 | fi |
| 922 | done |
| 923 | } |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 924 | # |
| 925 | # Sync remote urls for submodules |
| 926 | # This makes the value for remote.$remote.url match the value |
| 927 | # specified in .gitmodules. |
| 928 | # |
| 929 | cmd_sync() |
| 930 | { |
| 931 | while test $# -ne 0 |
| 932 | do |
| 933 | case "$1" in |
| 934 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 935 | GIT_QUIET=1 |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 936 | shift |
| 937 | ;; |
| 938 | --) |
| 939 | shift |
| 940 | break |
| 941 | ;; |
| 942 | -*) |
| 943 | usage |
| 944 | ;; |
| 945 | *) |
| 946 | break |
| 947 | ;; |
| 948 | esac |
| 949 | done |
| 950 | cd_to_toplevel |
| 951 | module_list "$@" | |
| 952 | while read mode sha1 stage path |
| 953 | do |
| 954 | name=$(module_name "$path") |
| 955 | url=$(git config -f .gitmodules --get submodule."$name".url) |
Johan Herland | baede9f | 2008-09-22 18:08:31 +0200 | [diff] [blame] | 956 | |
| 957 | # Possibly a url relative to parent |
| 958 | case "$url" in |
| 959 | ./*|../*) |
| 960 | url=$(resolve_relative_url "$url") || exit |
| 961 | ;; |
| 962 | esac |
| 963 | |
Junio C Hamano | ccee608 | 2011-06-25 22:41:25 +0200 | [diff] [blame] | 964 | if git config "submodule.$name.url" >/dev/null 2>/dev/null |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 965 | then |
Junio C Hamano | 0591c0a | 2011-07-19 09:45:37 -0700 | [diff] [blame] | 966 | say "$(eval_gettext "Synchronizing submodule url for '\$name'")" |
Junio C Hamano | ccee608 | 2011-06-25 22:41:25 +0200 | [diff] [blame] | 967 | git config submodule."$name".url "$url" |
| 968 | |
| 969 | if test -e "$path"/.git |
| 970 | then |
| 971 | ( |
| 972 | clear_local_git_env |
| 973 | cd "$path" |
| 974 | remote=$(get_default_remote) |
| 975 | git config remote."$remote".url "$url" |
| 976 | ) |
| 977 | fi |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 978 | fi |
| 979 | done |
| 980 | } |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 981 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 982 | # This loop parses the command line arguments to find the |
| 983 | # subcommand name to dispatch. Parsing of the subcommand specific |
| 984 | # options are primarily done by the subcommand implementations. |
| 985 | # Subcommand specific options such as --branch and --cached are |
| 986 | # parsed here as well, for backward compatibility. |
| 987 | |
| 988 | while test $# != 0 && test -z "$command" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 989 | do |
| 990 | case "$1" in |
David Aguilar | 2327f61 | 2008-08-24 12:43:37 -0700 | [diff] [blame] | 991 | add | foreach | init | update | status | summary | sync) |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 992 | command=$1 |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 993 | ;; |
| 994 | -q|--quiet) |
Stephen Boyd | 2e6a30e | 2009-06-16 15:33:00 -0700 | [diff] [blame] | 995 | GIT_QUIET=1 |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 996 | ;; |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 997 | -b|--branch) |
| 998 | case "$2" in |
| 999 | '') |
| 1000 | usage |
| 1001 | ;; |
| 1002 | esac |
| 1003 | branch="$2"; shift |
| 1004 | ;; |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 1005 | --cached) |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 1006 | cached="$1" |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 1007 | ;; |
| 1008 | --) |
| 1009 | break |
| 1010 | ;; |
| 1011 | -*) |
| 1012 | usage |
| 1013 | ;; |
| 1014 | *) |
| 1015 | break |
| 1016 | ;; |
| 1017 | esac |
| 1018 | shift |
| 1019 | done |
| 1020 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 1021 | # No command word defaults to "status" |
| 1022 | test -n "$command" || command=status |
Sven Verdoolaege | ecda072 | 2007-06-24 23:06:07 +0200 | [diff] [blame] | 1023 | |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 1024 | # "-b branch" is accepted only by "add" |
| 1025 | if test -n "$branch" && test "$command" != add |
| 1026 | then |
Lars Hjemli | 70c7ac2 | 2007-05-26 15:56:40 +0200 | [diff] [blame] | 1027 | usage |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 1028 | fi |
| 1029 | |
Ping Yin | 28f9af5 | 2008-03-11 21:52:15 +0800 | [diff] [blame] | 1030 | # "--cached" is accepted only by "status" and "summary" |
| 1031 | if test -n "$cached" && test "$command" != status -a "$command" != summary |
Junio C Hamano | 5c08dbb | 2008-01-15 02:48:45 -0800 | [diff] [blame] | 1032 | then |
| 1033 | usage |
| 1034 | fi |
| 1035 | |
| 1036 | "cmd_$command" "$@" |