OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
4.2 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-update-tree
  6. # Copyright (C) 2007 - 2020 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. #Description: Updates the entire working tree
  16. [ -n "$SDEROOT" ] ||
  17. export SDEROOT="$(cd "${0%/*}/.."; pwd -P)"
  18. . $SDEROOT/lib/libsde.in
  19. update_usage() {
  20. local progname="$(echo "${0##*/}" | sed -e 's,-, ,g')"
  21. cat <<-EOT
  22. Usage: $progname
  23. EOT
  24. }
  25. shortopts=
  26. longopts='help'
  27. options="$(getopt -o "$shortopts" -l "$longopts" -- "$@")"
  28. if [ $? -ne 0 ]; then
  29. update_usage
  30. exit -1
  31. fi
  32. # load new arguments list
  33. eval set -- "$options"
  34. while [ $# -gt 0 ]; do
  35. case "$1" in
  36. --help)
  37. update_usage
  38. exit 0 ;;
  39. --) shift; break ;;
  40. *) echo_abort 1 "Unknown argument '$1', aborting."
  41. esac
  42. shift
  43. done
  44. # jump to the working tree's root
  45. #
  46. cd "$SDEROOT"
  47. tree="${SDEROOT##*/}"
  48. update_git()
  49. {
  50. local prefix="$1"
  51. local branch="$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')"
  52. local remote="$(git config branch.$branch.remote)"
  53. local remote_list="$(git remote)"
  54. local remote_branch= remote_branch_list=
  55. local changes=false
  56. if [ -z "$remote_list" ]; then
  57. echo_warning "$prefix: no remotes set"
  58. return 0
  59. elif [ -n "$remote" -a -z "$( echo "$remote_list" | grep "^$remote\$" )" ]; then
  60. echo_abort 1 "$prefix: what?! '$remote' is gone!"
  61. elif [ -z "$remote" ]; then
  62. # uhm, get a good remote
  63. if [ "$( echo "$remote_list" | grep "^origin$" )" ]; then
  64. remote=origin
  65. else
  66. remote="$(echo "$remote_list" | head -n 1)"
  67. fi
  68. # and it's list of branches
  69. remote_branch_list="$(git branch -r | sed -n -e "s|^ $remote/||p" | grep -v '^HEAD$')"
  70. if [ -z "$remote_branch_list" ]; then
  71. echo_abort 1 "$prefix: no remote set, and couldn't guess one".
  72. elif [ "$( echo "$remote_branch_list" | grep "^$branch$" )" ]; then
  73. remote_branch="$branch"
  74. elif [ "$( echo "$remote_branch_list" | grep "^master$" )" ]; then
  75. remote_branch=master
  76. else
  77. remote_branch="$(echo "$remote_branch_list" | head -n 1)"
  78. fi
  79. echo_warning "$prefix: no remote set, assuming $remote/$remote_branch."
  80. git config branch.$branch.remote "$remote"
  81. git config branch.$branch.merge "refs/heads/$remote_branch"
  82. else
  83. echo_info "$prefix:"
  84. fi
  85. if git reset -q; then
  86. git remote prune "$remote"
  87. if [ -n "$(git ls-files -md)" ]; then
  88. changes=true
  89. git stash > /dev/null
  90. fi
  91. git pull --rebase
  92. if $changes; then
  93. git stash pop > /dev/null
  94. git status --porcelain
  95. fi
  96. fi
  97. if [ -x "./update.sh" ]; then
  98. ./update.sh "$prefix"
  99. fi
  100. }
  101. update_svn_nested()
  102. {
  103. trap ':' INT
  104. # find svn:externals, and filter out sub-externals
  105. svn st | grep '^X' | cut -c8- | tee /tmp/$$.nested |
  106. while read f; do
  107. sed -i -e "s|^$f/.*||;" -e '/^$/d;' /tmp/$$.nested
  108. done
  109. cat /tmp/$$.nested
  110. rm -f /tmp/$$.nested
  111. trap '-' INT
  112. }
  113. update_svn()
  114. {
  115. local prefix="$1" x=
  116. echo_info "$prefix:"
  117. svn up --ignore-externals
  118. if [ -x "./update.sh" ]; then
  119. ./update.sh "$prefix"
  120. fi
  121. # nested svn
  122. for x in $( update_svn_nested ); do
  123. ( cd "$x"; update_svn "$prefix/$x" )
  124. done
  125. }
  126. # hunt for the roots of the sub-working trees
  127. #
  128. baseurl="$( git config remote.origin.url | sed -e 's|/[^/]*$||' )"
  129. [ -n "$baseurl" ] || baseurl="https://git.opensde.net/opensde"
  130. set -- . \
  131. package:git+$baseurl/package-nopast.git \
  132. $( ls -1d package/* target/* 2> /dev/null )
  133. for x; do
  134. if [ "$x" != "${x%%:*}" ]; then
  135. url="${x#*:}"
  136. x="${x%%:*}"
  137. else
  138. url=
  139. fi
  140. if [ -e "$x" -a ! -d "$x/" ]; then
  141. continue
  142. elif [ "$x" = "." ]; then
  143. prefix="$tree"
  144. else
  145. prefix="$tree/$x"
  146. fi
  147. if [ ! -d "$x" ]; then
  148. case "$url" in
  149. "")
  150. echo_warning "$prefix: missing"
  151. ;;
  152. git+*)
  153. echo_info "$prefix"
  154. git clone "${url#git+}" "$x"
  155. ;;
  156. *)
  157. echo_warning "$prefix: invalid url ($url)"
  158. ;;
  159. esac
  160. elif [ -d "$x/.git" ]; then
  161. ( cd "$x" && update_git "$prefix" )
  162. elif [ -d "$x/.svn" ]; then
  163. ( cd "$x" && update_svn "$prefix" )
  164. fi
  165. done