-
Notifications
You must be signed in to change notification settings - Fork 20
/
tag
executable file
·90 lines (75 loc) · 2.16 KB
/
tag
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
#!/bin/bash
# --------------------------------------------------------------------
# Run this within a local respository directory to tag the latest
# commit, both locally and in the remote repository.
#
# For example:
#
#>> ./tag 1.1.2
# ++ git log --pretty=format:%H -n 1
# + latest_checksum=2cfa6a85c6d3bcfde3863f3e7417d0099782e198
# + git tag -a v1.1.2 -m 'version 1.1.2' 2cfa6a85c6d3bcfde3863f3e7417d0099782e198
# + git tag
# v0.9.7
# v0.9.7.1
# v0.9.8
# v0.9.8.1
# v0.9.8.3
# v0.9.9
# v0.9.9.1
# v1.0
# v1.0.1
# v1.0.2
# v1.0.3
# v1.0.4
# v1.1
# v1.1.1
# v1.1.2
# + git push origin v1.1.2
# Password for 'https://[email protected]':
# Counting objects: 1, done.
# Writing objects: 100% (1/1), 164 bytes | 0 bytes/s, done.
# Total 1 (delta 0), reused 0 (delta 0)
# To https://[email protected]/cfpython/cf-python.git
# * [new tag] v1.1.2 -> v1.1.2
# + set +x
# --------------------------------------------------------------------
if [[ ! $1 ]] ; then
echo "No version \$1 (e.g. 2.0.1)"
exit 1
fi
version=$1
major_version=$(echo $version | cut -c 1)
current_branch=`git rev-parse --abbrev-ref HEAD`
if [[ $major_version == 1 && $current_branch != v1 ]] ; then
echo "Can only tag version $version in branch v1, not branch $current_branch"
exit 2
fi
if [[ $major_version == 2 && $current_branch != master ]] ; then
echo "Can only tag version $version in branch master, not branch $current_branch"
echo "Can only tag branch 'master'"
exit 2
fi
echo "New tag: v$version"
echo
echo "Existing Tags:"
git tag
echo
x=`git tag | grep v$version`
if [[ $? -eq 0 ]] ; then
echo "ERROR: Tag v$version already exists"
exit 1
fi
set -x
# Find checksum of latest commit
latest_checksum=`git log --pretty=format:'%H' -n 1`
# Create tag in local repository
git tag -a v$version -m "version $version" $latest_checksum
# Look at at all my tags
git tag
# Push tag from a user account to the root cf-python repo (note the
# the command run gives the name of the current branch, to push from):
#git push --tags upstream $(git rev-parse --abbrev-ref HEAD):master
# Alternatively, push tag to repo from cf-python directly, via (uncomment):
git push origin v$version
set +x