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.

135 lines
3.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 - 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. GITSERVER="git://git.opensde.net"
  35. while [ $# -gt 0 ]; do
  36. case "$1" in
  37. --help)
  38. update_usage
  39. exit 0 ;;
  40. --) shift; break ;;
  41. *) echo_abort 1 "Unknown argument '$1', aborting."
  42. esac
  43. shift
  44. done
  45. indent_output() {
  46. sed -e '/^$/d;' -e 's/^/ /'
  47. }
  48. # jump to the working tree's root
  49. #
  50. cd "$SDEROOT"
  51. tree="${SDEROOT##*/}"
  52. update_git()
  53. {
  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 "no remotes set"
  60. return 0
  61. elif [ -n "$remote" -a -z "$( echo "$remote_list" | grep "^$remote\$" )" ]; then
  62. echo "$remote: 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 "no remote set, and couldn't guess".
  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 "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. fi
  87. git reset && git pull --rebase
  88. }
  89. # hunt for the roots of the sub-working trees
  90. #
  91. for x in . package $( ls -1d package/* target/* 2> /dev/null ); do
  92. if [ ! -d "$x" ]; then
  93. case "$x" in
  94. package)
  95. echo "$tree/$x:"
  96. ( git clone --quiet \
  97. "$GITSERVER/opensde/$x-nopast.git" "$x" 2>&1 &&
  98. echo "$x: cloned successfully"
  99. ) | indent_output
  100. ;;
  101. *)
  102. echo "$tree/$x: missing" >&2
  103. ;;
  104. esac
  105. elif [ -d "$x/.git" ]; then
  106. cd "$x";
  107. echo "$tree/$x:"
  108. update_git 2>&1 | indent_output
  109. cd - > /dev/null
  110. elif [ -d "$x/.svn" ]; then
  111. cd "$x";
  112. echo "$tree/$x:"
  113. svn up 2>&1 | indent_output
  114. cd - > /dev/null
  115. fi
  116. done