versioneer 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f1e3978f9d739b3a0e37ab2182cf0f692a8c1cb
4
- data.tar.gz: 999abeeadab4361199558bfae40daf4db19cebe3
3
+ metadata.gz: d3672df4599ece68c07bd90b81ee88ffbfaad7e5
4
+ data.tar.gz: c2e742df40e00c93dc2fda05e60cb99eb85d77ff
5
5
  SHA512:
6
- metadata.gz: 78b06f745b17f73ea085e2c9f33c2225c085a541fdd1f21e15f03222f0adac8e115a56d05144f67b5842cb1fc872bd8bfb6f0d462e2ac30d5fb87e6acbaa5467
7
- data.tar.gz: 59161c3239ceb2090c2563488862934adf507a8242d566c07f4ada062b8e8dcd0cc634a489455a95dd567c87128ce26a3813daa9fde012ed1efd30bc218b635d
6
+ metadata.gz: ce76334fbc57eb035b24faaece27228acbc5dfa408737645a1737921eb6d2391818c44f9e45e2c388f54b28c67b08dfb8537392a7acba2fa5e06b125fb62704d
7
+ data.tar.gz: 9abfe251e0fd6d9b5f2b9a3e1ad1e0cda86b0e324af2a388ee7ef618c5583e821a91f609e70eccad66f5e9e8d725efa06ea3f707dd80b29ada133d4a85fc035e
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /*.gem
11
+ /version.lock
data/.travis.yml CHANGED
@@ -2,4 +2,7 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.3.1
5
- before_install: gem install bundler -v 1.13.6
5
+ before_install:
6
+ - gem update bundler
7
+ after_success:
8
+ - bundle exec codeclimate-test-reporter
data/.versioneer.yml ADDED
@@ -0,0 +1,9 @@
1
+ # Versioneer Project Configuration
2
+ # https://git.io/versioneer-help
3
+
4
+ type: Git
5
+ bump_segment: minor
6
+ prereleases:
7
+ - alpha
8
+ - beta
9
+ - beta
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Versioneer Gem Changelog
2
+
3
+ ### 0.2 (2017-01-01)
4
+
5
+ * __`NEW`__ Add support for project config files.
6
+ * __`NEW`__ Add Ruby/Rails examples to README
7
+ * __`NEW`__ CodeClimate integration and test coverage.
8
+ * __`~~~`__ Untracked files in Git repos should not indicate alpha builds.
9
+ * __`~~~`__ Use Versioneer to manage its own Gem version.
10
+
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in versioneer.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem "simplecov"
8
+ gem "codeclimate-test-reporter", "~> 1.0.0"
9
+ end
data/README.md CHANGED
@@ -1,60 +1,89 @@
1
1
  # Versioneer
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/versioneer.svg)](https://badge.fury.io/rb/versioneer)
3
4
  [![Build Status](https://travis-ci.org/binarybabel/gem-versioneer.svg?branch=master)](https://travis-ci.org/binarybabel/gem-versioneer)
4
5
  [![Build status](https://ci.appveyor.com/api/projects/status/k3i9rbgy2q8xdl78/branch/master?svg=true)](https://ci.appveyor.com/project/babelop/gem-versioneer/branch/master)
6
+ [![Code Climate](https://codeclimate.com/github/binarybabel/gem-versioneer/badges/gpa.svg)](https://codeclimate.com/github/binarybabel/gem-versioneer)
7
+ [![Test Coverage](https://codeclimate.com/github/binarybabel/gem-versioneer/badges/coverage.svg)](https://codeclimate.com/github/binarybabel/gem-versioneer/coverage)
5
8
 
6
9
  __Dynamic project versioning (alpha/beta/rc) from commits since last Git Tag.__
7
10
 
8
11
  Versioneer **determines a project's version** from the latest source-control tag, then **adjusts automatically** by adding/bumping prereleases based on changes made since the last tagged release.
9
12
 
10
- Integration tested on **UNIX/MacOS and Windows**.
13
+ Integration tested on **UNIX/macOS and Windows**.
11
14
 
12
15
  ## Overview
13
16
 
14
- #### Non-production environments (default settings)
17
+ Project versions update automatically based on VCS changes and where the code has been deployed. The table below depicts the default settings; the prerelease workflow is customizable through code or a project config file.
15
18
 
16
- * No changes since last VCS Tag (Ex. v0.1.0)
17
- - **Same as Tag** `0.1.0`
18
- * Uncommitted changes
19
- - **Minor Bump + Alpha** `0.2.alpha1`
20
- * First commit
21
- - **Minor Bump + Beta** `0.2.beta1`
22
- * First commit with uncommitted changes
23
- - **Minor Bump + Alpha2** `0.2.alpha2`
24
-
25
- #### In production
26
-
27
- * No changes since last VCS Tag (Ex. v0.1.0)
28
- - **Same as Tag** `0.1.0`
29
- * Uncommitted changes
30
- - **Ignored in Production** `0.1.0`
31
- * First commit past VCS Tag
32
- - **Minor Bump + Release Candidate** `0.2.rc1`
33
- - Optionally, patches can be used instead of "rc" in production:
34
- - **Minor Bump + Patch** `0.1.1`
19
+ | VCS State | Last Tag/Release | Development Ver. | Production Ver. |
20
+ | --- | --- | --- | --- |
21
+ | No changes since last tag | v0.1.0 | `0.1.0` *Same as Tag* | `0.1.0` *Same as Tag* |
22
+ | Uncommitted changes | v0.1.0 | `0.2.alpha1` | `0.1.0` *Same as Tag* |
23
+ | First commit | v0.1.0 | `0.2.beta1` | `0.2.rc1` **or** `0.1.1` |
24
+ | First commit + Changes | v0.1.0 | `0.2.alpha2` | `0.2.rc1` **or** `0.1.1` |
25
+ | Second commit | v0.1.0 | `0.2.beta2` | `0.2.rc2` **or** `0.1.2` |
26
+ | Tag previous commit | v0.2.0 | `0.2.0` | `0.2.0` |
35
27
 
36
28
  ## Usage
37
29
 
38
- ### Ruby Project (Rails, Rack, etc.)
30
+ * [Configuration options are documented in the Wiki.](https://github.com/binarybabel/gem-versioneer/wiki)
31
+ * The Versioneer environment is selected from the following system variables:
32
+ * _Any value other than "production" is assumed to be "development"_
39
33
 
40
- TODO
34
+ ```
35
+ ENV['VERSIONEER_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['ENV']
36
+ ```
41
37
 
42
38
  ### Command-Line
43
39
 
44
- CLI usage defaults to "production" mode, unless otherwise given by ENV variable.
40
+ CLI usage defaults to "production" mode.
45
41
 
46
42
  ```
47
43
  $ git tag -am 'Release 0.1' v0.1
48
-
44
+ ...
49
45
  $ versioneer
50
46
  0.1
51
-
47
+ ...
52
48
  $ git commit --allow-empty -m 'Some changes.'
53
-
54
- $versioneer
49
+ ...
50
+ $ versioneer
55
51
  0.2.rc1
52
+ ...
53
+ $ versioneer --help
54
+ ```
55
+
56
+ ### Ruby Project (Rails, Rack, etc.)
57
+
58
+ * Add Versioneer to your Gemfile
59
+
60
+ ```
61
+ gem 'versioneer', '~> 0.1'
62
+ ...
63
+ $ bundle install
64
+ ```
65
+
66
+ * Generate a config file
67
+
56
68
  ```
69
+ $ bundle exec versioneer init
70
+ ...
71
+ Generating config
72
+ + .versioneer.yml
73
+ ```
74
+
75
+ * Modify your project's version variable
76
+
77
+ ```
78
+ require 'versioneer'
79
+ module MyApp
80
+ VERSION = Versioneer::Config.new(Rails.root).version.to_s
81
+ end
82
+ ```
83
+
84
+ ## Settings & Customization
57
85
 
86
+ **[Check out the Versioneer Wiki for more information](https://github.com/binarybabel/gem-versioneer/wiki)**
58
87
 
59
88
  ## Contributing
60
89
 
data/Rakefile CHANGED
@@ -1,10 +1,23 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
7
  t.test_files = FileList['test/**/*_test.rb']
8
8
  end
9
9
 
10
10
  task :default => :test
11
+
12
+ load 'changelog.rake'
13
+
14
+ task :relock do
15
+ system './bin/versioneer unlock > /dev/null'
16
+ system './bin/versioneer lock'
17
+ puts '...'
18
+ puts "Preparing to build Gem version #{`./bin/versioneer print`}..."
19
+ puts 'Press Ctrl-C now to cancel'
20
+ system 'sleep 5'
21
+ end
22
+
23
+ Rake::Task[:build].enhance [:relock]
data/bin/versioneer CHANGED
@@ -1,7 +1,117 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
+ require 'optparse'
4
5
  require 'versioneer'
5
- puts Versioneer::Git.new(Dir.getwd, {
6
+
7
+ cli_opts = {}
8
+ repo_opts = {
6
9
  environment: 'production'
7
- }).to_s
10
+ }
11
+
12
+ opparser = OptionParser.new do |opts|
13
+ opts.banner = [
14
+ '-------------------------------------',
15
+ 'Usage: versioneer [action] [options]',
16
+ 'Guide: https://git.io/versioneer-help',
17
+ '-------------------------------------',
18
+ ' Actions',
19
+ ' %-33s%s' % ['status', 'Report on versions for all environments (default action)'],
20
+ ' %-33s%s' % ['print', 'Print version number for production, or --env environment'],
21
+ ' %-33s%s' % ['init', 'Generate default configuration file'],
22
+ ' %-33s%s' % ['lock', 'Lock (save) current version (for deployments without VCS repo)'],
23
+ ' %-33s%s' % ['unlock', 'Unlock (discard) previously saved version'],
24
+ '',
25
+ ' Environment Options',
26
+ ' %-33s%s' % ['VERSIONEER_ENV > RAILS_ENV > RACK_ENV > ENV (searched in order, default value = production)', ''],
27
+ '',
28
+ ' Options',
29
+ ].join("\n")
30
+ opts.on('-c FILE', '--config=FILE', 'Config file (.versioneer.yml)') do |v|
31
+ cli_opts[:config] = v
32
+ end
33
+ opts.on('-e ENVIRONMENT', '--env=ENVIRONMENT', 'Environment (production)') do |v|
34
+ repo_opts[:environment] = v
35
+ end
36
+ end
37
+ opparser.parse!
38
+
39
+ if (config_base = cli_opts[:config])
40
+ unless config_base.match(%r{#{File::SEPARATOR}})
41
+ config_base = File.join(Dir.getwd, cli_opts[:config])
42
+ end
43
+ unless File.exist?(config_base)
44
+ STDERR.puts("ERROR: Versioneer config file does not exist. (#{config_base})")
45
+ exit(1)
46
+ end
47
+ else
48
+ config_base = Dir.getwd
49
+ end
50
+
51
+ begin
52
+ v = Versioneer::Config.new(config_base, repo_opts)
53
+ rescue Versioneer::MissingConfigError => e
54
+ if cli_opts[:config]
55
+ # Rethrow missing config error if file given on command-line.
56
+ raise e
57
+ else
58
+ # Use default VCS if config file not given.
59
+ v = Versioneer.const_get(Versioneer::Config::DEFAULT_TYPE.to_sym).new(Dir.getwd, repo_opts)
60
+ end
61
+ end
62
+
63
+ case (cmd = ARGV.shift)
64
+ when nil, 'status'
65
+ puts '---------------------------------------------------'
66
+ puts '%51s' % ["VERSIONEER GEM v#{Versioneer::GEM_VERSION}"]
67
+ puts '---------------------------------------------------'
68
+ puts 'Versioneer has calculated the following versions...'
69
+ if File.exist?(Versioneer::Config::DEFAULT_FILE)
70
+ puts "* Edit '#{Versioneer::Config::DEFAULT_FILE}' to modify project settings"
71
+ else
72
+ puts '* Run `versioneer init` to customize this project'
73
+ end
74
+ puts '* Try the --help option for additional commands'
75
+ puts '---------------------------------------------------'
76
+ locked = (v.respond_to? :lock_file and File.exist?(v.lock_file)) && '* LOCKED' || ''
77
+ v.environment = 'development'
78
+ puts "DEVELOPMENT -> #{v} #{locked}"
79
+ v.environment = 'production'
80
+ puts " PRODUCTION -> #{v} #{locked}"
81
+ when 'print'
82
+ puts v.to_s
83
+ when 'lock'
84
+ v.lock!(ARGV.shift)
85
+ puts "+ #{Versioneer::Config::DEFAULT_LOCK}"
86
+ puts "Locked at version: #{v}"
87
+ puts 'Will output this version without querying VCS.'
88
+ when 'unlock'
89
+ v.unlock!
90
+ puts "- #{Versioneer::Config::DEFAULT_LOCK}"
91
+ puts "Unlocked. #{v.environment.capitalize} now: #{v}"
92
+ when 'init'
93
+ init_file = Versioneer::Config::DEFAULT_FILE
94
+ if File.exist?(init_file)
95
+ STDERR.puts("ERROR: Versioneer config file already exists.")
96
+ exit(1)
97
+ end
98
+ File.open(init_file, 'w') do |file|
99
+ puts "Generating config..."
100
+ [
101
+ "# Versioneer Project Configuration",
102
+ "# https://git.io/versioneer-help",
103
+ "",
104
+ "type: #{Versioneer::Config::DEFAULT_TYPE}",
105
+ "bump_segment: #{v.bump_segment}",
106
+ "prereleases:",
107
+ " - alpha",
108
+ " - beta",
109
+ " - rc",
110
+ ].each do |line|
111
+ file.write(line + "\n")
112
+ end
113
+ puts "+ #{File.basename(init_file)}"
114
+ end
115
+ else
116
+ puts opparser.help
117
+ end
data/changelog.rake ADDED
@@ -0,0 +1,128 @@
1
+ namespace :changelog do
2
+
3
+ ### Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ # How to determine current project version, prompting user if nil result
6
+ # - Versioneer may be helpful: `gem install versioneer` - Docs: https://git.io/versioneer
7
+ # - Or you can try accessing your app/lib version constant
8
+ version_lambda = lambda { `versioneer print`.chomp }
9
+ # Changelog file to read/write
10
+ changelog_file = 'CHANGELOG.md'
11
+ # List of shell commands to try to determine previously released commit hash...
12
+ # - the first non-empty command result is accepted
13
+ # - changelog will be built from this reference to current HEAD
14
+ changelog_ref_sources = ['git describe --abbrev=0 --tags', 'git rev-list HEAD | tail -n 1']
15
+ # Filter and format commit subjects for the changelog
16
+ changelog_line_filter = lambda do |line|
17
+ case line
18
+ when /release|merge/i
19
+ nil
20
+ when /bug|fix/i
21
+ '* __`!!!`__ ' + line
22
+ when /add|support|ability/i
23
+ '* __`NEW`__ ' + line
24
+ when /remove|deprecate/i
25
+ '* __`-!-`__ ' + line
26
+ else
27
+ '* __`~~~`__ ' + line
28
+ end
29
+ end
30
+
31
+ ### Tasks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32
+
33
+ desc 'Generate changelog for current version (from last tagged release)'
34
+ task :update do
35
+ puts '== CHANGELOG:UPDATE =='
36
+ puts '** What new version are you documenting?'
37
+ current_version = version_lambda.call
38
+ if current_version and not current_version.empty?
39
+ current_version = ::Gem::Version.new(current_version).release.to_s
40
+ puts 'Leave blank to use the suggestion, or enter a version number:'
41
+ print "Version[ #{current_version} ] ?? "
42
+ else
43
+ puts 'Please enter a version number:'
44
+ print 'Version?? '
45
+ end
46
+ input = STDIN.gets.strip
47
+ if input.empty? and not current_version
48
+ raise 'ERROR: You did not enter a version.'
49
+ elsif not input.empty?
50
+ current_version = input
51
+ end
52
+
53
+ changelog_ref = ''
54
+ changelog_ref_sources.each do |cmd|
55
+ changelog_ref = %x{#{cmd} 2> /dev/null}.chomp
56
+ break unless changelog_ref.empty?
57
+ end
58
+ raise 'Failed to determine base git reference for changelog.' if changelog_ref.empty?
59
+
60
+ header = ''
61
+ footer = ''
62
+ if File.file?(changelog_file)
63
+ File.open(changelog_file, 'r') do |f|
64
+ in_header = true
65
+ f.each_line do |line|
66
+ if !in_header or line.match(/^##/)
67
+ in_header = false
68
+ footer << line
69
+ else
70
+ header << line
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ content = "### #{current_version} (#{DateTime.now.strftime('%Y-%m-%d')})\n\n"
77
+ gitlog = %x{git log #{changelog_ref}...HEAD --pretty=format:'%s' --reverse}
78
+ raise gitlog.to_s if $?.exitstatus > 0
79
+ gitlog.chomp.split("\n").each do |line|
80
+ line = changelog_line_filter.call(line.chomp)
81
+ content << line + "\n" if line
82
+ end
83
+ content << "\n\n"
84
+
85
+ puts "** Writing to #{changelog_file}"
86
+ puts
87
+ puts content.chomp
88
+ File.write(changelog_file, header + content + footer)
89
+ puts '== ALL DONE =='
90
+ end
91
+
92
+ desc 'Print changelog to console'
93
+ task :print do
94
+ if File.file?(changelog_file)
95
+ File.open(changelog_file, 'r') do |f|
96
+ f.each_line do |line|
97
+ puts line
98
+ end
99
+ end
100
+ else
101
+ STDERR.puts("Sorry, #{changelog_file} does not exist.")
102
+ STDERR.puts("Use `rake changelog:update` to start a new file.")
103
+ end
104
+ end
105
+
106
+ ### Rake Template Author + Updates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107
+ #
108
+ # 0101010
109
+ # 0010011
110
+ # 110101
111
+ # 0011
112
+ # __ __ ___ __ __ __ ___ 0100010
113
+ # / ` |__| /\ |\ | / _` |__ | / \ / _` |__) /\ |__/ |__ 1010 0010101000001
114
+ # \__, | | /~~\ | \| \__> |___ |___ \__/ \__> .| \ /~~\ | \ |___ 010101110100111101010010
115
+ # 01 0011000100
116
+ # 2017.01.01 from
117
+ # 0100
118
+ # 01001001
119
+ # 0100111001 000001010001110
120
+ # 101 0010010000010100100101
121
+ # 00111 0010011110100011001010
122
+ # 0110 10000010100111001000100
123
+ #
124
+ # github.com/binarybabel
125
+ #
126
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127
+
128
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'helpers'
2
+
3
+ module Versioneer
4
+ class Bypass < Repo
5
+ H = Helpers
6
+
7
+ def initialize(file_within_repo, options=nil)
8
+ raise InvalidRepoError if options[:invalid]
9
+ super
10
+ @commits_since_release = 0
11
+ @filesystem_dirty = false
12
+ end
13
+
14
+ def release
15
+ @release || super
16
+ end
17
+
18
+ def release=(v)
19
+ v = ::Gem::Version.new(v) if v.is_a? String
20
+ @release = v
21
+ end
22
+
23
+ attr_accessor :commits_since_release
24
+
25
+ def filesystem_dirty?
26
+ @filesystem_dirty
27
+ end
28
+
29
+ def filesystem_dirty=(v)
30
+ @filesystem_dirty = v
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,105 @@
1
+ require_relative 'helpers'
2
+ require_relative 'runtime_error'
3
+ require_relative 'missing_config_error'
4
+ require 'yaml'
5
+
6
+ module Versioneer
7
+ class Config
8
+ DEFAULT_TYPE = 'Git'
9
+ DEFAULT_FILE = '.versioneer.yml'
10
+ DEFAULT_LOCK = 'version.lock'
11
+
12
+ def initialize(base_dir_or_config_file, repo_options=nil)
13
+ base_dir_or_config_file = base_dir_or_config_file.to_s
14
+
15
+ if Dir.exist?(base_dir_or_config_file)
16
+ @config_base = base_dir_or_config_file
17
+ @config_file = File.join(base_dir_or_config_file, DEFAULT_FILE)
18
+ unless File.exist?(@config_file)
19
+ raise MissingConfigError, "#{self.class.name} file does not exist. (#{@config_file})"
20
+ end
21
+ elsif File.exist?(base_dir_or_config_file)
22
+ @config_file = base_dir_or_config_file
23
+ @config_base = File.dirname(@config_file)
24
+ else
25
+ raise RuntimeError, "#{self.class.name} file does not exist. (#{base_dir_or_config_file})"
26
+ end
27
+
28
+ params = YAML.load_file(@config_file)
29
+ raise RuntimeError, "Failed to parse YAML file. (#{@config_file})" unless params
30
+ params = params.inject({}) { |x, (k, v)| x[k.to_sym] = v; x } # symbolize keys
31
+
32
+ @lock_file = File.join(@config_base, params.delete(:lock_file) || DEFAULT_LOCK)
33
+ @repo = nil
34
+ @repo_type = (params.delete(:type) || DEFAULT_TYPE).capitalize.to_sym
35
+ @repo_options = Hash.new().merge(repo_options.to_h).merge(params.to_h)
36
+ end
37
+
38
+ attr_reader :config_file, :lock_file
39
+
40
+ def repo
41
+ return @repo unless @repo.nil?
42
+ @repo = case locked?
43
+ when true
44
+ Bypass.new(@config_base, release: version)
45
+ else
46
+ unless ::Versioneer.const_defined? @repo_type
47
+ raise RuntimeError, "Versioneer::#{@repo_type} is an unknown VCS type."
48
+ end
49
+
50
+ repo_class = ::Versioneer.const_get(@repo_type)
51
+ unless repo_class.superclass == ::Versioneer::Repo
52
+ raise RuntimeError, "Versioneer::#{@repo_type} is an invalid VCS type."
53
+ end
54
+
55
+ @repo = repo_class.new(@config_base, @repo_options)
56
+ end
57
+ end
58
+
59
+ def locked?
60
+ File.exist?(@lock_file)
61
+ end
62
+
63
+ def lock!(version=nil)
64
+ @repo = nil
65
+ version ||= repo.to_s
66
+ raise RuntimeError, 'Cannot lock. Version neither given nor detected.' if version.to_s.empty?
67
+ File.open(@lock_file, 'w') do |file|
68
+ file.write(version)
69
+ end
70
+ end
71
+
72
+ def unlock!
73
+ @repo = nil
74
+ if File.exist?(@lock_file)
75
+ File.delete(@lock_file)
76
+ end
77
+ end
78
+
79
+ def version
80
+ if File.exist?(@lock_file)
81
+ version = File.read(@lock_file)
82
+ ::Gem::Version.new(version)
83
+ else
84
+ super
85
+ end
86
+ end
87
+
88
+ def to_s
89
+ version.to_s
90
+ end
91
+
92
+ def method_missing(name, *args, &block)
93
+ if repo.respond_to? name
94
+ repo.send(name, *args, &block)
95
+ else
96
+ super
97
+ end
98
+ end
99
+
100
+ def respond_to?(name)
101
+ return true if repo.respond_to? name
102
+ super
103
+ end
104
+ end
105
+ end
@@ -1,3 +1,7 @@
1
1
  module Versioneer
2
- GEM_VERSION = '0.1.0'
2
+ begin
3
+ GEM_VERSION = Config.new(::File.expand_path('../../../.versioneer.yml', __FILE__))
4
+ rescue
5
+ GEM_VERSION = '0.0.0'
6
+ end
3
7
  end
@@ -1,7 +1,9 @@
1
1
  require_relative 'helpers'
2
2
 
3
3
  module Versioneer
4
- class Git < Base
4
+ class Git < Repo
5
+ H = Helpers
6
+
5
7
  def initialize(file_within_repo, options=nil)
6
8
  super
7
9
  unless file_within_repo.is_a? Dir and Dir.join('.git').exist?
@@ -31,7 +33,8 @@ module Versioneer
31
33
  end
32
34
 
33
35
  def filesystem_dirty?
34
- H.lines? `git status -s`
36
+ system 'git diff-index --quiet HEAD --'
37
+ $?.exitstatus != 0
35
38
  end
36
39
 
37
40
  protected
@@ -44,12 +47,23 @@ module Versioneer
44
47
  ref
45
48
  else
46
49
  # Iterate through tags in date order for first match.
47
- `git tag --sort=taggerdate`.split("\n").each do |tag|
48
- tag.chomp!
49
- if tag.match(release_pattern)
50
- return tag
50
+ if H.windows?
51
+ `git tag --sort=-*creatordate`.split("\n").each do |tag|
52
+ if tag.match(release_pattern)
53
+ return tag
54
+ end
55
+ end
56
+ else
57
+ `git for-each-ref --sort='-*creatordate' --format '%(objecttype)=%(refname)'`.split("\n").each do |line|
58
+ type, ref = line.chomp.split('=')
59
+ ref_name = ref.split('/').last
60
+
61
+ if type == 'tag' and ref_name.match(release_pattern)
62
+ return ref_name
63
+ end
51
64
  end
52
65
  end
66
+ nil
53
67
  end
54
68
  end
55
69
 
@@ -59,9 +73,5 @@ module Versioneer
59
73
  return nil if ref.empty?
60
74
  ref
61
75
  end
62
-
63
- private
64
-
65
- H = Helpers
66
76
  end
67
77
  end
@@ -1,5 +1,7 @@
1
+ require_relative 'runtime_error'
2
+
1
3
  module Versioneer
2
- class InvalidRepoError < ArgumentError
4
+ class InvalidRepoError < RuntimeError
3
5
 
4
6
  end
5
7
  end
@@ -0,0 +1,7 @@
1
+ require_relative 'runtime_error'
2
+
3
+ module Versioneer
4
+ class MissingConfigError < RuntimeError
5
+
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  module Versioneer
2
- class Base
2
+ class Repo
3
3
  def initialize(file_within_repo, options=nil)
4
4
  @file = file_within_repo
5
5
  @directory = File.dirname(@file)
@@ -7,7 +7,7 @@ module Versioneer
7
7
 
8
8
  @bump_segment = :minor
9
9
  @prereleases = %w(alpha beta rc)
10
- @release_pattern = /^v?([0-9\.]+$)/
10
+ @release_pattern = /\Av?([0-9\.]+\z)/
11
11
  @starting_release = Gem::Version.new('0.0')
12
12
 
13
13
  if options.is_a? Hash
@@ -18,11 +18,16 @@ module Versioneer
18
18
  end
19
19
 
20
20
  attr_accessor :starting_release,
21
- :bump_segment,
22
21
  :prereleases
23
22
 
23
+ attr_reader :bump_segment
24
+
25
+ def bump_segment=(v)
26
+ @bump_segment = v.to_sym
27
+ end
28
+
24
29
  def environment
25
- @environment || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['ENV'] || 'development'
30
+ @environment || ENV['VERSIONEER_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['ENV'] || 'development'
26
31
  end
27
32
 
28
33
  attr_writer :environment
@@ -0,0 +1,5 @@
1
+ module Versioneer
2
+ class RuntimeError < ::RuntimeError
3
+
4
+ end
5
+ end
data/lib/versioneer.rb CHANGED
@@ -1,7 +1,11 @@
1
- require 'versioneer/gem_version'
2
- require 'versioneer/invalid_repo_error'
3
- require 'versioneer/base'
4
- require 'versioneer/git'
1
+ load 'versioneer/runtime_error.rb'
2
+ load 'versioneer/invalid_repo_error.rb'
3
+ load 'versioneer/missing_config_error.rb'
4
+ load 'versioneer/repo.rb'
5
+ load 'versioneer/config.rb'
6
+ load 'versioneer/bypass.rb'
7
+ load 'versioneer/git.rb'
8
+ load 'versioneer/gem_version.rb'
5
9
 
6
10
  module Versioneer
7
11
  end
data/version.lock ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/versioneer.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'versioneer/gem_version'
4
+ require 'versioneer'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'versioneer'
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
17
  f.match(%r{^(test|spec|features)/})
18
18
  end
19
+ spec.files += ['version.lock']
19
20
  spec.bindir = 'bin'
20
21
  spec.executables = ['versioneer']
21
22
  spec.require_paths = ['lib']
@@ -23,4 +24,5 @@ Gem::Specification.new do |spec|
23
24
  spec.add_development_dependency 'bundler', '~> 1.13'
24
25
  spec.add_development_dependency 'rake', '~> 10.0'
25
26
  spec.add_development_dependency 'minitest', '~> 5.0'
27
+ spec.add_development_dependency 'pry', '~> 0'
26
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: versioneer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BinaryBabel OSS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-16 00:00:00.000000000 Z
11
+ date: 2017-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description:
56
70
  email:
57
71
  - oss@binarybabel.net
@@ -62,18 +76,26 @@ extra_rdoc_files: []
62
76
  files:
63
77
  - ".gitignore"
64
78
  - ".travis.yml"
79
+ - ".versioneer.yml"
80
+ - CHANGELOG.md
65
81
  - Gemfile
66
82
  - LICENSE.txt
67
83
  - README.md
68
84
  - Rakefile
69
85
  - appveyor.yml
70
86
  - bin/versioneer
87
+ - changelog.rake
71
88
  - lib/versioneer.rb
72
- - lib/versioneer/base.rb
89
+ - lib/versioneer/bypass.rb
90
+ - lib/versioneer/config.rb
73
91
  - lib/versioneer/gem_version.rb
74
92
  - lib/versioneer/git.rb
75
93
  - lib/versioneer/helpers.rb
76
94
  - lib/versioneer/invalid_repo_error.rb
95
+ - lib/versioneer/missing_config_error.rb
96
+ - lib/versioneer/repo.rb
97
+ - lib/versioneer/runtime_error.rb
98
+ - version.lock
77
99
  - versioneer.gemspec
78
100
  homepage: https://github.com/binarybabel/gem-versioneer
79
101
  licenses: