import-upstream-tag 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/bash
  2. set -e
  3. top=$(pwd)
  4. # parameters
  5. kernel_submodule=
  6. kernel_patchdir=
  7. new_tag=
  8. rebase=
  9. # generated based on new_tag
  10. pq_branch=
  11. # previously checked out in submodule
  12. old_ref=
  13. function cleanup_pq_branch {
  14. if [[ -n $pq_branch ]]; then
  15. echo "cleaning up PQ branch '$pq_branch'"
  16. cd "${top}/${kernel_submodule}"
  17. git checkout --quiet $old_ref
  18. git reset --hard
  19. git branch -D "$pq_branch"
  20. fi
  21. }
  22. function error_exit {
  23. echo "$1"
  24. set +e
  25. cleanup_pq_branch
  26. cd "${top}"
  27. exit 1
  28. }
  29. if [[ "$#" -lt 3 || "$#" -gt 4 ]]; then
  30. echo "USAGE: $0 submodule patchdir tag [rebase]"
  31. echo "\t fetches and checks out 'tag' in 'submodule'"
  32. echo "\t if 'rebase' is given, imports, rebases and exports patchqueue from 'patchdir' as well"
  33. exit 1
  34. fi
  35. kernel_submodule=$1
  36. if [ ! -d "${kernel_submodule}" ]; then
  37. error_exit "'${kernel_submodule}' must be a directory!"
  38. fi
  39. kernel_patchdir=$2
  40. if [ ! -d "${kernel_patchdir}" ]; then
  41. error_exit "'${kernel_patchdir}' must be a directory!"
  42. fi
  43. new_tag=$3
  44. rebase=$4
  45. if [[ -n $(git status --untracked-files=no --porcelain) ]]; then
  46. error_exit "working directory unclean, aborting"
  47. fi
  48. cd "${kernel_submodule}"
  49. ## check for tag and fetch if needed
  50. echo "checking for tag '${new_tag}'"
  51. if [[ -z $(git tag -l "${new_tag}") ]]; then
  52. echo "tag not found, fetching and retrying"
  53. git fetch --tags
  54. fi
  55. if [[ -z $(git tag -l "${new_tag}") ]]; then
  56. error_exit "tag not found, aborting"
  57. fi
  58. echo "tag found"
  59. cd "${top}"
  60. if [[ -n "$rebase" ]]; then
  61. echo ""
  62. echo "automatic patchqueue rebase enabled"
  63. cd "${kernel_submodule}"
  64. ## preparing patch queue branch
  65. old_ref=$(git rev-parse HEAD)
  66. pq_branch="auto_pq/${new_tag}"
  67. cd "${top}"
  68. echo "previous HEAD: ${old_ref}"
  69. echo ""
  70. "${top}/debian/scripts/import-patchqueue" "${kernel_submodule}" "${kernel_patchdir}" "${pq_branch}" || error_exit "failed to import patchqueue"
  71. cd "${kernel_submodule}"
  72. ## rebase patches
  73. echo ""
  74. echo "rebasing patchqueue on top of '${new_tag}'"
  75. git rebase "${new_tag}"
  76. cd "${top}"
  77. ## regenerate exported patch queue
  78. echo ""
  79. "${top}/debian/scripts/export-patchqueue" "${kernel_submodule}" "${kernel_patchdir}" "${new_tag}" || error_exit "failed to export patchqueue"
  80. cleanup_pq_branch
  81. cd "${top}"
  82. pq_branch=
  83. fi
  84. cd "${kernel_submodule}"
  85. echo ""
  86. echo "checking out '${new_tag}' in submodule"
  87. git checkout --quiet "${new_tag}"
  88. cd "${top}"
  89. echo ""
  90. echo "committing results"
  91. git commit --verbose -s -m "update sources to ${new_tag}" -m "(generated with debian/scripts/import-upstream-tag)" "${kernel_submodule}"
  92. if [[ -n "$rebase" ]]; then
  93. git add "${kernel_patchdir}"
  94. git commit --verbose -s -m "rebase patches on top of ${new_tag}" -m "(generated with debian/scripts/import-upstream-tag)" "${kernel_patchdir}"
  95. fi