mfnew 667 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bash
  2. #
  3. # mfnew
  4. #
  5. # Create a new branch from the default target with the given name
  6. #
  7. usage() {
  8. echo "usage: `basename $0` [1|2] [name]" 1>&2
  9. }
  10. [[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { usage; exit 1; }
  11. MFINFO=$(mfinfo "$@") || exit 1
  12. IFS=' ' read -a INFO <<< "$MFINFO"
  13. TARG=${INFO[3]}
  14. BRANCH=pr_for_$TARG-$(date +"%G-%m-%d_%H.%M.%S")
  15. # BRANCH can be given as the last argument
  16. case "$#" in
  17. 1 ) case "$1" in
  18. 1|2) ;;
  19. *) BRANCH=$1 ;;
  20. esac
  21. ;;
  22. 2 ) case "$1" in
  23. 1|2) BRANCH=$2 ;;
  24. *) usage ; exit 1 ;;
  25. esac
  26. ;;
  27. esac
  28. git fetch upstream
  29. git checkout --no-track upstream/$TARG -b $BRANCH