git-add-user-branch.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #! /bin/sh -e
  2. # Create a new upstream user branch.
  3. # Usage:
  4. # contrib/git-add-user-branch.sh [<personal-prefix>/]<branch-name> <base>
  5. usage ()
  6. {
  7. echo "Usage:"
  8. echo " $0 [<personal-prefix>/]<branch-name> <start-point>"
  9. echo
  10. echo "personal space must already have been set up using"
  11. echo "contrib/gcc-git-customization.sh"
  12. exit 1
  13. }
  14. if [ $# != 2 ]
  15. then
  16. usage
  17. fi
  18. userpfx=$(git config --get "gcc-config.userpfx")
  19. user=$(git config --get "gcc-config.user")
  20. if [ -z "$userpfx" -o -z "$user" ]
  21. then
  22. usage
  23. fi
  24. branch=$(echo "$1" | sed -r "s:(${userpfx}/)?(.*)$:\2:")
  25. start=$2
  26. # Sanity check the new branch argument. If there is no '/', then the
  27. # vendor will be the same as the entire first argument.
  28. if [ -z "$branch" ]
  29. then
  30. usage
  31. fi
  32. git push users/${userpfx} ${start}:refs/users/${user}/heads/${branch}
  33. git fetch -q users/${userpfx}
  34. git branch ${userpfx}/${branch} remotes/users/${userpfx}/${branch}
  35. echo "You are now ready to check out ${userpfx}/${branch}"
  36. echo "To push the branch upstream use:"
  37. echo " git push users/${userpfx} ${userpfx}/${branch}"