autoversion 0.5.2 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/Versionfile +0 -16
- data/lib/autoversion/cli.rb +9 -2
- data/lib/autoversion/gitter.rb +22 -15
- data/lib/autoversion/version.rb +1 -1
- data/lib/autoversion/versioner.rb +2 -0
- data/spec/gitter_spec.rb +137 -43
- data/spec/spec_helper.rb +1 -0
- data/spec/versioner_spec.rb +16 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfa3cbc993f8e206969b4407f50f9a2d83b3b14e
|
4
|
+
data.tar.gz: cd5a95dc30d2eb8d314a26d804064bf48d7f09d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f611f283b75cc6026462bd527526610ba75219b262aff8d8c2bd5e160aebef106e5291254456cb82dceb2216e355d21e7fb21e2cc5c7febc74249aa6f30a9e85
|
7
|
+
data.tar.gz: 9a40fb07d455d68be5f258a86f95bb2f2bcd40cffe8f8277a0338acf02152f52aaa967fbeb216289e3d6ca9b1abeaa8679d955f4ca5171dc9c4f16f291566e9c
|
data/Gemfile.lock
CHANGED
data/Versionfile
CHANGED
@@ -14,19 +14,3 @@ write_version do |currentVersion, nextVersion|
|
|
14
14
|
file.write contents
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
18
|
-
before :version do |currentVersion, nextVersion|
|
19
|
-
puts "Before version #{currentVersion} => #{nextVersion}"
|
20
|
-
end
|
21
|
-
|
22
|
-
after :version do |currentVersion|
|
23
|
-
puts "After version #{currentVersion}"
|
24
|
-
end
|
25
|
-
|
26
|
-
before :patch do |currentVersion, nextVersion|
|
27
|
-
puts "Before patch #{currentVersion} => #{nextVersion}"
|
28
|
-
end
|
29
|
-
|
30
|
-
after :patch do |currentVersion|
|
31
|
-
puts "After patch #{currentVersion}"
|
32
|
-
end
|
data/lib/autoversion/cli.rb
CHANGED
@@ -51,8 +51,15 @@ module Autoversion
|
|
51
51
|
def increment_version type, simulate=false, force=false
|
52
52
|
if force or yes? "Do you want to increment #{type.to_s} to #{@versioner.next_version(type)}? (y/N)"
|
53
53
|
outcome = simulate ? "would change" : "changed"
|
54
|
-
|
55
|
-
|
54
|
+
|
55
|
+
begin
|
56
|
+
@versioner.increment! type, simulate
|
57
|
+
say "Version #{outcome} to #{@versioner.current_version}", simulate ? :cyan : :green
|
58
|
+
rescue Autoversion::Gitter::DirtyStaging
|
59
|
+
say "Autoversion error: The git workspace is in a dirty state.", :red
|
60
|
+
rescue Autoversion::Gitter::NotOnStableBranch => e
|
61
|
+
say "Autoversion error: Major version increments can only happen on your configured stable branch (#{e.message}).", :red
|
62
|
+
end
|
56
63
|
else
|
57
64
|
say "No changes were made."
|
58
65
|
end
|
data/lib/autoversion/gitter.rb
CHANGED
@@ -7,6 +7,9 @@ module Autoversion
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class NotOnStableBranch < Exception
|
10
|
+
def initialize(msg)
|
11
|
+
super(msg)
|
12
|
+
end
|
10
13
|
end
|
11
14
|
|
12
15
|
def initialize path, config
|
@@ -21,19 +24,17 @@ module Autoversion
|
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
# puts "untracked: #{@repo.status.untracked}"
|
28
|
-
# puts "added: #{@repo.status.added}"
|
29
|
-
# puts "changed: #{@repo.status.changed}"
|
30
|
-
# puts "deleted: #{@repo.status.deleted}"
|
31
|
-
# end
|
27
|
+
def ensure_valid_branch! versionType
|
28
|
+
raise NotOnStableBranch.new(@config[:stable_branch]) if versionType == :major && !on_stable_branch?
|
29
|
+
end
|
32
30
|
|
33
|
-
|
31
|
+
def dir_is_clean?
|
32
|
+
sum = gitstatus_untracked_workaround.length +
|
33
|
+
@repo.status.added.length +
|
34
|
+
@repo.status.changed.length +
|
35
|
+
@repo.status.deleted.length
|
34
36
|
|
35
|
-
|
36
|
-
true
|
37
|
+
sum == 0
|
37
38
|
end
|
38
39
|
|
39
40
|
def on_stable_branch?
|
@@ -41,9 +42,8 @@ module Autoversion
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def commit! versionType, currentVersion
|
44
|
-
return false unless @config[:actions].include?(:commit)
|
45
|
-
|
46
|
-
|
45
|
+
return false unless @config[:actions].include?(:commit)
|
46
|
+
|
47
47
|
write_commit currentVersion
|
48
48
|
write_tag currentVersion if @config[:actions].include?(:tag)
|
49
49
|
end
|
@@ -59,5 +59,12 @@ module Autoversion
|
|
59
59
|
@repo.add_tag "#{@config[:prefix]}#{version}"
|
60
60
|
end
|
61
61
|
|
62
|
+
def gitstatus_untracked_workaround
|
63
|
+
git_cmd = "git --work-tree=#{@repo.dir} --git-dir=#{@repo.dir}/.git " +
|
64
|
+
"ls-files -o -z --full-name --exclude-standard"
|
65
|
+
`#{git_cmd}`.split("\x0")
|
66
|
+
end
|
67
|
+
|
62
68
|
end
|
63
|
-
end
|
69
|
+
end
|
70
|
+
|
data/lib/autoversion/version.rb
CHANGED
data/spec/gitter_spec.rb
CHANGED
@@ -3,63 +3,157 @@ require 'git'
|
|
3
3
|
|
4
4
|
describe Autoversion::Gitter do
|
5
5
|
|
6
|
-
before(:
|
7
|
-
@gitter_path = File.join(File.dirname(__FILE__), 'tmp', 'gitter')
|
6
|
+
before { Git.stub(:open).with(gitter_path).and_return(repo) }
|
8
7
|
|
9
|
-
|
10
|
-
FileUtils.rm_rf @gitter_path
|
11
|
-
end
|
12
|
-
|
13
|
-
system("mkdir #{@gitter_path}")
|
14
|
-
system("tar -xf spec/fixtures/bare_repo.tar --strip 1 -C #{@gitter_path}")
|
15
|
-
|
16
|
-
# Fix to make specs run on travis-ci which has no
|
17
|
-
# default git user config.
|
18
|
-
# system("cd #{@gitter_path} && git config user.email 'you@example.com'")
|
19
|
-
# system("cd #{@gitter_path} && git config user.name 'Your Name'")
|
8
|
+
let(:repo) { double() }
|
20
9
|
|
21
|
-
|
22
|
-
|
23
|
-
system("cd #{@gitter_path} && git commit -m 'test'")
|
10
|
+
let(:gitter_path) { File.join(File.dirname(__FILE__), 'tmp', 'gitter') }
|
11
|
+
let(:stable_branch) { 'master' }
|
24
12
|
|
25
|
-
|
13
|
+
subject(:gitter) do
|
14
|
+
::Autoversion::Gitter.new(gitter_path, {
|
15
|
+
:actions => [:commit],
|
16
|
+
:stable_branch => stable_branch})
|
26
17
|
end
|
27
18
|
|
28
|
-
|
29
|
-
|
30
|
-
:
|
19
|
+
shared_context 'when on "whatever" branch' do
|
20
|
+
before do
|
21
|
+
repo.stub(:current_branch).and_return('whatever')
|
22
|
+
end
|
23
|
+
end
|
31
24
|
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
shared_context 'when on stable branch' do
|
26
|
+
before do
|
27
|
+
repo.stub(:current_branch).and_return(stable_branch)
|
28
|
+
end
|
29
|
+
end
|
35
30
|
|
36
|
-
|
37
|
-
|
31
|
+
describe '#ensure_cleanliness!' do
|
32
|
+
context 'when config actions include "commit" && #dir_is_clean? is false' do
|
33
|
+
before do
|
34
|
+
gitter.stub(:dir_is_clean?).and_return(false)
|
35
|
+
end
|
36
|
+
it 'raises a DirtyStaging Exception' do
|
37
|
+
expect { gitter.ensure_cleanliness! }.to(
|
38
|
+
raise_error ::Autoversion::Gitter::DirtyStaging)
|
39
|
+
end
|
40
|
+
end
|
38
41
|
end
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
possible_dirtiness = %w[untracked changed added deleted]
|
44
|
+
describe '#dir_is_clean?' do
|
45
|
+
before do
|
46
|
+
# untracked workaround
|
47
|
+
gitter.stub(:gitstatus_untracked_workaround).and_return([])
|
44
48
|
|
45
|
-
|
46
|
-
|
49
|
+
possible_dirtiness.each do |dirty|
|
50
|
+
repo.stub_chain(:status, :"#{dirty}").and_return({})
|
51
|
+
end
|
52
|
+
end
|
47
53
|
|
48
|
-
|
54
|
+
context "when there aren't dirty files" do
|
55
|
+
it 'returns true' do
|
56
|
+
expect(gitter.dir_is_clean?).to be_true
|
57
|
+
end
|
58
|
+
end
|
49
59
|
|
50
|
-
|
51
|
-
|
60
|
+
possible_dirtiness.each do |dirty|
|
61
|
+
context "when there are #{dirty} files" do
|
62
|
+
before do
|
63
|
+
# untracked workaround
|
64
|
+
if dirty == 'untracked'
|
65
|
+
gitter.stub(:gitstatus_untracked_workaround).and_return(
|
66
|
+
["untracked_file.rb"])
|
67
|
+
end
|
68
|
+
|
69
|
+
# e.g.: repo.status.changed => {"changed_file.rb" => nil}
|
70
|
+
repo.stub_chain(:status, :"#{dirty}").and_return(
|
71
|
+
{"#{dirty}_file.rb" => nil})
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns false' do
|
75
|
+
expect(gitter.dir_is_clean?).to be_false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
52
79
|
end
|
53
80
|
|
54
|
-
|
55
|
-
|
56
|
-
|
81
|
+
describe '#on_stable_branch?' do
|
82
|
+
context 'when the config stable branch differs with the current branch' do
|
83
|
+
include_context 'when on "whatever" branch'
|
84
|
+
|
85
|
+
it 'returns false' do
|
86
|
+
expect(gitter.on_stable_branch?).to be_false
|
87
|
+
end
|
88
|
+
end
|
57
89
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
90
|
+
context 'when the config stable branch equals the current branch' do
|
91
|
+
include_context 'when on stable branch'
|
92
|
+
|
93
|
+
it 'returns true' do
|
94
|
+
expect(gitter.on_stable_branch?).to be_true
|
95
|
+
end
|
96
|
+
end
|
63
97
|
end
|
64
98
|
|
65
|
-
|
99
|
+
describe '#commit!' do
|
100
|
+
let(:version) { 'v1.2.3' }
|
101
|
+
let(:invoke) {
|
102
|
+
gitter.commit! :major, version
|
103
|
+
}
|
104
|
+
|
105
|
+
context 'when cannot commit' do
|
106
|
+
context 'when config actions do not include "commit"' do
|
107
|
+
subject(:gitter) do
|
108
|
+
::Autoversion::Gitter.new(gitter_path, {
|
109
|
+
:actions => [],
|
110
|
+
:stable_branch => stable_branch})
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'returns false' do
|
114
|
+
expect(invoke).to be_false
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when versionType == :major && #on_stable_branch? == false' do
|
119
|
+
include_context 'when on "whatever" branch'
|
120
|
+
|
121
|
+
it 'raises NotOnStableBranch Exception' do
|
122
|
+
expect {
|
123
|
+
gitter.ensure_valid_branch! :major
|
124
|
+
invoke
|
125
|
+
}.to(
|
126
|
+
raise_error ::Autoversion::Gitter::NotOnStableBranch)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end #context cannot commit
|
130
|
+
|
131
|
+
context 'when can commit' do
|
132
|
+
include_context 'when on stable branch'
|
133
|
+
|
134
|
+
before do
|
135
|
+
repo.should_receive(:add).with('.').ordered
|
136
|
+
repo.should_receive(:commit).with(version).ordered
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'calls #add and #commit on the repo (Git) object' do
|
140
|
+
invoke
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'when config actions include "tag"' do
|
144
|
+
subject(:gitter) do
|
145
|
+
::Autoversion::Gitter.new(gitter_path, {
|
146
|
+
:actions => [:commit, :tag],
|
147
|
+
:stable_branch => stable_branch})
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'also calls #add_tag on the repo (Git) object' do
|
151
|
+
repo.should_receive(:add_tag).with(version).ordered
|
152
|
+
invoke
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end #context can commit
|
156
|
+
end #commit!
|
157
|
+
|
158
|
+
end
|
159
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -9,5 +9,6 @@ RSpec.configure do |config|
|
|
9
9
|
config.after(:all) do
|
10
10
|
FileUtils.rm_rf File.join(File.dirname(__FILE__), 'tmp', 'gitter')
|
11
11
|
FileUtils.rm_rf File.join(File.dirname(__FILE__), 'tmp', 'cli')
|
12
|
+
FileUtils.rm_rf File.join(File.dirname(__FILE__), 'tmp', 'versioner')
|
12
13
|
end
|
13
14
|
end
|
data/spec/versioner_spec.rb
CHANGED
@@ -3,7 +3,22 @@ require 'spec_helper'
|
|
3
3
|
describe Autoversion::Versioner do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@
|
6
|
+
@path = File.join(File.dirname(__FILE__), 'tmp', 'versioner')
|
7
|
+
|
8
|
+
if File.directory? @path
|
9
|
+
FileUtils.rm_rf @path
|
10
|
+
end
|
11
|
+
|
12
|
+
system("mkdir #{@path}")
|
13
|
+
system("tar -xf spec/fixtures/bare_repo.tar --strip 1 -C #{@path}")
|
14
|
+
|
15
|
+
system("echo '0.0.1' > #{@path}/version.txt")
|
16
|
+
system("cd #{@path} && git add .")
|
17
|
+
system("cd #{@path} && git commit -m 'first'")
|
18
|
+
|
19
|
+
@repo = Git.open(@path)
|
20
|
+
|
21
|
+
@versioner = Autoversion::Versioner.new Versionfiles::VALID_BASIC, @path
|
7
22
|
end
|
8
23
|
|
9
24
|
it "should be able to read the current version" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autoversion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Pettersson
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.0.
|
124
|
+
rubygems_version: 2.0.14
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: Automate your Semantic Versioning with git and hooks
|