tj.git-extras/bin/git-fresh-branch
Richard Fearn 4f8e411f71 git-fresh-branch: fix handling of 'yes' response when there are changes
'break' isn't valid in its current location in the script, resulting in an
error like:

  /usr/bin/git-fresh-branch: line 42: break: only meaningful in a `for', `while', or `until' loop

Since there's a call to 'clean' right at the end of the script, do nothing if
anything beginning 'Y' or 'y' is entered; execution will continue to the end
of the script, and 'clean' will be called.
2016-11-19 16:59:58 +00:00

25 lines
396 B
Bash
Executable file

#!/usr/bin/env bash
branch=$1
test -z $branch && echo "branch required." 1>&2 && exit 1
changes=`git status --porcelain`
clean()
{
git symbolic-ref HEAD refs/heads/$branch
rm .git/index
git clean -fdx
}
if [ ! -z "$changes" ]; then
read -p "All untracked changes will be lost. Continue [y/N]? " res
case $res in
[Yy]* ) ;;
* ) exit 0;;
esac
fi
clean