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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd7b4f97607250bc93704a5e07b8090bd03c7781
4
- data.tar.gz: 470da6b3c6d68faf3b188c60a72eac40ccf02b42
3
+ metadata.gz: cfa3cbc993f8e206969b4407f50f9a2d83b3b14e
4
+ data.tar.gz: cd5a95dc30d2eb8d314a26d804064bf48d7f09d1
5
5
  SHA512:
6
- metadata.gz: e19e62c9f6f0adbe977f03b8801e4343a04cb7270934fd1e351c5114f239bb270eab91bd1ee4091d023da63ec38b53864946197101f9f7a4886d115d21a291b7
7
- data.tar.gz: 58ccd1508c29127c47594120c00db96cddba4d33d2394a6ecbb85e5a121295f2a4812cf52eb0f778b9ad4005ebdbcbfd60892751d390ddd721b465e6f5af2202
6
+ metadata.gz: f611f283b75cc6026462bd527526610ba75219b262aff8d8c2bd5e160aebef106e5291254456cb82dceb2216e355d21e7fb21e2cc5c7febc74249aa6f30a9e85
7
+ data.tar.gz: 9a40fb07d455d68be5f258a86f95bb2f2bcd40cffe8f8277a0338acf02152f52aaa967fbeb216289e3d6ca9b1abeaa8679d955f4ca5171dc9c4f16f291566e9c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- autoversion (0.5.2)
4
+ autoversion (0.5.4)
5
5
  git (= 1.2.5)
6
6
  semantic (= 1.1.0)
7
7
  thor (= 0.17.0)
@@ -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
@@ -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
- @versioner.increment! type, simulate
55
- say "Version #{outcome} to #{@versioner.current_version}", simulate ? :cyan : :green
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
@@ -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 dir_is_clean?
25
- # sum = @repo.status.untracked.length + @repo.status.added.length + @repo.status.changed.length + @repo.status.deleted.length
26
- # if sum > 0
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
- # sum == 0
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
- # Disabled for now. ruby-git doesn't seem to read the .gitignore files, so the untracked count is completely useless.
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
- raise NotOnStableBranch if versionType == :major && !on_stable_branch?
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
+
@@ -1,3 +1,3 @@
1
1
  module Autoversion
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.4'
3
3
  end
@@ -31,6 +31,8 @@ module Autoversion
31
31
 
32
32
  process_before type, @current, nextVersion
33
33
  unless simulate
34
+ @gitter.ensure_valid_branch! type
35
+
34
36
  write_version @current, nextVersion
35
37
  @current = nextVersion
36
38
  @gitter.commit! type, @current.to_s
@@ -3,63 +3,157 @@ require 'git'
3
3
 
4
4
  describe Autoversion::Gitter do
5
5
 
6
- before(:each) do
7
- @gitter_path = File.join(File.dirname(__FILE__), 'tmp', 'gitter')
6
+ before { Git.stub(:open).with(gitter_path).and_return(repo) }
8
7
 
9
- if File.directory? @gitter_path
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
- system("echo 'test' > #{@gitter_path}/test.txt")
22
- system("cd #{@gitter_path} && git add .")
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
- @gitter_repo = Git.open(@gitter_path)
13
+ subject(:gitter) do
14
+ ::Autoversion::Gitter.new(gitter_path, {
15
+ :actions => [:commit],
16
+ :stable_branch => stable_branch})
26
17
  end
27
18
 
28
- it 'should detect stable branch' do
29
- @gitter = ::Autoversion::Gitter.new(@gitter_path, {
30
- :stable_branch => 'master'})
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
- @gitter_repo.branch('feature1').checkout
33
- @gitter_repo.branch('feature2').checkout
34
- @gitter.on_stable_branch?.should eq(false)
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
- @gitter_repo.branch('master').checkout
37
- @gitter.on_stable_branch?.should eq(true)
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
- it 'should be able to commit and tag a new version' do
41
- @gitter = ::Autoversion::Gitter.new(@gitter_path, {
42
- :actions => [:commit, :tag],
43
- :stable_branch => 'master'})
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
- #Fake version file
46
- system("touch #{@gitter_path}/version.rb")
49
+ possible_dirtiness.each do |dirty|
50
+ repo.stub_chain(:status, :"#{dirty}").and_return({})
51
+ end
52
+ end
47
53
 
48
- @gitter.commit! :major, 'v1.2.3'
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
- @gitter_repo.log.first.message.should == "v1.2.3"
51
- @gitter_repo.tags.first.name.should == "v1.2.3"
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
- it 'should should detect cleanliness' do
55
- @gitter = ::Autoversion::Gitter.new(@gitter_path, {
56
- :stable_branch => 'master'})
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
- @gitter.dir_is_clean?.should eq(true)
59
-
60
- # Disabled for now since ruby-git does not read .gitignore files
61
- #system("touch #{@gitter_path}/test2.txt")
62
- #@gitter.dir_is_clean?.should eq(false)
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
- end
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
+
@@ -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
@@ -3,7 +3,22 @@ require 'spec_helper'
3
3
  describe Autoversion::Versioner do
4
4
 
5
5
  before(:each) do
6
- @versioner = Autoversion::Versioner.new Versionfiles::VALID_BASIC
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.2
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.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