-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeat.sh
executable file
·86 lines (78 loc) · 1.98 KB
/
feat.sh
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
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
set -e
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
-e|--extension)
EXTENSION="$2"
shift # past argument
shift # past value
;;
-s|--searchpath)
SEARCHPATH="$2"
shift # past argument
shift # past value
;;
--delete)
DELETE=YES
shift # past argument
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
if { [ "$CURRENT_BRANCH" != "main" ] && [ "$CURRENT_BRANCH" != "master" ]; } && [ "$DELETE" != "YES" ]
then
echo "You must be on the main branch to create a feature branch"
exit 1
fi
#check that the repo is clean and up to date
if [ -n "$(git status --porcelain)" ]
then
echo "You have uncommitted changes"
exit 1
fi
# git fetch
if [ -n "$(git diff --name-only origin/$CURRENT_BRANCH)" ]
then
echo "You are not up to date with the remote branch"
exit 1
fi
# echo "extension: $EXTENSION"
# echo "searchpath: $SEARCHPATH"
# echo "default: $DEFAULT"
# echo "positional args: $@"
# echo "positional args: $POSITIONAL_ARGS"
if [ "$DELETE" == "YES" ] && { [ "$@" = "master" ] || [ "$@" = "develop" ] || [ "$@" = "main" ]; }
then
echo "Deleting master/main and develop branches not alloed"
exit 1
fi
if [ -z "$@" ]
then
echo "eksempel på kall: feat.sh <feature branch> (e.g 1234-feat-my-feature)"
exit 1
else
BRANCH=$@
echo "branch: "$BRANCH
fi
if [ "$DELETE" == "YES" ]
then
echo "Deleting branch: "$BRANCH
git branch -d $BRANCH
git push origin --delete "feature/$BRANCH"
else
echo "Creating branch: "$BRANCH
git checkout $CURRENT_BRANCH
git pull
git checkout -b "feature/$1" $CURRENT_BRANCH
git push -u origin "feature/$1"
fi