Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 1e73e565b0
Fetching contributors…

Cannot retrieve contributors at this time

executable file 107 lines (90 sloc) 1.903 kb
#!/bin/bash
CURRENT=$(git symbolic-ref -q HEAD || git rev-parse HEAD)
CURRENT=${CURRENT#refs/heads/}
# default settings
explain=false
verbose=true
run=true
force=false
BRANCH="$CURRENT"
# colors
RED="\033[0;31m"
YELLOW="\033[1;33m"
GREEN="\033[0;32m"
NO_COLOR="\033[0m"
die() {
echo -e "${RED}${@}${NO_COLOR}"
exit 1
}
warn() {
echo -e "${YELLOW}${@}${NO_COLOR}"
}
good() {
echo -e "${GREEN}${@}${NO_COLOR}"
}
printUsage() {
echo "usage: git-close [-f|--force] [BRANCH]"
echo "Deletes the current branch or a branch named BRANCH."
echo ""
echo "Options"
echo " -f --force Passes -D to git-branch, forcing the branch to be deleted."
echo ""
echo "If BRANCH is not provided, the current branch is used. If BRANCH is master,"
echo "exit with an error message."
}
for arg in "$@"; do
case "$arg" in
-f | -D | --force)
force=true
;;
-e | --explain | --dry-run)
explain=true
verbose=true
run=false
;;
-v | --verbose)
verbose=true
;;
-q | --quiet)
verbose=false
;;
-h | --help)
exit 0
;;
-*)
warn "${YELLOW}$0: unrecognized parameter '$arg'${NO_COLOR}"
exit 1
;;
*)
BRANCH="$arg"
;;
esac
shift
done
GIT=`which git`
git() {
if [ "$verbose" = true ]; then
echo -e "+ ${GREEN}git $@${NO_COLOR}"
fi
if [ "$run" = true ]; then
eval "$GIT $@"
fi
}
if [ "$BRANCH" = "master" ]; then
die "Cowardly refusing to remove master branch"
fi
if [[ "$BRANCH" = "$CURRENT" && "$CURRENT" != "master" ]]; then
git checkout master
fi
if [ "$force" = true ]; then
args="-D"
else
args="-d"
fi
git branch $args $BRANCH
if [ $? != 0 ]; then
warn "Unable to close $BRANCH. If you're sure you want to delete it, try adding --force."
git checkout $BRANCH
elif [ "$run" = true ]; then
good "Branch $BRANCH has been closed"
fi
Jump to Line
Something went wrong with that request. Please try again.