cherrybase 0.0.3 → 0.0.4

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.
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ nbproject
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cherrybase}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["born2snipe"]
12
- s.date = %q{2009-12-14}
12
+ s.date = %q{2010-01-12}
13
13
  s.default_executable = %q{cherrybase}
14
14
  s.description = %q{Ruby gem to cherry-pick a range of commits with similar rebase options}
15
15
  s.email = %q{born2snipe@gmail.com}
@@ -36,13 +36,15 @@ Gem::Specification.new do |s|
36
36
  "lib/executor.rb",
37
37
  "lib/file_util.rb",
38
38
  "lib/git.rb",
39
+ "lib/validator.rb",
39
40
  "spec/args_spec.rb",
40
41
  "spec/baser_spec.rb",
41
42
  "spec/executor_spec.rb",
42
43
  "spec/file_util_spec.rb",
43
44
  "spec/git_spec.rb",
44
45
  "spec/spec.opts",
45
- "spec/spec_helper.rb"
46
+ "spec/spec_helper.rb",
47
+ "spec/validator_spec.rb"
46
48
  ]
47
49
  s.homepage = %q{http://github.com/born2snipe/cherrybase}
48
50
  s.rdoc_options = ["--charset=UTF-8"]
@@ -55,7 +57,8 @@ Gem::Specification.new do |s|
55
57
  "spec/executor_spec.rb",
56
58
  "spec/file_util_spec.rb",
57
59
  "spec/git_spec.rb",
58
- "spec/spec_helper.rb"
60
+ "spec/spec_helper.rb",
61
+ "spec/validator_spec.rb"
59
62
  ]
60
63
 
61
64
  if s.respond_to? :specification_version then
@@ -1,22 +1,20 @@
1
1
  require 'git'
2
2
  require 'file_util'
3
+ require 'validator'
3
4
 
4
5
  module Cherrybase
5
6
  class Baser
6
7
 
7
- def initialize(git = Cherrybase::Git.new, file_util = Cherrybase::FileUtil.new)
8
+ def initialize(git = Cherrybase::Git.new, file_util = Cherrybase::FileUtil.new, validator = Cherrybase::Validator.new)
8
9
  @git = git
9
10
  @file_util = file_util
11
+ @validator = validator
10
12
  end
11
13
 
12
14
  def init(branch_name, starting_commit, ending_commit)
13
15
  use_svn_commit = starting_commit && starting_commit.upcase == 'SVN'
14
16
 
15
- raise "Could not locate .git folder! Is this a Git repository?" if !@file_util.git_repo?
16
- raise "Could not find branch (#{branch_name}) in the Git repository" if !@git.has_branch?(branch_name)
17
- raise "It appears you are already in the middle of a cherrybase!?" if @file_util.temp_file?
18
- raise "Could not locate START hash (#{starting_commit}) in the Git repository history" if !use_svn_commit && !@git.has_commit?(branch_name, starting_commit)
19
- raise "Could not locate END hash (#{ending_commit}) in the Git repository history" if ending_commit != nil && !@git.has_commit?(branch_name, ending_commit)
17
+ @validator.validate_init(branch_name, starting_commit, ending_commit, use_svn_commit)
20
18
 
21
19
  if (use_svn_commit)
22
20
  first_commit = @git.last_svn_commit(branch_name)
@@ -29,7 +27,7 @@ module Cherrybase
29
27
  else
30
28
  last_commit = @git.last_commit(branch_name)
31
29
  end
32
-
30
+
33
31
  commits = @git.commits_to_cherrypick(branch_name, first_commit, last_commit)
34
32
 
35
33
  if (use_svn_commit)
@@ -31,14 +31,14 @@ module Cherrybase
31
31
  end
32
32
 
33
33
  def showUsage()
34
- puts "Usage: cherrybase [<branch> [<commit> | <commit>..<commit>]] | --continue | --abort"
34
+ puts "Usage: cherrybase [<branch> [<commit> | <commit>..<commit> | svn | svn..<commit>]] | --continue | --abort"
35
35
  end
36
36
 
37
37
  def showHelp()
38
38
  puts "NAME"
39
39
  puts "\tcherrybase - cherry-pick a range of commits from one branch to the current branch"
40
40
  puts "SYNOPSIS"
41
- puts "\tcherrybase [<branch> [<commit> | <commit>..<commit>]] | --continue | --abort"
41
+ puts "\tshowUsage()"
42
42
  puts "DESCRIPTION"
43
43
  puts "\tThe idea is to cherry-pick across multiple commits and have similar functionality as the rebase command."
44
44
  end
data/lib/git.rb CHANGED
@@ -44,7 +44,12 @@ module Cherrybase
44
44
  end
45
45
 
46
46
  def has_conflicts?()
47
- @cmd.run("git ls-files -tu").length > 0
47
+ @cmd.run("git status").each do |line|
48
+ if (line.include?("Unmerged paths:"))
49
+ return true
50
+ end
51
+ end
52
+ false
48
53
  end
49
54
 
50
55
  def commit(commit_hash)
@@ -109,7 +114,7 @@ module Cherrybase
109
114
  break
110
115
  else
111
116
  if line =~ /commit [a-z0-9]+$/
112
- last_commit_hash = line[7,line.length]
117
+ last_commit_hash = line[7,line.length].strip
113
118
  end
114
119
  end
115
120
  end
@@ -0,0 +1,19 @@
1
+ module Cherrybase
2
+ class Validator
3
+
4
+ def initialize(git = Cherrybase::Git.new, file_util = Cherrybase::FileUtil.new)
5
+ @git = git
6
+ @file_util = file_util
7
+ end
8
+
9
+ def validate_init(branch_name, starting_commit, ending_commit, use_svn_commit)
10
+ raise "Could not locate .git folder! Is this a Git repository?" if !@file_util.git_repo?
11
+ raise "Could not find branch (#{branch_name}) in the Git repository" if !@git.has_branch?(branch_name)
12
+ raise "It appears you are already in the middle of a cherrybase!?" if @file_util.temp_file?
13
+ raise "Could not locate START hash (#{starting_commit}) in the Git repository history" if !use_svn_commit && !@git.has_commit?(branch_name, starting_commit)
14
+ raise "Could not locate END hash (#{ending_commit}) in the Git repository history" if ending_commit != nil && !@git.has_commit?(branch_name, ending_commit)
15
+ raise "Could not locate the last SVN commit in branch (#{branch_name})" if use_svn_commit && !@git.last_svn_commit(branch_name)
16
+ end
17
+
18
+ end
19
+ end
@@ -6,16 +6,15 @@ describe Cherrybase::Baser do
6
6
  before(:each) do
7
7
  @git = mock("git")
8
8
  @file_util = mock("file_util")
9
- @baser = Cherrybase::Baser.new(@git, @file_util)
9
+ @validator = mock("validator")
10
+ @baser = Cherrybase::Baser.new(@git, @file_util, @validator)
10
11
 
11
12
  @first_commit = "commit1"
12
13
  @commits = ["commit1", "commit2"]
13
14
  end
14
15
 
15
16
  it "should not care about case of the SVN given" do
16
- @file_util.should_receive(:git_repo?).and_return(true)
17
- @file_util.should_receive(:temp_file?).and_return(false)
18
- @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
17
+ @validator.should_receive(:validate_init)
19
18
  @git.should_receive(:last_svn_commit).with(BRANCH).and_return('svn_commit')
20
19
  @git.should_receive(:last_commit).with(BRANCH).and_return('last_commit')
21
20
  @git.should_receive(:commits_to_cherrypick).with(BRANCH, 'svn_commit', 'last_commit').and_return(['svn', 'commit1', 'commit2'])
@@ -27,9 +26,7 @@ describe Cherrybase::Baser do
27
26
  end
28
27
 
29
28
  it "should find the commit after the last svn commit and use it as the starting commit" do
30
- @file_util.should_receive(:git_repo?).and_return(true)
31
- @file_util.should_receive(:temp_file?).and_return(false)
32
- @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
29
+ @validator.should_receive(:validate_init)
33
30
  @git.should_receive(:last_svn_commit).with(BRANCH).and_return('svn_commit')
34
31
  @git.should_receive(:last_commit).with(BRANCH).and_return('last_commit')
35
32
  @git.should_receive(:commits_to_cherrypick).with(BRANCH, 'svn_commit', 'last_commit').and_return(['svn', 'commit1', 'commit2'])
@@ -68,11 +65,7 @@ describe Cherrybase::Baser do
68
65
  end
69
66
 
70
67
  it "should use the end commit if given" do
71
- @file_util.should_receive(:git_repo?).and_return(true)
72
- @file_util.should_receive(:temp_file?).and_return(false)
73
- @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
74
- @git.should_receive(:has_commit?).with(BRANCH, 'starting-commit').and_return(true)
75
- @git.should_receive(:has_commit?).with(BRANCH, 'end-commit').and_return(true)
68
+ @validator.should_receive(:validate_init)
76
69
  @git.should_receive(:commits_to_cherrypick).with(BRANCH, @first_commit, 'last_commit').and_return(@commits)
77
70
  @git.stub!(:resolve_commit).with(BRANCH, "starting-commit").and_return(@first_commit)
78
71
  @git.stub!(:resolve_commit).with(BRANCH, "end-commit").and_return("last_commit")
@@ -83,28 +76,6 @@ describe Cherrybase::Baser do
83
76
  @baser.init(BRANCH, 'starting-commit', "end-commit")
84
77
  end
85
78
 
86
- it "should raise an error if the end commit could not be located in the history" do
87
- @file_util.should_receive(:git_repo?).and_return(true)
88
- @file_util.should_receive(:temp_file?).and_return(false)
89
- @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
90
- @git.should_receive(:has_commit?).with(BRANCH, "start").and_return(true)
91
- @git.should_receive(:has_commit?).with(BRANCH, "end").and_return(false)
92
- lambda {
93
- @baser.init(BRANCH, "start", "end")
94
- }.should raise_error(RuntimeError, "Could not locate END hash (end) in the Git repository history")
95
- end
96
-
97
- it "should raise an error if the start commit could not be located in the history" do
98
- @file_util.should_receive(:git_repo?).and_return(true)
99
- @file_util.should_receive(:temp_file?).and_return(false)
100
- @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
101
-
102
- lambda {
103
- @git.should_receive(:has_commit?).with(BRANCH, "doesNotExist").and_return(false)
104
- @baser.init(BRANCH, "doesNotExist", nil)
105
- }.should raise_error(RuntimeError, "Could not locate START hash (doesNotExist) in the Git repository history")
106
- end
107
-
108
79
  it "should commit staged merge resolution" do
109
80
  @file_util.should_receive(:temp_file?).and_return(true)
110
81
  @file_util.should_receive(:read_temp_file).and_return({
@@ -219,11 +190,8 @@ describe Cherrybase::Baser do
219
190
  end
220
191
 
221
192
  it "should create the cherrybase temp file with the given branch's last commit" do
222
- @file_util.should_receive(:git_repo?).and_return(true)
223
- @file_util.should_receive(:temp_file?).and_return(false)
224
- @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
193
+ @validator.should_receive(:validate_init)
225
194
  @git.should_receive(:last_commit).with(BRANCH).and_return('last-commit')
226
- @git.should_receive(:has_commit?).with(BRANCH, 'starting-commit').and_return(true)
227
195
  @git.should_receive(:commits_to_cherrypick).with(BRANCH, @first_commit, 'last-commit').and_return(@commits)
228
196
  @git.stub!(:resolve_commit).with(BRANCH, "starting-commit").and_return(@first_commit)
229
197
  @git.stub!(:current_branch).and_return("current")
@@ -232,28 +200,4 @@ describe Cherrybase::Baser do
232
200
  @baser.init(BRANCH, 'starting-commit', nil)
233
201
  end
234
202
 
235
- it "should throw an error if the given branch name does not exist in the repository" do
236
- lambda {
237
- @file_util.should_receive(:git_repo?).and_return(true)
238
- @git.should_receive(:has_branch?).with(BRANCH).and_return(false)
239
- @baser.init(BRANCH, nil, nil)
240
- }.should raise_error(RuntimeError, "Could not find branch (branch-name) in the Git repository")
241
- end
242
-
243
- it "should throw an exception if the git repo folder could not be discovered" do
244
- lambda {
245
- @file_util.should_receive(:git_repo?).and_return(false)
246
- @baser.init(nil, nil, nil)
247
- }.should raise_error(RuntimeError, "Could not locate .git folder! Is this a Git repository?")
248
- end
249
-
250
- it "should throw an error if you already in the middle of a cherrybase" do
251
- @file_util.should_receive(:git_repo?).and_return(true)
252
- @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
253
- lambda {
254
- @file_util.should_receive(:temp_file?).and_return(true)
255
- @baser.init("branch-name", nil, nil)
256
- }.should raise_error(RuntimeError, "It appears you are already in the middle of a cherrybase!?")
257
- end
258
-
259
203
  end
@@ -75,19 +75,18 @@ describe Cherrybase::Git do
75
75
  end
76
76
 
77
77
  it "should return false if no files are marked as unmerged" do
78
- @cmd.should_receive(:run).with("git ls-files -tu").and_return([])
78
+ @cmd.should_receive(:run).with("git status").and_return([])
79
79
 
80
80
  @git.has_conflicts?().should == false
81
81
  end
82
82
 
83
83
  it "should return true if files are marked as unmerged" do
84
84
  log_lines = [
85
- "M 100644 e01079f2c38b76cf43780a2899c3f5bd2f50b3a7 1 readme.txt",
86
- "M 100644 f7b5ff223f06fb323463b81b08759cf13678fd27 2 readme.txt",
87
- "M 100644 0ebe257230ddb66e12610ad9b304c7605b61dfeb 3 readme.txt"
85
+ "# On branch test",
86
+ "# Unmerged paths:"
88
87
  ]
89
88
 
90
- @cmd.should_receive(:run).with("git ls-files -tu").and_return(log_lines)
89
+ @cmd.should_receive(:run).with("git status").and_return(log_lines)
91
90
 
92
91
  @git.has_conflicts?().should == true
93
92
  end
@@ -146,7 +145,7 @@ describe Cherrybase::Git do
146
145
  "",
147
146
  " comment-1",
148
147
  "",
149
- "commit hash2",
148
+ "commit hash2\n",
150
149
  "Author: author-2",
151
150
  "Date: date-2",
152
151
  "",
@@ -5,6 +5,7 @@ require 'baser'
5
5
  require 'file_util'
6
6
  require 'args'
7
7
  require 'executor'
8
+ require 'validator'
8
9
 
9
10
  require 'spec'
10
11
  require 'spec/autorun'
@@ -0,0 +1,93 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Cherrybase::Validator do
4
+ BRANCH = "branch-name"
5
+
6
+ before(:each) do
7
+ @git = mock("git")
8
+ @file_util = mock("file_util")
9
+ @validator = Cherrybase::Validator.new(@git, @file_util)
10
+ end
11
+
12
+ it "should not raise any errors" do
13
+ @file_util.should_receive(:git_repo?).and_return(true)
14
+ @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
15
+ @file_util.should_receive(:temp_file?).and_return(false)
16
+ @git.should_receive(:has_commit?).with(BRANCH, "start-commit").and_return(true)
17
+ @git.should_receive(:has_commit?).with(BRANCH, "end-commit").and_return(true)
18
+
19
+ @validator.validate_init(BRANCH, "start-commit", "end-commit", nil)
20
+ end
21
+
22
+ it "should raise an error if the last SVN commit could not be found" do
23
+ @file_util.should_receive(:git_repo?).and_return(true)
24
+ @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
25
+ @file_util.should_receive(:temp_file?).and_return(false)
26
+ @git.should_receive(:last_svn_commit).with(BRANCH).and_return(nil)
27
+
28
+ lambda {
29
+ @validator.validate_init(BRANCH, nil, nil, true)
30
+ }.should raise_error(RuntimeError, "Could not locate the last SVN commit in branch (#{BRANCH})")
31
+ end
32
+
33
+ it "should raise an error if the given ending commit can not be found for the given branch" do
34
+ @file_util.should_receive(:git_repo?).and_return(true)
35
+ @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
36
+ @file_util.should_receive(:temp_file?).and_return(false)
37
+ @git.should_receive(:has_commit?).with(BRANCH, "start-commit").and_return(true)
38
+ @git.should_receive(:has_commit?).with(BRANCH, "end-commit").and_return(false)
39
+
40
+ lambda {
41
+ @validator.validate_init(BRANCH, "start-commit", "end-commit", nil)
42
+ }.should raise_error(RuntimeError, "Could not locate END hash (end-commit) in the Git repository history")
43
+ end
44
+
45
+
46
+ it "should not check for start commit hash if using the last SVN commit" do
47
+ @file_util.should_receive(:git_repo?).and_return(true)
48
+ @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
49
+ @file_util.should_receive(:temp_file?).and_return(false)
50
+ @git.should_receive(:last_svn_commit).with(BRANCH).and_return("last-svn-commit")
51
+
52
+ @validator.validate_init(BRANCH, nil, nil, true)
53
+ end
54
+
55
+ it "should raise an error if the given starting commit can not be found for the given branch" do
56
+ @file_util.should_receive(:git_repo?).and_return(true)
57
+ @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
58
+ @file_util.should_receive(:temp_file?).and_return(false)
59
+ @git.should_receive(:has_commit?).with(BRANCH, "start-commit").and_return(false)
60
+
61
+ lambda {
62
+ @validator.validate_init(BRANCH, "start-commit", nil, nil)
63
+ }.should raise_error(RuntimeError, "Could not locate START hash (start-commit) in the Git repository history")
64
+ end
65
+
66
+ it "should raise an error if you are currently in the middle of a cherrybase already" do
67
+ @file_util.should_receive(:git_repo?).and_return(true)
68
+ @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
69
+ @file_util.should_receive(:temp_file?).and_return(true)
70
+
71
+ lambda {
72
+ @validator.validate_init(BRANCH, nil, nil, nil)
73
+ }.should raise_error(RuntimeError, "It appears you are already in the middle of a cherrybase!?")
74
+ end
75
+
76
+ it "should raise an error if the branch given is NOT found in the repository" do
77
+ @file_util.should_receive(:git_repo?).and_return(true)
78
+ @git.should_receive(:has_branch?).with(BRANCH).and_return(false)
79
+
80
+ lambda {
81
+ @validator.validate_init(BRANCH, nil, nil, nil)
82
+ }.should raise_error(RuntimeError, "Could not find branch (#{BRANCH}) in the Git repository")
83
+ end
84
+
85
+ it "should raise an error if the current directory is NOT a git repository" do
86
+ @file_util.should_receive(:git_repo?).and_return(false)
87
+
88
+ lambda {
89
+ @validator.validate_init(nil, nil, nil, nil)
90
+ }.should raise_error(RuntimeError, "Could not locate .git folder! Is this a Git repository?")
91
+ end
92
+
93
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cherrybase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - born2snipe
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-14 00:00:00 -06:00
12
+ date: 2010-01-12 00:00:00 -06:00
13
13
  default_executable: cherrybase
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,7 @@ files:
49
49
  - lib/executor.rb
50
50
  - lib/file_util.rb
51
51
  - lib/git.rb
52
+ - lib/validator.rb
52
53
  - spec/args_spec.rb
53
54
  - spec/baser_spec.rb
54
55
  - spec/executor_spec.rb
@@ -56,6 +57,7 @@ files:
56
57
  - spec/git_spec.rb
57
58
  - spec/spec.opts
58
59
  - spec/spec_helper.rb
60
+ - spec/validator_spec.rb
59
61
  has_rdoc: true
60
62
  homepage: http://github.com/born2snipe/cherrybase
61
63
  licenses: []
@@ -91,3 +93,4 @@ test_files:
91
93
  - spec/file_util_spec.rb
92
94
  - spec/git_spec.rb
93
95
  - spec/spec_helper.rb
96
+ - spec/validator_spec.rb