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.

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