-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgit-hotfix
39 lines (31 loc) · 951 Bytes
/
git-hotfix
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
#!/bin/sh
set -e
masterBranch="master"
((!$#)) && echo No hotfix name, command ignored! && echo " - git hotfix <version> <tag>" && exit 1
if [[ "$1" = "--h" ]] ; then
echo "Creates a hotfix branch at the latest available tag and checks it out.";
echo " - git hotfix <version> <tag>";
echo "Tag is optional. If not supplied, it will take the latest tag automatically"
exit 1;
fi
if ! [ -d .git ] ; then
if ! [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ] ; then
echo "Current directory is not a git folder."
exit 1;
fi
fi
numericRegex="^[.0-9]+$"
if ! [[ "$1" =~ $numericRegex ]] ; then
echo error: Not a numeric version
exit 1
fi
echo Starting hotfix $1
head=$masterBranch
if [ "$2" = "" ]; then
head=$(git describe --tags `git rev-list --tags --max-count=1`)
echo branching from latest tag: $head
else
head=$2
echo branching from requested cs: $head
fi
git checkout -b hotfix/$1 $head