Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new option -d: delete remote and local 'fire-' branches #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
new option -d: delete remote and local 'fire-' branches
  • Loading branch information
dbaltas committed Dec 29, 2015
commit 95422ce405cd7e89616d587e026ba32594e1da9e
28 changes: 26 additions & 2 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,27 @@ 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 == remotes/$remote/$BRANCH_PREFIX* ]] ;
then
branch_without_remote_in_name="${branch/remotes\/$remote\//}"
echo "deleting remote " $remote $branch_without_remote_in_name
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,6 +85,7 @@ 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
Expand All @@ -72,6 +95,7 @@ EOF
case $1 in
-V|--version) version; exit 0 ;;
-h|--help) display_help; exit 0 ;;
-d|--delete) delete_fire_branches; exit 0 ;;
esac

fire "$@"