submodules-update-branch (1335B)
1 #!/bin/sh -e 2 prog=$(basename "$0") 3 fatal() { 4 printf >&2 '%s: fatal: %s\n' "$prog" "$*" 5 exit 1 6 } 7 cd "$(dirname "$0")/.." 8 prefix=mrrl- 9 branch=$(git branch --show-current --format '%(refname:short)') 10 branch=trunk 11 if test -z "$branch"; then 12 fatal "could not determine branch name" 13 fi 14 git submodule status --cached --recursive | while read -r line; do 15 line=${line# } 16 commit=${line%% *} 17 line=${line#* } 18 submodule=${line%% (*} 19 if test -z "$submodule"; then 20 fatal "could not determine submodule name" 21 fi 22 case "$commit" in 23 ("") 24 fatal "could not determine commit id" 25 ;; 26 (-*) 27 # not checked out, skip 28 continue 29 ;; 30 (+*) 31 fatal "submodule '$submodule' has different than recorded commit id" 32 ;; 33 ([a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]) 34 ;; 35 (*) 36 fatal "invalid commit id" 37 ;; 38 esac 39 case "$line" in 40 (*' (heads/mrrl-trunk)') continue;; 41 esac 42 ( cd $submodule && if test x"$(git branch --show-current)" = x"$prefix$branch"; then git merge --ff-only "$commit"; else git branch --force "$prefix$branch" "$commit"; fi ) 43 done