-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitrelease
More file actions
104 lines (82 loc) · 2.3 KB
/
Copy pathgitrelease
File metadata and controls
104 lines (82 loc) · 2.3 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/sh
# The sed expression here replaces all backslashes by forward slashes.
# This helps our Windows users, while not bothering our Unix users.
export GITFLOW_DIR=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
usage()
{
echo "usage: gitrelease <version>"
}
main()
{
# Load common git functionality
. "$GITFLOW_DIR/common/gitfunctions"
# Check we have two parameters
if [ $# -lt 1 ];
then
warn "error: missing arguments"
usage
exit 1
fi
# Read arguments
TAGGED_VERSION=$1
TAGGED_TEMP_BRANCH="$TAGGED_VERSION-Temp"
TEMP_TAGGED="$TAGGED_VERSION"
# Checks
require_git_repo
require_clean_working_tree
# Get current branch name
local current_branch=$(echo "$(git_current_branch)" | grep "^$PREFIX")
# Pull current branch from origin including tags
echo "Fetching tags"
git fetch --tags
# Check tagged version does exist, checkout to dev instead
if ! git_tag_exists $TAGGED_VERSION;
then
TEMP_TAGGED="$TAGGED_VERSION"
TAGGED_VERSION="dev"
fi
# Check tagged temp branch does not exist
if git_tag_exists $TAGGED_TEMP_BRANCH;
then
die "error: version temp branch name exists"
fi
# Check we are on master
if [ "$current_branch" != "master" ];
then
# If not, checkout to master
git checkout master || \
die "error: could not checkout master"
fi
# Fetch latest
echo "Pulling branch master"
git pull origin master || \
die "error: could not pull master"
# Checkout to tag
echo "Creating temp branch from tag commit ref"
git checkout -f $TAGGED_VERSION
# Create new branch from tag
git branch $TAGGED_TEMP_BRANCH
# Checkout back to master
git checkout -f master
# Attempt to merge tagged version into master
echo "Releasing $TAGGED_VERSION to 'master'"
git merge -q --no-ff -m "$TEMP_TAGGED" $TAGGED_TEMP_BRANCH
# If we haven't tagged the release yet, make sure we do
if [ "$TAGGED_VERSION" == "dev" ];
then
git tag -a -m "Created version $TEMP_TAGGED." $TEMP_TAGGED
fi
# Push branch
echo "Pushing $TEMP_TAGGED to origin master including tags"
git push origin master || \
die "error: could not push to origin master"
git push --tags || \
die "error: could not push tags to origin"
# Clean up temp tag
git branch -D $TAGGED_TEMP_BRANCH
# Checkout to back to branch
git checkout $current_branch
# Finished
echo "Released $TEMP_TAGGED to master"
}
main "$@"