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.

checkoutAt.sh 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # Script to checkout the client at a given point of time.
  3. # Usage:
  4. #
  5. # checkoutAt.sh <meta|client|parser|util|plugins> <sha1>
  6. #
  7. # This will checkout <sha1> in the given repo, and then checkout the last
  8. # commit in all other repos that happened before the time of requested commit.
  9. REPO="${1}"
  10. SHA1="${2}"
  11. VALID_REPOS=(meta client parser util plugins)
  12. containsElement () {
  13. local e
  14. for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
  15. return 1
  16. }
  17. containsElement "${REPO}" "${VALID_REPOS[@]}"
  18. RES=${?}
  19. if [ "${SHA1}" = "" -o ${RES} -ne 0 ]; then
  20. echo "Usage:"
  21. echo "${0} <meta|client|parser|util|plugins> <sha1>"
  22. echo ""
  23. echo "This will checkout <sha1> in the given repo, and then checkout the last commit in all other repos that happened before the time of requested commit."
  24. exit 1;
  25. fi;
  26. CHECKOUTDIR="${PWD}"
  27. if [ ! -e "${CHECKOUTDIR}/settings.gradle" -o "$(grep "rootProject.name = 'dmdirc'" settings.gradle 2>&1)" = "" ]; then
  28. echo "'${PWD}' does not look like a DMDirc/meta checkout."
  29. exit 1;
  30. fi;
  31. getRepoDir() {
  32. if [ "${1}" = "meta" ]; then
  33. echo "${CHECKOUTDIR}/"
  34. else
  35. echo "${CHECKOUTDIR}/${1}"
  36. fi;
  37. }
  38. isCommit() {
  39. if [ "$(git cat-file -t "${1}" 2>&1)" = "commit" ]; then
  40. echo "0"
  41. else
  42. echo "1"
  43. fi;
  44. }
  45. cd $(getRepoDir "${REPO}")
  46. if [ $(isCommit ${SHA1}) -eq 1 ]; then
  47. echo "Invalid commit in ${REPO}: ${SHA1}"
  48. exit 1;
  49. fi;
  50. # Get the requested commit.
  51. echo -ne "\e[32m"
  52. echo "In ${REPO}: "
  53. echo -ne "\e[93m"; git show ${SHA1} -s --format=" Checking out: %H - %s"
  54. echo -ne "\e[93m"; git show ${SHA1} -s --format=" Author: %an / Committer: %cn / Date: %cD"
  55. echo -e "\e[39m"
  56. echo -ne "\e[90m"
  57. git reset --hard
  58. git checkout -f ${SHA1}
  59. echo -e "\e[39m"
  60. THISTIME=$(git show ${SHA1} --pretty=format:%ct)
  61. # Now get all the others...
  62. for R in "${VALID_REPOS[@]}"
  63. do
  64. if [ "${R}" != "${REPO}" ]; then
  65. cd $(getRepoDir "${R}")
  66. RSHA1=$(git rev-list -1 --before="${THISTIME}" --all)
  67. echo -ne "\e[32m"
  68. echo "In ${R}: "
  69. echo -ne "\e[93m"; git show ${RSHA1} -s --format=" Checking out: %H - %s"
  70. echo -ne "\e[93m"; git show ${RSHA1} -s --format=" Author: %an / Committer: %cn / Date: %cD"
  71. echo -e "\e[39m"
  72. echo -ne "\e[90m"
  73. git reset --hard
  74. git checkout -f ${RSHA1}
  75. echo -e "\e[39m"
  76. fi;
  77. done;
  78. cd "${CHECKOUTDIR}"