Skip to content

Commit 95422ce

Browse files
committed
new option -d: delete remote and local 'fire-' branches
1 parent 7284b9c commit 95422ce

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

git-fire

+26-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Setup.
44
VERSION="0.0.1"
5+
BRANCH_PREFIX="fire-"
56

67
version() {
78
printf "git-fire version %s\n" "$VERSION"
@@ -23,12 +24,12 @@ user_email() {
2324
}
2425

2526
new_branch() {
26-
echo "fire-$(current_branch)-$(user_email)-$(current_epoch)"
27+
echo "$BRANCH_PREFIX$(current_branch)-$(user_email)-$(current_epoch)"
2728
}
2829

2930
fire() {
3031
git checkout -b "$(new_branch)"
31-
32+
3233
# cd to git root directory
3334
cd "$(git rev-parse --show-toplevel)"
3435

@@ -49,6 +50,27 @@ fire() {
4950
printf "\n\nLeave building!\n"
5051
}
5152

53+
delete_fire_branches() {
54+
all_branches=( $(git branch -a) )
55+
for branch in "${all_branches[@]}"
56+
do
57+
for remote in $(git remote); do
58+
if [[ $branch == remotes/$remote/$BRANCH_PREFIX* ]] ;
59+
then
60+
branch_without_remote_in_name="${branch/remotes\/$remote\//}"
61+
echo "deleting remote " $remote $branch_without_remote_in_name
62+
git push --delete $remote $branch_without_remote_in_name
63+
fi
64+
done
65+
66+
if [[ $branch == $BRANCH_PREFIX* ]] ;
67+
then
68+
echo "deleting local branch: $branch"
69+
git branch -D $branch
70+
fi
71+
done
72+
}
73+
5274
display_help() {
5375
cat <<-EOF
5476
@@ -63,6 +85,7 @@ display_help() {
6385
options:
6486
-V, --version Output current version of git-fire
6587
-h, --help Display this help information
88+
-d, --delete Delete branches prefixed with "$BRANCH_PREFIX"
6689
6790
EOF
6891
exit 0
@@ -72,6 +95,7 @@ EOF
7295
case $1 in
7396
-V|--version) version; exit 0 ;;
7497
-h|--help) display_help; exit 0 ;;
98+
-d|--delete) delete_fire_branches; exit 0 ;;
7599
esac
76100

77101
fire "$@"

0 commit comments

Comments
 (0)