mfnew 667 B

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