Skip to content

Commit

Permalink
new option -d: delete remote and local 'fire-' branches
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaltas committed Dec 29, 2015
1 parent 7284b9c commit 7da0b05
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions git-fire
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Setup.
VERSION="0.0.1"
BRANCH_PREFIX="fire-"

version() {
printf "git-fire version %s\n" "$VERSION"
Expand All @@ -23,12 +24,12 @@ user_email() {
}

new_branch() {
echo "fire-$(current_branch)-$(user_email)-$(current_epoch)"
echo "$BRANCH_PREFIX$(current_branch)-$(user_email)-$(current_epoch)"
}

fire() {
git checkout -b "$(new_branch)"

# cd to git root directory
cd "$(git rev-parse --show-toplevel)"

Expand All @@ -49,6 +50,26 @@ fire() {
printf "\n\nLeave building!\n"
}

delete_fire_branches() {
all_branches=( $(git branch -a) )
for branch in "${all_branches[@]}"
do
for remote in $(git remote); do
if [[ $branch == $remote/$BRANCH_PREFIX* ]] ;
then
branch_without_remote_in_name="${branch/$remote\//}"
git push --delete $remote $branch_without_remote_in_name
fi
done

if [[ $branch == $BRANCH_PREFIX* ]] ;
then
echo "deleting local branch: $branch"
git branch -D $branch
fi
done
}

display_help() {
cat <<-EOF
Expand All @@ -63,15 +84,16 @@ display_help() {
options:
-V, --version Output current version of git-fire
-h, --help Display this help information
-d, --delete Delete branches prefixed with "$BRANCH_PREFIX"
EOF
exit 0
}


case $1 in
-V|--version) version; exit 0 ;;
-h|--help) display_help; exit 0 ;;
-d|--delete) delete_fire_branches; exit 0 ;;
esac

fire "$@"

0 comments on commit 7da0b05

Please sign in to comment.