src 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/src +7 -0
- data/lib/src/branch.rb +80 -0
- data/lib/src/cli.rb +48 -0
- data/lib/src/git/branch.rb +96 -0
- data/lib/src/git.rb +5 -0
- data/lib/src.rb +46 -0
- data/spec/lib/sc/branch_spec.rb +43 -0
- data/spec/lib/sc/cli_spec.rb +95 -0
- data/spec/lib/sc/git/branch_spec.rb +199 -0
- data/spec/lib/sc/git_spec.rb +10 -0
- data/spec/lib/sc_spec.rb +6 -0
- data/spec/spec_helper.rb +22 -0
- data/src.gemspec +22 -0
- data/version +1 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a5d818bb0a01bebb3dfec0adc34608e32fe79e84
|
4
|
+
data.tar.gz: 970da6fcc1f6c1eea4a850c1407ef4ac679a2deb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a9ed84c7cff5c216176fffff785184cf05335b1ef576b4c347d5772445dea3d076334c95ffd41bc260b17574fb442c25507306bfc6336df5a87d32325a9a9052
|
7
|
+
data.tar.gz: da3426bfe40ec3dd7e4c39b0b33e6f6ad6ed0bdf48b6fcdd8484d00929f689d386adaa0a699fa9bbfc5b8345e4754b4579b03605d5435544a4466d7388c1d029
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tyler Hartland
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Sc
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sc'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install sc
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/sc/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/src
ADDED
data/lib/src/branch.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'src'
|
2
|
+
require 'src/git/branch'
|
3
|
+
|
4
|
+
module SRC
|
5
|
+
class Branch
|
6
|
+
attr_reader :vc, :branches_from, :prefix, :merges_to, :semantic_level
|
7
|
+
|
8
|
+
def initialize(type)
|
9
|
+
opts = branches[type.to_sym] || {}
|
10
|
+
@vc = SRC::Git::Branch
|
11
|
+
@branches_from = vc.new(opts[:branches_from])
|
12
|
+
@prefix = opts[:prefix]
|
13
|
+
@merges_to = vc.new(opts[:merges_to])
|
14
|
+
@semantic_level = opts[:semantic_level]
|
15
|
+
end
|
16
|
+
|
17
|
+
def cut
|
18
|
+
if unmerged?
|
19
|
+
puts "An unmerged #{prefix} branch exists. Checking out."
|
20
|
+
latest.checkout
|
21
|
+
else
|
22
|
+
create_new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def merge
|
27
|
+
if unmerged?
|
28
|
+
if merges_to.subset_of?(latest)
|
29
|
+
merges_to.merge(latest)
|
30
|
+
else
|
31
|
+
puts "You must first merge #{merges_to} into #{latest}"
|
32
|
+
end
|
33
|
+
else
|
34
|
+
puts "No unmerged #{prefix} branch exists."
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def next_version
|
39
|
+
case semantic_level
|
40
|
+
when 'patch'
|
41
|
+
i = 2
|
42
|
+
when 'minor'
|
43
|
+
i = 1
|
44
|
+
when 'major'
|
45
|
+
i = 0
|
46
|
+
end
|
47
|
+
|
48
|
+
parts = branches_from.version.split('.')
|
49
|
+
((i + 1)..2).each { |j| parts[j] = '0' }
|
50
|
+
parts[i] = (parts[i].to_i + 1).to_s
|
51
|
+
|
52
|
+
parts.join('.')
|
53
|
+
end
|
54
|
+
|
55
|
+
def latest
|
56
|
+
@latest ||= vc.latest(prefix)
|
57
|
+
end
|
58
|
+
|
59
|
+
def unmerged?
|
60
|
+
latest && !latest.subset_of?(merges_to)
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def create_new
|
66
|
+
if branches_from == merges_to
|
67
|
+
new_branch = branches_from.branch_from("#{prefix}-#{next_version}")
|
68
|
+
new_branch.update_version_file(next_version)
|
69
|
+
else
|
70
|
+
new_branch = branches_from.branch_from("#{prefix}-#{branches_from.version}")
|
71
|
+
branches_from.update_version_file(next_version)
|
72
|
+
end
|
73
|
+
new_branch.checkout
|
74
|
+
end
|
75
|
+
|
76
|
+
def branches
|
77
|
+
SRC::BRANCHES
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/src/cli.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'src'
|
2
|
+
require 'src/branch'
|
3
|
+
|
4
|
+
module SRC
|
5
|
+
class CLI
|
6
|
+
def run
|
7
|
+
public_send(*options[:base_args])
|
8
|
+
end
|
9
|
+
|
10
|
+
def cut(*args)
|
11
|
+
SRC::Branch.new(args[0]).cut
|
12
|
+
end
|
13
|
+
|
14
|
+
def merge(*args)
|
15
|
+
SRC::Branch.new(args[0]).merge
|
16
|
+
end
|
17
|
+
|
18
|
+
def check(*args)
|
19
|
+
SRC.check
|
20
|
+
end
|
21
|
+
|
22
|
+
def options
|
23
|
+
@options ||= parse
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse
|
27
|
+
key = :base_args
|
28
|
+
argv.inject({}) do |args, val|
|
29
|
+
if val[0] == '-'
|
30
|
+
key = val.gsub('-', '').to_sym
|
31
|
+
args[key] ||= nil
|
32
|
+
elsif args[key]
|
33
|
+
args[key] = [args[key]] unless args[key].kind_of? Array
|
34
|
+
args[key] << val
|
35
|
+
else
|
36
|
+
args[key] = val
|
37
|
+
end
|
38
|
+
args
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def argv
|
45
|
+
ARGV
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module SRC::Git
|
2
|
+
class Branch
|
3
|
+
VERSION_FILE = 'version'
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def checked_out
|
9
|
+
new(`git rev-parse --abbrev-ref HEAD`.chomp)
|
10
|
+
end
|
11
|
+
|
12
|
+
def latest(prefix)
|
13
|
+
branch_name = `git branch`.split(/\s+/).select { |b| b =~ /\A#{prefix}/ }.max
|
14
|
+
new(branch_name) if branch_name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(name)
|
19
|
+
@name = name.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def exists?
|
23
|
+
system("git show-ref --verify --quiet refs/heads/'#{name}'")
|
24
|
+
end
|
25
|
+
|
26
|
+
def checkout
|
27
|
+
msg = `git checkout #{name} -q`
|
28
|
+
raise msg unless $?.success?
|
29
|
+
end
|
30
|
+
|
31
|
+
def checked_out?
|
32
|
+
self.class.checked_out == self
|
33
|
+
end
|
34
|
+
|
35
|
+
def subset_of?(other_branch)
|
36
|
+
`git rev-list #{other_branch}..#{name}`.chomp.length == 0
|
37
|
+
end
|
38
|
+
|
39
|
+
def version
|
40
|
+
`git show #{name}:#{version_file}`.chomp
|
41
|
+
end
|
42
|
+
|
43
|
+
def version_file
|
44
|
+
VERSION_FILE
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_version_file(new_version)
|
48
|
+
checked_out do
|
49
|
+
raise unless system("echo '#{new_version}' > #{version_file}")
|
50
|
+
self.add(version_file)
|
51
|
+
self.commit("version bumped to #{new_version}")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def commit(msg)
|
56
|
+
checked_out do
|
57
|
+
raise unless system("git commit -m '#{msg}' -q")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def add(filename)
|
62
|
+
checked_out do
|
63
|
+
raise unless system("git add #{filename}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def branch_from(new_branch)
|
68
|
+
checked_out do
|
69
|
+
raise unless system("git branch #{new_branch}")
|
70
|
+
end
|
71
|
+
self.class.new(new_branch)
|
72
|
+
end
|
73
|
+
|
74
|
+
def checked_out
|
75
|
+
previous_branch = self.class.checked_out
|
76
|
+
self.checkout
|
77
|
+
yield
|
78
|
+
ensure
|
79
|
+
previous_branch.checkout
|
80
|
+
end
|
81
|
+
|
82
|
+
def merge(other_branch)
|
83
|
+
checked_out do
|
84
|
+
raise unless system("git merge --no-ff #{other_branch}")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_s
|
89
|
+
name
|
90
|
+
end
|
91
|
+
|
92
|
+
def ==(other)
|
93
|
+
name == other.to_s
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/src/git.rb
ADDED
data/lib/src.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module SRC
|
2
|
+
BRANCHES = {
|
3
|
+
master: nil,
|
4
|
+
hotfix: {
|
5
|
+
branches_from: 'master',
|
6
|
+
merges_to: 'master',
|
7
|
+
prefix: 'hotfix',
|
8
|
+
semantic_level: 'patch'
|
9
|
+
},
|
10
|
+
release: {
|
11
|
+
branches_from: 'develop',
|
12
|
+
merges_to: 'master',
|
13
|
+
prefix: 'release',
|
14
|
+
semantic_level: 'minor'
|
15
|
+
},
|
16
|
+
develop: nil
|
17
|
+
}
|
18
|
+
|
19
|
+
def self.check
|
20
|
+
report = []
|
21
|
+
branches.each_with_index do |branch, i|
|
22
|
+
branches[(i + 1)..-1].each do |superset|
|
23
|
+
unless branch.subset_of?(superset)
|
24
|
+
report << "#{branch} should be merged into #{superset}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if report.empty?
|
30
|
+
puts 'No merges needed.'
|
31
|
+
else
|
32
|
+
puts report.join("\n")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.branches
|
37
|
+
@branches ||= BRANCHES.map do |k, v|
|
38
|
+
if v
|
39
|
+
sc_branch = SRC::Branch.new(k) if v
|
40
|
+
sc_branch.latest if sc_branch.unmerged?
|
41
|
+
else
|
42
|
+
SRC::Git::Branch.new(k)
|
43
|
+
end
|
44
|
+
end.compact
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'src/branch'
|
3
|
+
|
4
|
+
describe SRC::Branch do
|
5
|
+
describe '#next_version' do
|
6
|
+
let(:branch) { SRC::Branch.new('testing #next_version') }
|
7
|
+
|
8
|
+
before do
|
9
|
+
SRC::Branch.any_instance.stub(:branches).and_return(double(:'[]' => {}))
|
10
|
+
branch.stub(:branches_from).and_return(double(version: '1.2.3'))
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'a patch level change' do
|
14
|
+
before do
|
15
|
+
branch.stub(:semantic_level).and_return('patch')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'increments only the patch number' do
|
19
|
+
expect(branch.next_version).to eq '1.2.4'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'a minor level change' do
|
24
|
+
before do
|
25
|
+
branch.stub(:semantic_level).and_return('minor')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'increments the minor number and sets the patch to 0' do
|
29
|
+
expect(branch.next_version).to eq '1.3.0'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'a major level change' do
|
34
|
+
before do
|
35
|
+
branch.stub(:semantic_level).and_return('major')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'increments only the major number and sets others to 0' do
|
39
|
+
expect(branch.next_version).to eq '2.0.0'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'src/cli'
|
3
|
+
|
4
|
+
describe SRC::CLI do
|
5
|
+
let(:cli) { SRC::CLI.new }
|
6
|
+
let(:dub) { double }
|
7
|
+
|
8
|
+
describe '#run' do
|
9
|
+
before do
|
10
|
+
cli.stub(:argv).and_return(['function', 'more', 'base', 'args'])
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'calls a function corresponding to the first arg with remaining base args' do
|
14
|
+
expect(cli).to receive(:function).with('more', 'base', 'args')
|
15
|
+
cli.run
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#cut' do
|
20
|
+
before do
|
21
|
+
cli.stub(:options).and_return(base_args: [ 'cut', 'type' ])
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'passes args and options to a new instance of SRC::Cutter and calls cut' do
|
25
|
+
expect(SRC::Branch).to receive(:new).with('type').and_return(dub)
|
26
|
+
expect(dub).to receive(:cut)
|
27
|
+
cli.run
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#options' do
|
32
|
+
context 'argv has one base arg' do
|
33
|
+
before do
|
34
|
+
cli.stub(:argv).and_return(['arg'])
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'puts { :base_args => arg } into the options hash' do
|
38
|
+
expect(cli.options[:base_args]).to eq 'arg'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'argv has multiple base args' do
|
43
|
+
before do
|
44
|
+
cli.stub(:argv).and_return(['arg1', 'arg2'])
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'puts { :base_args => [ arg1, arg2 ] } into the options hash' do
|
48
|
+
expect(cli.options[:base_args]).to eq [ 'arg1', 'arg2' ]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'argv has an option with no following value' do
|
53
|
+
before do
|
54
|
+
cli.stub(:argv).and_return(['-option'])
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'puts { :option => nil } into the options hash' do
|
58
|
+
expect(cli.options.has_key?(:option)).to be_true
|
59
|
+
expect(cli.options[:option]).to eq nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'argv has an option with one following value' do
|
64
|
+
before do
|
65
|
+
cli.stub(:argv).and_return(['-option', 'value'])
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'puts { :option => "value" } into the options hash' do
|
69
|
+
expect(cli.options[:option]).to eq('value')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'argv has an option with several following values' do
|
74
|
+
before do
|
75
|
+
cli.stub(:argv).and_return(['-option', 'value1', 'value2', 'value3'])
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'puts { :option => ["value1", "value2", "value3"] } into the options hash' do
|
79
|
+
expect(cli.options[:option]).to eq(['value1', 'value2', 'value3'])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'argv has complex options and values with several following values' do
|
84
|
+
before do
|
85
|
+
cli.stub(:argv).and_return(['-option1', '-option2', 'value2-1', '-option3', 'value3-1', 'value3-2', 'value3-3'])
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'builds the options hash' do
|
89
|
+
expect(cli.options[:option1]).to eq(nil)
|
90
|
+
expect(cli.options[:option2]).to eq('value2-1')
|
91
|
+
expect(cli.options[:option3]).to eq(['value3-1', 'value3-2', 'value3-3'])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'src/git/branch'
|
3
|
+
|
4
|
+
def quiet
|
5
|
+
'-q'
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_file
|
9
|
+
@test_file ||= rand(10000).to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_branch
|
13
|
+
@test_branch ||= SRC::Git::Branch.new('test_branch')
|
14
|
+
end
|
15
|
+
|
16
|
+
def other_branch
|
17
|
+
@other_branch ||= SRC::Git::Branch.new('other_test_branch')
|
18
|
+
end
|
19
|
+
|
20
|
+
def klass
|
21
|
+
SRC::Git::Branch
|
22
|
+
end
|
23
|
+
|
24
|
+
describe SRC::Git::Branch do
|
25
|
+
before(:all) do
|
26
|
+
@reset_to = `git rev-parse HEAD`.chomp
|
27
|
+
@checkout_to = `git rev-parse --abbrev-ref HEAD`.chomp
|
28
|
+
run "touch #{test_file}"
|
29
|
+
run "git add . -A"
|
30
|
+
run "git commit -m 'temp commit' #{quiet}"
|
31
|
+
|
32
|
+
run "git branch #{quiet} #{test_branch}"
|
33
|
+
end
|
34
|
+
|
35
|
+
after(:all) do
|
36
|
+
run "git checkout #{@checkout_to} #{quiet}"
|
37
|
+
run "git reset #{quiet} #{@reset_to}"
|
38
|
+
run "rm #{test_file}"
|
39
|
+
|
40
|
+
run "git branch -D #{quiet} #{test_branch}"
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '.checked_out' do
|
44
|
+
it 'returns a branch object for the currently checked out branch' do
|
45
|
+
expect(klass.checked_out.to_s).to eq @checkout_to
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '.latest' do
|
50
|
+
context 'a branch of this type exists' do
|
51
|
+
before do
|
52
|
+
run "git branch #{quiet} git_branch_latest_test-1.2.3"
|
53
|
+
run "git branch #{quiet} git_branch_latest_test-1.2.4"
|
54
|
+
run "git checkout git_branch_latest_test-1.2.3 #{quiet}"
|
55
|
+
end
|
56
|
+
|
57
|
+
after do
|
58
|
+
run "git checkout #{@checkout_to} #{quiet}"
|
59
|
+
run "git branch -D #{quiet} git_branch_latest_test-1.2.3"
|
60
|
+
run "git branch -D #{quiet} git_branch_latest_test-1.2.4"
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns the latest branch for this prefix type' do
|
64
|
+
expect(klass.latest('git_branch_latest_test')).to eq 'git_branch_latest_test-1.2.4'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'a branch of this type does not exist' do
|
69
|
+
it 'returns nil' do
|
70
|
+
expect(klass.latest('git_branch_latest_test')).to be_nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#exists?' do
|
76
|
+
context 'the branch exists' do
|
77
|
+
it 'returns true' do
|
78
|
+
expect(test_branch.exists?).to eq true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'the branch does not exist' do
|
83
|
+
it 'returns false' do
|
84
|
+
expect(other_branch.exists?).to eq false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#checked_out?' do
|
90
|
+
context 'the branch is checked out' do
|
91
|
+
before do
|
92
|
+
run "git checkout #{quiet} #{test_branch}"
|
93
|
+
end
|
94
|
+
|
95
|
+
after do
|
96
|
+
run "git checkout - #{quiet}"
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'returns true' do
|
100
|
+
expect(test_branch.checked_out?).to eq true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'the branch is not checked_out' do
|
105
|
+
it 'returns false' do
|
106
|
+
expect(test_branch.checked_out?).to eq false
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#subset_of?' do
|
112
|
+
before do
|
113
|
+
run "git branch #{quiet} #{other_branch}"
|
114
|
+
end
|
115
|
+
|
116
|
+
after do
|
117
|
+
run "git branch -D #{quiet} #{other_branch}"
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'the branch is not a subset' do
|
121
|
+
before do
|
122
|
+
run "git checkout #{quiet} #{other_branch}"
|
123
|
+
run "touch subset_of_test_file"
|
124
|
+
run 'git add .'
|
125
|
+
run "git commit -m 'temp commit' #{quiet}"
|
126
|
+
end
|
127
|
+
|
128
|
+
after do
|
129
|
+
run "git checkout - #{quiet}"
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'returns false' do
|
133
|
+
expect(other_branch.subset_of?(test_branch)).to eq false
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'the branch is a subset' do
|
138
|
+
it 'returns true' do
|
139
|
+
expect(other_branch.subset_of?(test_branch)).to eq true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#checkout' do
|
145
|
+
after do
|
146
|
+
run "git checkout #{@checkout_to} #{quiet}"
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'checks out the branch' do
|
150
|
+
expect {
|
151
|
+
test_branch.checkout
|
152
|
+
}.to change {
|
153
|
+
`git rev-parse --abbrev-ref HEAD`.chomp
|
154
|
+
}.to(test_branch.to_s)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#version' do
|
159
|
+
it 'returns the contents of the version file' do
|
160
|
+
expect(test_branch.version).to eq `cat #{test_branch.version_file}`.chomp
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '#branch_from' do
|
165
|
+
after do
|
166
|
+
run 'git branch -D from_test_branch -q'
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'creates a new branch from self' do
|
170
|
+
expect {
|
171
|
+
SRC::Git::Branch.new('test_branch').branch_from('from_test_branch')
|
172
|
+
}.to change {
|
173
|
+
system("git show-ref --verify --quiet refs/heads/from_test_branch")
|
174
|
+
}.from(false).to(true)
|
175
|
+
expect(`git rev-parse --abbrev-ref HEAD`.chomp).to eq @checkout_to
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '#update_version_file' do
|
180
|
+
before do
|
181
|
+
@reset_update_version_file_to = `git rev-parse #{test_branch}`.chomp
|
182
|
+
raise @reset_update_version_file_to unless $?.success?
|
183
|
+
end
|
184
|
+
|
185
|
+
after do
|
186
|
+
run "git checkout #{test_branch} #{quiet}"
|
187
|
+
run "git reset --hard #{@reset_update_version_file_to} #{quiet}"
|
188
|
+
run "git checkout #{@checkout_to} #{quiet}"
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'updates the version file' do
|
192
|
+
expect {
|
193
|
+
test_branch.update_version_file('new_version')
|
194
|
+
}.to change {
|
195
|
+
`git show #{test_branch}:#{test_branch.version_file}`.chomp
|
196
|
+
}.to('new_version')
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
data/spec/lib/sc_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def run(cmd)
|
21
|
+
raise "'#{cmd}' failed" unless system cmd
|
22
|
+
end
|
data/src.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "src"
|
7
|
+
spec.version = `cat version`.chomp
|
8
|
+
spec.authors = ["Tyler Hartland"]
|
9
|
+
spec.email = ["tylerhartland7@gmail.com"]
|
10
|
+
spec.summary = 'Easily cut and merge release branches.'
|
11
|
+
spec.homepage = ""
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rspec"
|
22
|
+
end
|
data/version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: src
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tyler Hartland
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- tylerhartland7@gmail.com
|
58
|
+
executables:
|
59
|
+
- src
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/src
|
70
|
+
- lib/src.rb
|
71
|
+
- lib/src/branch.rb
|
72
|
+
- lib/src/cli.rb
|
73
|
+
- lib/src/git.rb
|
74
|
+
- lib/src/git/branch.rb
|
75
|
+
- spec/lib/sc/branch_spec.rb
|
76
|
+
- spec/lib/sc/cli_spec.rb
|
77
|
+
- spec/lib/sc/git/branch_spec.rb
|
78
|
+
- spec/lib/sc/git_spec.rb
|
79
|
+
- spec/lib/sc_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- src.gemspec
|
82
|
+
- version
|
83
|
+
homepage: ''
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.1.11
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Easily cut and merge release branches.
|
107
|
+
test_files:
|
108
|
+
- spec/lib/sc/branch_spec.rb
|
109
|
+
- spec/lib/sc/cli_spec.rb
|
110
|
+
- spec/lib/sc/git/branch_spec.rb
|
111
|
+
- spec/lib/sc/git_spec.rb
|
112
|
+
- spec/lib/sc_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
has_rdoc:
|