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