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.

159 lines
3.7 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 - 2008 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=${0##*/}
  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. indent_output() {
  45. sed -e '/^$/d;' -e 's/^/ /'
  46. }
  47. # jump to the working tree's root
  48. #
  49. cd "$SDEROOT"
  50. tree="${SDEROOT##*/}"
  51. update_git()
  52. {
  53. local prefix="$1"
  54. local branch=$( git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||' )
  55. local remote=$( git config branch.$branch.remote )
  56. local remote_list=$( git remote )
  57. local remote_branch= remote_branch_list=
  58. if [ -z "$remote_list" ]; then
  59. echo "$prefix: no remotes set"
  60. return 0
  61. elif [ -n "$remote" -a -z "$( echo "$remote_list" | grep "^$remote\$" )" ]; then
  62. echo "$prefix: what?! '$remote' is gone!"
  63. return 1
  64. elif [ -z "$remote" ]; then
  65. # uhm, get a good remote
  66. if [ "$( echo "$remote_list" | grep "^origin$" )" ]; then
  67. remote=origin
  68. else
  69. remote="$( echo "$remote_list" | head -n 1 )"
  70. fi
  71. # and it's list of branches
  72. remote_branch_list=$( git branch -r | sed -n -e "s|^ $remote/||p" | grep -v '^HEAD$' )
  73. if [ -z "$remote_branch_list" ]; then
  74. echo "$prefix: no remote set, and couldn't guess one".
  75. return 1
  76. elif [ "$( echo "$remote_branch_list" | grep "^$branch$" )" ]; then
  77. remote_branch="$branch"
  78. elif [ "$( echo "$remote_branch_list" | grep "^master$" )" ]; then
  79. remote_branch=master
  80. else
  81. remote_branch="$( echo "$remote_branch_list" | head -n 1 )"
  82. fi
  83. echo "$prefix: no remote set, assuming $remote/$remote_branch."
  84. git config branch.$branch.remote "$remote"
  85. git config branch.$branch.merge "refs/heads/$remote_branch"
  86. else
  87. echo "$prefix:"
  88. fi
  89. ( git reset && git pull --rebase ) 2>&1 | indent_output
  90. }
  91. update_svn_nested()
  92. {
  93. trap ':' INT
  94. # find svn:externals, and filter out sub-externals
  95. svn st | grep '^X' | cut -c8- | tee /tmp/$$.nested |
  96. while read f; do
  97. sed -i -e "s|^$f/.*||;" -e '/^$/d;' /tmp/$$.nested
  98. done
  99. cat /tmp/$$.nested
  100. rm -f /tmp/$$.nested
  101. trap '-' INT
  102. }
  103. update_svn()
  104. {
  105. local prefix="$1" x=
  106. echo "$prefix:"
  107. svn up --ignore-externals 2>&1 | indent_output
  108. # nested svn
  109. for x in $( update_svn_nested ); do
  110. ( cd "$x"; update_svn "$prefix/$x" )
  111. done
  112. }
  113. # hunt for the roots of the sub-working trees
  114. #
  115. baseurl=$( git config remote.origin.url | sed -e 's|/[^/]*$||' )
  116. [ -n "$baseurl" ] || baseurl="git://git.opensde.net/opensde"
  117. echo ".: $baseurl"
  118. for x in . package $( ls -1d package/* target/* 2> /dev/null ); do
  119. if [ ! -d "$x" ]; then
  120. case "$x" in
  121. package)
  122. echo "$tree/$x:"
  123. ( git clone "$baseurl/$x-nopast.git" "$x" 2>&1 &&
  124. echo "$x: cloned successfully"
  125. ) | indent_output
  126. ;;
  127. *)
  128. echo "$tree/$x: missing" >&2
  129. ;;
  130. esac
  131. elif [ -d "$x/.git" ]; then
  132. ( cd "$x"; update_git "$tree/$x" )
  133. elif [ -d "$x/.svn" ]; then
  134. ( cd "$x"; update_svn "$tree/$x" )
  135. fi
  136. done