forked from pokey/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfff
executable file
·74 lines (58 loc) · 1.71 KB
/
fff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
### Finish a PR gracefully ###
set -euo pipefail
IFS=$'\n\t'
get_branch() {
# Get current branch
# Thanks StackOverflow: http://stackoverflow.com/a/12142066/678823
branch="$(git rev-parse --abbrev-ref HEAD)"
echo "$branch"
}
get_branch_name() {
# Determine what type of branch this is
branch_name="$(echo "$1" | awk -F '/' '{print $2}')"
echo "$branch_name"
}
get_branch_type() {
# Determine what type of branch this is
branch_type="$(echo "$1" | awk -F '/' '{print $1}')"
echo "$branch_type"
}
is_supported() {
# Check if branch type is supported by git-flow
supported_branch_types=("feature" "bugfix" "release" "hotfix" "support")
for e in "${supported_branch_types[@]}"; do
if [[ "${1}" == "${e}" ]]; then
return 0
fi
done
return 1
}
git_finish_branch() {
# Pass type, keep remote branch
# git flow assumes current branch is to be finished
git flow "${1}" finish -k --showcommands
}
git_delete_branch() {
# Pass type and name, remove remote branch
git flow "${1}" delete "${2}" -r --showcommands
}
main() {
branch="$(get_branch)"
branch_type="$(get_branch_type "$branch")"
branch_name="$(get_branch_name "$branch")"
if $(is_supported "$branch_type"); then
# Will checkout develop when done with merge
echo "Finishing branch $branch"
git_finish_branch "$branch_type"
# Push to remote origin
echo "Pushing to remote origin"
git push
# Now it's safe to delete
echo "Deleting branch $branch"
git_delete_branch "$branch_type" "$branch_name"
else
echo "Branch type '$branch_type' not supported"
fi
}
main