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.

161 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 - 2009 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. if git reset; then
  85. git remote prune "$remote"
  86. git pull --rebase
  87. fi
  88. }
  89. update_svn_nested()
  90. {
  91. trap ':' INT
  92. # find svn:externals, and filter out sub-externals
  93. svn st | grep '^X' | cut -c8- | tee /tmp/$$.nested |
  94. while read f; do
  95. sed -i -e "s|^$f/.*||;" -e '/^$/d;' /tmp/$$.nested
  96. done
  97. cat /tmp/$$.nested
  98. rm -f /tmp/$$.nested
  99. trap '-' INT
  100. }
  101. update_svn()
  102. {
  103. local prefix="$1" x=
  104. echo_info "$prefix:"
  105. svn up --ignore-externals
  106. # nested svn
  107. for x in $( update_svn_nested ); do
  108. ( cd "$x"; update_svn "$prefix/$x" )
  109. done
  110. }
  111. # hunt for the roots of the sub-working trees
  112. #
  113. baseurl=$( git config remote.origin.url | sed -e 's|/[^/]*$||' )
  114. [ -n "$baseurl" ] || baseurl="git://git.opensde.net/opensde"
  115. for x in . package $( ls -1d package/* target/* 2> /dev/null ); do
  116. if [ -e "$x" -a ! -d "$x/" ]; then
  117. continue
  118. elif [ "$x" = "." ]; then
  119. prefix="$tree"
  120. else
  121. prefix="$tree/$x"
  122. fi
  123. if [ ! -d "$x" ]; then
  124. case "$x" in
  125. package)
  126. echo_info "$prefix:"
  127. git clone "$baseurl/$x-nopast.git" "$x"
  128. ;;
  129. *)
  130. echo_warning "$prefix: missing"
  131. ;;
  132. esac
  133. elif [ -d "$x/.git" ]; then
  134. ( cd "$x" && update_git "$prefix" )
  135. elif [ -d "$x/.svn" ]; then
  136. ( cd "$x" && update_svn "$prefix" )
  137. fi
  138. done