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.

145 lines
3.4 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 prefix="$1"
  55. local branch=$( git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||' )
  56. local remote=$( git config branch.$branch.remote )
  57. local remote_list=$( git remote )
  58. local remote_branch= remote_branch_list=
  59. if [ -z "$remote_list" ]; then
  60. echo "$prefix: no remotes set"
  61. return 0
  62. elif [ -n "$remote" -a -z "$( echo "$remote_list" | grep "^$remote\$" )" ]; then
  63. echo "$prefix: what?! '$remote' is gone!"
  64. return 1
  65. elif [ -z "$remote" ]; then
  66. # uhm, get a good remote
  67. if [ "$( echo "$remote_list" | grep "^origin$" )" ]; then
  68. remote=origin
  69. else
  70. remote="$( echo "$remote_list" | head -n 1 )"
  71. fi
  72. # and it's list of branches
  73. remote_branch_list=$( git branch -r | sed -n -e "s|^ $remote/||p" | grep -v '^HEAD$' )
  74. if [ -z "$remote_branch_list" ]; then
  75. echo "$prefix: no remote set, and couldn't guess one".
  76. return 1
  77. elif [ "$( echo "$remote_branch_list" | grep "^$branch$" )" ]; then
  78. remote_branch="$branch"
  79. elif [ "$( echo "$remote_branch_list" | grep "^master$" )" ]; then
  80. remote_branch=master
  81. else
  82. remote_branch="$( echo "$remote_branch_list" | head -n 1 )"
  83. fi
  84. echo "$prefix: no remote set, assuming $remote/$remote_branch."
  85. git config branch.$branch.remote "$remote"
  86. git config branch.$branch.merge "refs/heads/$remote_branch"
  87. else
  88. echo "$prefix:"
  89. fi
  90. ( git reset && git pull --rebase ) 2>&1 | indent_output
  91. }
  92. update_svn()
  93. {
  94. local prefix="$1" x=
  95. echo "$prefix:"
  96. svn up --ignore-externals 2>&1 | indent_output
  97. # nested svn
  98. for x in $( svn st | grep '^X' | cut -c8- ); do
  99. ( cd "$x"; update_svn "$prefix/$x" )
  100. done
  101. }
  102. # hunt for the roots of the sub-working trees
  103. #
  104. for x in . package $( ls -1d package/* target/* 2> /dev/null ); do
  105. if [ ! -d "$x" ]; then
  106. case "$x" in
  107. package)
  108. echo "$tree/$x:"
  109. ( git clone --quiet \
  110. "$GITSERVER/opensde/$x-nopast.git" "$x" 2>&1 &&
  111. echo "$x: cloned successfully"
  112. ) | indent_output
  113. ;;
  114. *)
  115. echo "$tree/$x: missing" >&2
  116. ;;
  117. esac
  118. elif [ -d "$x/.git" ]; then
  119. ( cd "$x"; update_git "$tree/$x" )
  120. elif [ -d "$x/.svn" ]; then
  121. ( cd "$x"; update_svn "$tree/$x" )
  122. fi
  123. done