git-fetch-vendor.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. usage ()
  3. {
  4. echo "Usage: $0 [--enable-push] <vendor>"
  5. echo "The following vendors are already known:"
  6. git ls-remote ${upstream} "*/vendors/*" | sed -r "s:.*/vendors/([^/]+)/.*:\1:"|sort|uniq
  7. exit 1
  8. }
  9. # Should we insert a "push" refspec to enable pushing to the vendor branch?
  10. enable_push=no
  11. upstream=`git config --get "gcc-config.upstream"`
  12. if [ x"$upstream" = x ]
  13. then
  14. echo "Config gcc-config.upstream not set, run contrib/gcc-git-customization"
  15. exit 1
  16. fi
  17. case $# in
  18. 1)
  19. # vendor names never start with -, so catch this in case user wrote something like --help.
  20. case "$1" in
  21. -*)
  22. usage
  23. ;;
  24. *)
  25. vendor=$1
  26. ;;
  27. esac
  28. ;;
  29. 2)
  30. vendor=$2
  31. if [ "$1" = "--enable-push" ]
  32. then
  33. enable_push=yes
  34. else
  35. usage
  36. fi
  37. ;;
  38. *)
  39. usage
  40. ;;
  41. esac
  42. echo "setting up git to fetch vendor ${vendor} to remotes/vendors/${vendor}"
  43. url=$(git config --get "remote.${upstream}.url")
  44. pushurl=$(git config --get "remote.${upstream}.pushurl")
  45. git config "remote.vendors/${vendor}.url" "${url}"
  46. if [ "x$pushurl" != "x" ]
  47. then
  48. git config "remote.vendors/${vendor}.pushurl" "${pushurl}"
  49. fi
  50. git config --replace-all "remote.vendors/${vendor}.fetch" "+refs/vendors/${vendor}/heads/*:refs/remotes/vendors/${vendor}/*" "refs/vendors/${vendor}/heads"
  51. git config --replace-all "remote.vendors/${vendor}.fetch" "+refs/vendors/${vendor}/tags/*:refs/tags/vendors/${vendor}/*" "refs/vendors/${vendor}/tags"
  52. if [ "$enable_push" = "yes" ]
  53. then
  54. echo "Warning: take care when pushing that you only push the changes you intend."
  55. echo "E.g. use \"git push vendors/${vendor} HEAD\" to push the current branch"
  56. git config --replace-all "remote.vendors/${vendor}.push" "refs/heads/${vendor}/*:refs/vendors/${vendor}/heads/*"
  57. else
  58. git config --unset-all "remote.vendors/${vendor}.push"
  59. fi
  60. git fetch vendors/${vendor}