git-version-bump 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -34,6 +34,18 @@ I recommend adding an alias to your `~/.gitconfig` file, for less typing:
34
34
  [alias]
35
35
  vb = version-bump
36
36
 
37
+ You can also add your own release notes to your release tags, by using the
38
+ `-n` (or `--notes`, if you like typing) option:
39
+
40
+ git version-bump -n minor
41
+
42
+ This will open an editor, containing a list of the commits since the last
43
+ release tag, in which you can type your release notes. If you follow
44
+ standard git commit style (a "heading" line, then a blank line, followed by
45
+ free-form text) you're perfectly positioned to use
46
+ [github-release](http://theshed.hezmatt.org/github-release) to make
47
+ gorgeous-looking release announcements to Github.
48
+
37
49
 
38
50
  ## In your `Rakefile`
39
51
 
@@ -113,3 +125,11 @@ to do:
113
125
 
114
126
  This will work correctly inside your git tree, and also in your installed
115
127
  gem. Magical!
128
+
129
+
130
+ # Contributing
131
+
132
+ Send your pull requests to the [Github
133
+ repo](https://github.com/mpalmer/git-version-bump), or send patches to
134
+ `theshed+git-version-bump@hezmatt.org`. Bug reports can be sent to the same
135
+ place, although I greatly prefer patches.
@@ -7,14 +7,20 @@ if ARGV[0].nil? or
7
7
  ARGV[0] == '-h' or
8
8
  ARGV[0] == '--help'
9
9
  $stderr.puts <<-EOF.gsub(/^\t\t/, '')
10
- Usage: git version-bump <major|minor|patch>
10
+ Usage: git version-bump [-n|--notes] <major|minor|patch|show>
11
11
 
12
12
  'major': x.y.z -> x+1.0.0
13
13
  'minor': x.y.z -> x.y+1.0
14
14
  'patch': x.y.z -> x.y.z+1
15
+
16
+ 'show': Display the current GVB version
17
+
18
+ --release: Prompt for "release notes" to add to the release tag
15
19
  EOF
16
20
  end
17
21
 
22
+ release_notes = ARGV.delete('-n') or ARGV.delete('--notes')
23
+
18
24
  if ARGV[0].nil? or ARGV[0].empty?
19
25
  exit 1
20
26
  elsif ARGV[0] == '-h' or ARGV[0] == '--help'
@@ -23,11 +29,11 @@ end
23
29
 
24
30
  case ARGV[0].downcase
25
31
  when /^maj?o?r?$/
26
- GVB.tag_version "#{GVB.major_version + 1}.0.0"
32
+ GVB.tag_version "#{GVB.major_version + 1}.0.0", release_notes
27
33
  when /^min?o?r?$/
28
- GVB.tag_version "#{GVB.major_version}.#{GVB.minor_version+1}.0"
34
+ GVB.tag_version "#{GVB.major_version}.#{GVB.minor_version+1}.0", release_notes
29
35
  when /^pa?t?c?h?$/
30
- GVB.tag_version "#{GVB.major_version}.#{GVB.minor_version}.#{GVB.patch_version+1}"
36
+ GVB.tag_version "#{GVB.major_version}.#{GVB.minor_version}.#{GVB.patch_version+1}", release_notes
31
37
  when /^sh?o?w?$/
32
38
  puts GVB.version
33
39
  exit 0
@@ -1,3 +1,6 @@
1
+ require 'tempfile'
2
+ require 'digest/sha1'
3
+
1
4
  module GitVersionBump
2
5
  def self.dirty_tree?
3
6
  # Are we in a dirty, dirty tree?
@@ -42,14 +45,14 @@ module GitVersionBump
42
45
  strip.
43
46
  gsub(/^v/, '').
44
47
  gsub('-', '.')
45
-
48
+
46
49
  # If git returned success, then it gave us a described version.
47
50
  # Success!
48
51
  return git_ver if $? == 0
49
52
 
50
53
  # git failed us; we're either not in a git repo or else we've never
51
54
  # tagged anything before.
52
-
55
+
53
56
  # Are we in a git repo with no tags? If so, dump out our
54
57
  # super-special version and be done with it.
55
58
  system("git status >/dev/null 2>&1")
@@ -79,12 +82,12 @@ module GitVersionBump
79
82
  def self.major_version(gem = nil)
80
83
  ver = version(gem)
81
84
  v = ver.split('.')[0]
82
-
85
+
83
86
  unless v =~ /^[0-9]+$/
84
87
  raise ArgumentError,
85
88
  "#{v} (part of #{ver.inspect}) is not a numeric version component. Abandon ship!"
86
89
  end
87
-
90
+
88
91
  return v.to_i
89
92
  end
90
93
 
@@ -93,12 +96,12 @@ module GitVersionBump
93
96
  def self.minor_version(gem = nil)
94
97
  ver = version(gem)
95
98
  v = ver.split('.')[1]
96
-
99
+
97
100
  unless v =~ /^[0-9]+$/
98
101
  raise ArgumentError,
99
102
  "#{v} (part of #{ver.inspect}) is not a numeric version component. Abandon ship!"
100
103
  end
101
-
104
+
102
105
  return v.to_i
103
106
  end
104
107
 
@@ -107,12 +110,12 @@ module GitVersionBump
107
110
  def self.patch_version(gem = nil)
108
111
  ver = version(gem)
109
112
  v = ver.split('.')[2]
110
-
113
+
111
114
  unless v =~ /^[0-9]+$/
112
115
  raise ArgumentError,
113
116
  "#{v} (part of #{ver.inspect}) is not a numeric version component. Abandon ship!"
114
117
  end
115
-
118
+
116
119
  return v.to_i
117
120
  end
118
121
 
@@ -153,12 +156,46 @@ module GitVersionBump
153
156
 
154
157
  DATE = date('git-version-bump')
155
158
 
156
- def self.tag_version(v)
159
+ def self.tag_version(v, release_notes = false)
157
160
  if dirty_tree?
158
161
  puts "You have uncommitted files. Refusing to tag a dirty tree."
159
162
  else
160
- puts "Tagging version #{v}..."
161
- system("git tag -a -m 'Version v#{v}' v#{v}")
163
+ if release_notes
164
+ # We need to find the tag before this one, so we can list all the commits
165
+ # between the two. This is not a trivial operation.
166
+ prev_tag = `git describe --always`.strip.gsub(/-\d+-g[0-9a-f]+$/, '')
167
+
168
+ log_file = Tempfile.new('gvb')
169
+
170
+ log_file.puts <<-EOF.gsub(/^\t\t\t\t\t/, '')
171
+
172
+
173
+
174
+ # Write your release notes above. The first line should be the release name.
175
+ # To help you remember what's in here, the commits since your last release
176
+ # are listed below.
177
+ #
178
+ EOF
179
+
180
+ log_file.close
181
+ system("git log --format='# %h %s' #{prev_tag}..HEAD >>#{log_file.path}")
182
+
183
+ pre_hash = Digest::SHA1.hexdigest(File.read(log_file.path))
184
+ system("git config -e -f #{log_file.path}")
185
+ if Digest::SHA1.hexdigest(File.read(log_file.path)) == pre_hash
186
+ puts "Release notes not edited; aborting"
187
+ log_file.unlink
188
+ return
189
+ end
190
+
191
+ puts "Tagging version #{v}..."
192
+ system("git tag -a -F #{log_file.path} v#{v}")
193
+ log_file.unlink
194
+ else
195
+ # Crikey this is a lot simpler
196
+ system("git tag -a -m 'Version v#{v}' v#{v}")
197
+ end
198
+
162
199
  system("git push >/dev/null 2>&1")
163
200
  system("git push --tags >/dev/null 2>&1")
164
201
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-version-bump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-03 00:00:00.000000000 Z
12
+ date: 2014-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  segments:
91
91
  - 0
92
- hash: -3956615801826870030
92
+ hash: -2656244140223345320
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  segments:
100
100
  - 0
101
- hash: -3956615801826870030
101
+ hash: -2656244140223345320
102
102
  requirements: []
103
103
  rubyforge_project:
104
104
  rubygems_version: 1.8.23