| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # | ||||
| 3 | # Wrapper for git to handle more subdirs at the same time | ||||
| 4 | # | ||||
| Norbert Thiebaud | 8feb6c0 | 2010-11-22 03:11:56 -0600 | [diff] [blame] | 5 | |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 6 | if [ -n "$g_debug" ] ; then |
| 7 | set -x | ||||
| 8 | fi | ||||
| 9 | |||||
| Norbert Thiebaud | 060219a | 2012-11-08 16:25:37 -0600 | [diff] [blame] | 10 | SUBMODULES_ALL="dictionaries helpcontent2 translations" |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 11 | |
| 12 | pushd $(dirname $0) > /dev/null | ||||
| Norbert Thiebaud | ae4e327 | 2012-12-11 07:49:24 -0600 | [diff] [blame] | 13 | if [ -f config_host.mk ] ; then |
| Luboš Luňák | c8c056f | 2012-12-11 15:39:49 +0100 | [diff] [blame] | 14 | # we are in the BUILDDIR |
| Ilmari Lauhakangas | 55c5b27 | 2017-04-15 18:35:17 +0300 | [diff] [blame] | 15 | SRC_ROOT=$(< config_host.mk grep -a SRC_ROOT | sed -e "s/.*=//") |
| Norbert Thiebaud | ae4e327 | 2012-12-11 07:49:24 -0600 | [diff] [blame] | 16 | else |
| 17 | SRC_ROOT=$(pwd) | ||||
| 18 | fi | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 19 | popd > /dev/null |
| 20 | |||||
| Norbert Thiebaud | ae4e327 | 2012-12-11 07:49:24 -0600 | [diff] [blame] | 21 | COREDIR="$SRC_ROOT" |
| 22 | |||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 23 | usage() |
| 24 | { | ||||
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 25 | git |
| 26 | echo | ||||
| Arnaud VERSINI | 5448ad5 | 2022-01-02 17:33:27 +0100 | [diff] [blame] | 27 | echo "Usage: g [options] [git (checkout|clone|fetch|gc|grep|pull|push|reset) [git options/args..]]" |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 28 | echo "" |
| Peter Foley | 41b5c80 | 2012-10-16 20:43:21 -0400 | [diff] [blame] | 29 | echo " -z restore the git hooks and do other sanity checks" |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 30 | } |
| 31 | |||||
| 32 | refresh_submodule_hooks() | ||||
| 33 | { | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 34 | local repo=$1 |
| 35 | local hook | ||||
| 36 | local hook_name | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 37 | |
| Ilmari Lauhakangas | e5b1c53 | 2017-04-27 12:46:47 +0300 | [diff] [blame] | 38 | if [ -d "${repo?}"/.git ] ; then |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 39 | # use core's hook by default |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 40 | for hook_name in "${COREDIR?}/.git-hooks"/* ; do |
| Mike Kaganski | 0e6e10c | 2021-03-04 11:40:05 +0300 | [diff] [blame] | 41 | if [ ! -e "${hook_name}" ] ; then |
| 42 | continue | ||||
| 43 | fi | ||||
| Ilmari Lauhakangas | 55c5b27 | 2017-04-15 18:35:17 +0300 | [diff] [blame] | 44 | hook="${repo?}/.git/hooks/${hook_name##*/}" |
| 45 | if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 46 | rm -f "${hook?}" |
| 47 | ln -sf "${hook_name}" "${hook?}" | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 48 | fi |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 49 | done |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 50 | # override if need be by the submodules' own hooks |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 51 | for hook_name in "${COREDIR?}/${repo?}/.git-hooks"/* ; do |
| Mike Kaganski | 0e6e10c | 2021-03-04 11:40:05 +0300 | [diff] [blame] | 52 | if [ ! -e "${hook_name}" ] ; then |
| 53 | continue | ||||
| 54 | fi | ||||
| Ilmari Lauhakangas | 55c5b27 | 2017-04-15 18:35:17 +0300 | [diff] [blame] | 55 | hook="${repo?}/.git/hooks/${hook_name##*/}" |
| 56 | if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 57 | rm -f "${hook?}" |
| 58 | ln -sf "${hook_name}" "${hook?}" | ||||
| 59 | fi | ||||
| 60 | done | ||||
| Ilmari Lauhakangas | e5b1c53 | 2017-04-27 12:46:47 +0300 | [diff] [blame] | 61 | elif [ -d .git/modules/"${repo}"/hooks ] ; then |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 62 | for hook_name in "${COREDIR?}/.git-hooks"/* ; do |
| Mike Kaganski | 0e6e10c | 2021-03-04 11:40:05 +0300 | [diff] [blame] | 63 | if [ ! -e "${hook_name}" ] ; then |
| 64 | continue | ||||
| 65 | fi | ||||
| Ilmari Lauhakangas | 55c5b27 | 2017-04-15 18:35:17 +0300 | [diff] [blame] | 66 | hook=".git/modules/${repo?}/hooks/${hook_name##*/}" |
| 67 | if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 68 | rm -f "${hook?}" |
| 69 | ln -sf "${hook_name}" "${hook?}" | ||||
| Norbert Thiebaud | 0cac67b | 2012-12-21 04:33:20 -0600 | [diff] [blame] | 70 | fi |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 71 | done |
| Norbert Thiebaud | 0cac67b | 2012-12-21 04:33:20 -0600 | [diff] [blame] | 72 | # override if need be by the submodules' own hooks |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 73 | for hook_name in "${COREDIR?}/${repo?}/.git-hooks"/* ; do |
| Mike Kaganski | 0e6e10c | 2021-03-04 11:40:05 +0300 | [diff] [blame] | 74 | if [ ! -e "${hook_name}" ] ; then |
| 75 | continue | ||||
| 76 | fi | ||||
| Ilmari Lauhakangas | 55c5b27 | 2017-04-15 18:35:17 +0300 | [diff] [blame] | 77 | hook=".git/modules/${repo?}/hooks/${hook_name##*/}" |
| 78 | if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 79 | rm -f "${hook?}" |
| 80 | ln -sf "${hook_name}" "${hook?}" | ||||
| 81 | fi | ||||
| 82 | done | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 83 | fi |
| Norbert Thiebaud | 0cac67b | 2012-12-21 04:33:20 -0600 | [diff] [blame] | 84 | |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 85 | } |
| 86 | |||||
| 87 | refresh_all_hooks() | ||||
| 88 | { | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 89 | local repo |
| 90 | local hook_name | ||||
| 91 | local hook | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 92 | |
| Stephan Bergmann | a3e51e2 | 2015-01-14 15:42:00 +0100 | [diff] [blame] | 93 | pushd "${COREDIR?}" > /dev/null |
| Ilmari Lauhakangas | e5b1c53 | 2017-04-27 12:46:47 +0300 | [diff] [blame] | 94 | for hook_name in "${COREDIR?}/.git-hooks"/* ; do |
| Ilmari Lauhakangas | 55c5b27 | 2017-04-15 18:35:17 +0300 | [diff] [blame] | 95 | hook=".git/hooks/${hook_name##*/}" |
| 96 | if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 97 | rm -f "${hook?}" |
| Ilmari Lauhakangas | 55c5b27 | 2017-04-15 18:35:17 +0300 | [diff] [blame] | 98 | ln -sf "${hook_name}" "${hook?}" |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 99 | fi |
| 100 | done | ||||
| 101 | |||||
| 102 | for repo in ${SUBMODULES_ALL?} ; do | ||||
| Ilmari Lauhakangas | e5b1c53 | 2017-04-27 12:46:47 +0300 | [diff] [blame] | 103 | refresh_submodule_hooks "$repo" |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 104 | done |
| 105 | popd > /dev/null | ||||
| 106 | |||||
| 107 | } | ||||
| 108 | |||||
| 109 | set_push_url() | ||||
| 110 | { | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 111 | local repo |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 112 | |
| 113 | repo="$1" | ||||
| 114 | if [ -n "$repo" ] ; then | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 115 | pushd "${COREDIR?}/${repo?}" > /dev/null |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 116 | else |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 117 | pushd "${COREDIR?}" > /dev/null |
| 118 | repo="core" | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 119 | fi |
| 120 | echo "setting up push url for ${repo?}" | ||||
| 121 | if [ "${repo?}" = "helpcontent2" ] ; then | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 122 | git config remote.origin.pushurl "ssh://${PUSH_USER}logerrit/help" |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 123 | else |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 124 | git config remote.origin.pushurl "ssh://${PUSH_USER}logerrit/${repo?}" |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 125 | fi |
| 126 | popd > /dev/null | ||||
| 127 | } | ||||
| 128 | |||||
| 129 | set_push_urls() | ||||
| 130 | { | ||||
| 131 | PUSH_USER="$1" | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 132 | set_push_url |
| 133 | for repo in ${SUBMODULES_ACTIVE?} ; do | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 134 | set_push_url "${repo?}" |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 135 | done |
| 136 | } | ||||
| 137 | |||||
| 138 | get_active_submodules() | ||||
| 139 | { | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 140 | SUBMODULES_ACTIVE="" |
| 141 | local repo | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 142 | |
| 143 | for repo in ${SUBMODULES_ALL?} ; do | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 144 | if [ -d "${repo?}"/.git ] || [ -f "${repo?}"/.git ] ; then |
| 145 | SUBMODULES_ACTIVE="${repo?} ${SUBMODULES_ACTIVE?}" | ||||
| 146 | fi | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 147 | done |
| 148 | } | ||||
| 149 | |||||
| 150 | get_configured_submodules() | ||||
| 151 | { | ||||
| 152 | SUBMODULES_CONFIGURED="" | ||||
| Luboš Luňák | d449869 | 2012-12-11 16:39:02 +0100 | [diff] [blame] | 153 | if [ -f config_host.mk ] ; then |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 154 | SUBMODULES_CONFIGURED=$(< config_host.mk grep -a GIT_NEEDED_SUBMODULES | sed -e "s/.*=//") |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 155 | else |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 156 | # if we need the configured submodule before the configuration is done. we assumed you want them all |
| 157 | SUBMODULES_CONFIGURED=${SUBMODULES_ALL?} | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 158 | fi |
| 159 | } | ||||
| 160 | |||||
| Miklos Vajna | 803137f | 2013-02-09 19:09:32 +0100 | [diff] [blame] | 161 | get_git_reference() |
| 162 | { | ||||
| 163 | REFERENCED_GIT="" | ||||
| 164 | if [ -f config_host.mk ]; then | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 165 | REFERENCED_GIT=$(< config_host.mk grep -a GIT_REFERENCE_SRC | sed -e "s/.*=//") |
| Miklos Vajna | 803137f | 2013-02-09 19:09:32 +0100 | [diff] [blame] | 166 | fi |
| Lionel Elie Mamane | aa1a988 | 2013-06-21 13:31:37 +0200 | [diff] [blame] | 167 | LINKED_GIT="" |
| 168 | if [ -f config_host.mk ]; then | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 169 | LINKED_GIT=$(< config_host.mk grep -a GIT_LINK_SRC | sed -e "s/.*=//") |
| Lionel Elie Mamane | aa1a988 | 2013-06-21 13:31:37 +0200 | [diff] [blame] | 170 | fi |
| Miklos Vajna | 803137f | 2013-02-09 19:09:32 +0100 | [diff] [blame] | 171 | } |
| 172 | |||||
| Norbert Thiebaud | a31714f | 2012-10-02 12:59:44 -0500 | [diff] [blame] | 173 | do_shortcut_update() |
| 174 | { | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 175 | local module |
| 176 | local repo | ||||
| Norbert Thiebaud | a31714f | 2012-10-02 12:59:44 -0500 | [diff] [blame] | 177 | |
| 178 | for module in $SUBMODULES_CONFIGURED ; do | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 179 | if [ ! -d "${module?}"/.git ] ; then |
| 180 | case "${module?}" in | ||||
| 181 | helpcontent2) | ||||
| 182 | if [ -d clone/help/.git ] ; then | ||||
| 183 | repo="clone/help/.git" | ||||
| 184 | fi | ||||
| 185 | ;; | ||||
| 186 | *) | ||||
| 187 | if [ -d clone/"${module?}"/.git ] ; then | ||||
| 188 | repo="clone/${module?}/.git" | ||||
| 189 | fi | ||||
| 190 | ;; | ||||
| 191 | esac | ||||
| 192 | if [ -n "$repo" ] ; then | ||||
| 193 | cp -r "${repo?}" "${module?}/." | ||||
| 194 | fi | ||||
| 195 | fi | ||||
| Norbert Thiebaud | a31714f | 2012-10-02 12:59:44 -0500 | [diff] [blame] | 196 | done |
| 197 | } | ||||
| 198 | |||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 199 | do_git_cmd() |
| 200 | { | ||||
| Ilmari Lauhakangas | e5b1c53 | 2017-04-27 12:46:47 +0300 | [diff] [blame] | 201 | echo "cmd:$*" |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 202 | git "$@" |
| 203 | git submodule foreach git "$@" $KEEP_GOING | ||||
| 204 | } | ||||
| 205 | |||||
| 206 | do_checkout() | ||||
| 207 | { | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 208 | local cmd |
| 209 | local create_branch="0" | ||||
| 210 | local branch | ||||
| 211 | local module | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 212 | |
| 213 | git checkout "$@" || return $? | ||||
| 214 | for cmd in "$@" ; do | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 215 | if [ "$cmd" = "-f" ]; then |
| Thorsten Behrens | 5fce97a | 2018-07-02 18:11:47 +0200 | [diff] [blame] | 216 | continue |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 217 | elif [ "$cmd" = "-b" ] ; then |
| 218 | create_branch=1 | ||||
| 219 | elif [ "$create_branch" = "1" ] ; then | ||||
| 220 | branch="$cmd" | ||||
| 221 | create_branch=0 | ||||
| 222 | fi | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 223 | done |
| 224 | if [ -f .gitmodules ] ; then | ||||
| Kevin Suo | 508ccbd | 2021-06-26 17:42:52 +0800 | [diff] [blame] | 225 | git submodule update --progress |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 226 | if [ -n "$branch" ] ; then |
| 227 | git submodule foreach git checkout -b "${branch}" HEAD || return $? | ||||
| 228 | fi | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 229 | else |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 230 | # now that is the nasty case we moved prior to submodules |
| 231 | # delete the submodules left over if any | ||||
| 232 | for module in $SUBMODULES_ALL ; do | ||||
| 233 | echo "clean-up submodule $module" | ||||
| 234 | rm -fr "${module}" | ||||
| 235 | done | ||||
| 236 | # make sure we have the needed repo in clone | ||||
| 237 | ./g clone && ./g -f checkout "$@" || return $? | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 238 | fi |
| 239 | return $? | ||||
| 240 | } | ||||
| 241 | |||||
| 242 | do_reset() | ||||
| 243 | { | ||||
| 244 | git reset "$@" || return $? | ||||
| 245 | if [ -f .gitmodules ] ; then | ||||
| Kevin Suo | 508ccbd | 2021-06-26 17:42:52 +0800 | [diff] [blame] | 246 | git submodule update --progress || return $? |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 247 | else |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 248 | # now that is the nasty case we moved prior to submodules |
| 249 | # delete the submodules left over if any | ||||
| 250 | for module in $SUBMODULES_ALL ; do | ||||
| 251 | echo "clean-up submodule $module" | ||||
| 252 | rm -fr "${module}" | ||||
| 253 | done | ||||
| 254 | # make sure we have the needed repo in clone | ||||
| 255 | ./g clone && ./g -f reset "$@" | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 256 | fi |
| 257 | return $?; | ||||
| 258 | } | ||||
| 259 | |||||
| 260 | do_init_modules() | ||||
| 261 | { | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 262 | local module |
| 263 | local configured | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 264 | |
| Norbert Thiebaud | a31714f | 2012-10-02 12:59:44 -0500 | [diff] [blame] | 265 | do_shortcut_update |
| 266 | |||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 267 | for module in $SUBMODULES_CONFIGURED ; do |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 268 | if [ -n "$LINKED_GIT" ] ; then |
| 269 | if ! [ -d ".git/modules/${module}" ]; then | ||||
| 270 | ./bin/git-new-module-workdir "${LINKED_GIT}/${module}" "${module}" | ||||
| 271 | fi | ||||
| 272 | fi | ||||
| 273 | configured=$(git config --local --get submodule."${module}".url) | ||||
| 274 | if [ -z "$configured" ] ; then | ||||
| 275 | git submodule init "$module" || return $? | ||||
| 276 | fi | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 277 | done |
| Miklos Vajna | 73b50b7 | 2013-02-26 16:17:51 +0100 | [diff] [blame] | 278 | for module in $SUBMODULES_CONFIGURED ; do |
| 279 | if [ -n "$REFERENCED_GIT" ] ; then | ||||
| Kevin Suo | 508ccbd | 2021-06-26 17:42:52 +0800 | [diff] [blame] | 280 | git submodule update --reference "$REFERENCED_GIT/.git/modules/$module" --progress "$module" || return $? |
| Miklos Vajna | 73b50b7 | 2013-02-26 16:17:51 +0100 | [diff] [blame] | 281 | else |
| Kevin Suo | 508ccbd | 2021-06-26 17:42:52 +0800 | [diff] [blame] | 282 | git submodule update --progress "$module" || return $? |
| Miklos Vajna | 73b50b7 | 2013-02-26 16:17:51 +0100 | [diff] [blame] | 283 | fi |
| 284 | done | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 285 | return 0 |
| 286 | } | ||||
| 287 | |||||
| 288 | |||||
| 289 | # no params, no action | ||||
| 290 | if [ "$#" -eq "0" ] ; then | ||||
| 291 | usage | ||||
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 292 | fi |
| 293 | |||||
| Ilmari Lauhakangas | 55c5b27 | 2017-04-15 18:35:17 +0300 | [diff] [blame] | 294 | if [ ! "$(type -p git)" ]; then |
| Miklos Vajna | 889934e | 2011-09-05 20:45:43 +0200 | [diff] [blame] | 295 | echo "Cannot find the git binary! Is git installed and is in PATH?" |
| 296 | exit 1 | ||||
| 297 | fi | ||||
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 298 | |
| Norbert Thiebaud | 71e5200 | 2011-08-27 23:41:18 -0500 | [diff] [blame] | 299 | |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 300 | get_active_submodules |
| 301 | get_configured_submodules | ||||
| Miklos Vajna | 803137f | 2013-02-09 19:09:32 +0100 | [diff] [blame] | 302 | get_git_reference |
| Bjoern Michaelsen | 79e9a64 | 2012-07-10 12:57:01 +0200 | [diff] [blame] | 303 | |
| Jan Holesovsky | 40dd1bc | 2010-11-25 00:13:14 +0100 | [diff] [blame] | 304 | |
| Norbert Thiebaud | 71e5200 | 2011-08-27 23:41:18 -0500 | [diff] [blame] | 305 | |
| Norbert Thiebaud | 71e5200 | 2011-08-27 23:41:18 -0500 | [diff] [blame] | 306 | |
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 307 | # extra params for some commands, like log |
| 308 | EXTRA= | ||||
| 309 | COMMAND="$1" | ||||
| 310 | PAGER= | ||||
| 311 | RELATIVIZE=1 | ||||
| 312 | PUSH_ALL= | ||||
| Michael Meeks | 4d2803d | 2011-10-25 13:20:58 +0100 | [diff] [blame] | 313 | PUSH_USER= |
| 314 | PUSH_NOTES= | ||||
| 315 | LAST_WORKING= | ||||
| 316 | SET_LAST_WORKING= | ||||
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 317 | ALLOW_EMPTY= |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 318 | KEEP_GOING= |
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 319 | REPORT_REPOS=1 |
| Stephan Bergmann | 79e65ee | 2011-11-29 16:38:46 +0100 | [diff] [blame] | 320 | REPORT_COMMANDS=0 |
| Norbert Thiebaud | 67dd44fb | 2011-05-01 03:26:45 -0500 | [diff] [blame] | 321 | REPORT_COMPACT=0 |
| Norbert Thiebaud | 71e5200 | 2011-08-27 23:41:18 -0500 | [diff] [blame] | 322 | DO_HOOK_REFRESH=false |
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 323 | |
| 324 | while [ "${COMMAND:0:1}" = "-" ] ; do | ||||
| 325 | case "$COMMAND" in | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 326 | -f )KEEP_GOING="||:" |
| Michael Stahl | 175f17b | 2011-11-03 21:56:21 +0100 | [diff] [blame] | 327 | ;; |
| 328 | -z) | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 329 | refresh_all_hooks |
| 330 | exit 0; | ||||
| Michael Stahl | 175f17b | 2011-11-03 21:56:21 +0100 | [diff] [blame] | 331 | ;; |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 332 | --set-push-urls) |
| 333 | shift | ||||
| 334 | PUSH_USER="$1" | ||||
| 335 | if [ -n "${PUSH_USER}" ] ; then | ||||
| 336 | PUSH_USER="${PUSH_USER}@" | ||||
| 337 | fi | ||||
| 338 | set_push_urls "$PUSH_USER" | ||||
| 339 | exit 0; | ||||
| 340 | ;; | ||||
| 341 | -*) | ||||
| 342 | echo "option: $COMMAND not supported" 1>&2 | ||||
| 343 | exit 1 | ||||
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 344 | esac |
| 345 | shift | ||||
| 346 | COMMAND="$1" | ||||
| 347 | done | ||||
| 348 | |||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 349 | shift |
| 350 | |||||
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 351 | case "$COMMAND" in |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 352 | branch) |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 353 | do_git_cmd "${COMMAND}" "$@" |
| 354 | ;; | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 355 | checkout) |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 356 | do_checkout "$@" |
| 357 | ;; | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 358 | clone) |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 359 | do_init_modules && refresh_all_hooks |
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 360 | ;; |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 361 | fetch) |
| Kevin Suo | 508ccbd | 2021-06-26 17:42:52 +0800 | [diff] [blame] | 362 | (git fetch "$@" && git submodule foreach git fetch "$@" ) && git submodule update --progress |
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 363 | |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 364 | ;; |
| Arnaud VERSINI | 5448ad5 | 2022-01-02 17:33:27 +0100 | [diff] [blame] | 365 | gc) |
| 366 | (git gc "$@" && git submodule foreach git gc "$@" ) | ||||
| 367 | ;; | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 368 | grep) |
| 369 | KEEP_GOING="||:" | ||||
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 370 | do_git_cmd "${COMMAND}" "$@" |
| 371 | ;; | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 372 | pull) |
| Kevin Suo | 508ccbd | 2021-06-26 17:42:52 +0800 | [diff] [blame] | 373 | git pull "$@" && git submodule update --progress && refresh_all_hooks |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 374 | ;; |
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 375 | push) |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 376 | git submodule foreach git push "$@" |
| 377 | if [ "$?" = "0" ] ; then | ||||
| 378 | git push "$@" | ||||
| 379 | fi | ||||
| 380 | ;; | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 381 | reset) |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 382 | do_reset |
| 383 | ;; | ||||
| Norbert Thiebaud | a31714f | 2012-10-02 12:59:44 -0500 | [diff] [blame] | 384 | tag) |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 385 | do_git_cmd "${COMMAND}" "$@" |
| 386 | ;; | ||||
| 387 | "") | ||||
| 388 | ;; | ||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 389 | *) |
| Thorsten Behrens | 4c475bc | 2018-07-02 18:11:22 +0200 | [diff] [blame] | 390 | echo "./g does not support command: $COMMAND" 1>&2 |
| 391 | exit 1; | ||||
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 392 | ;; |
| 393 | esac | ||||
| 394 | |||||
| Norbert Thiebaud | 9152c42 | 2012-10-01 23:48:10 -0500 | [diff] [blame] | 395 | exit $? |
| Norbert Thiebaud | 71e5200 | 2011-08-27 23:41:18 -0500 | [diff] [blame] | 396 | |
| Jan Holesovsky | a694de1 | 2010-11-16 15:00:48 +0100 | [diff] [blame] | 397 | # vi:set shiftwidth=4 expandtab: |