cherrybase 0.0.1 → 0.0.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/cherrybase.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cherrybase}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
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-12}
12
+ s.date = %q{2009-12-13}
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}
data/lib/baser.rb CHANGED
@@ -35,36 +35,39 @@ module Cherrybase
35
35
  next_cherrypick = temp_data['next_cherrypick']
36
36
 
37
37
  if commit_previous_hash
38
- @git.commit(commits[commits.index(next_cherrypick) - 1])
38
+ raise "Please stage all your changes before trying to --continue" if @git.has_conflicts?
39
+ commit_hash = commits.last
40
+ if next_cherrypick
41
+ commit_hash = commits[commits.index(next_cherrypick) - 1]
42
+ end
43
+ @git.commit(commit_hash)
39
44
  end
40
45
 
41
- conflicts_found = false
42
- last_commit_applied = nil
43
- i = commits.index(next_cherrypick)
46
+ if next_cherrypick
47
+ conflicts_found = false
48
+ last_commit_applied = nil
49
+ i = commits.index(next_cherrypick)
44
50
 
45
- while i < commits.length
46
- puts "Applying #{i+1} of #{commits.length} cherry-picks\r"
47
- last_commit_applied = commits[i]
48
- @git.cherry_pick(last_commit_applied)
49
- if @git.has_conflicts?
50
- conflicts_found = true
51
- break
51
+ while i < commits.length
52
+ puts "Applying #{i+1} of #{commits.length} cherry-picks"
53
+ last_commit_applied = commits[i]
54
+ @git.cherry_pick(last_commit_applied)
55
+ if @git.has_conflicts?
56
+ conflicts_found = true
57
+ break
58
+ end
59
+ i += 1
52
60
  end
53
- i += 1
54
61
  end
55
62
 
56
63
  if conflicts_found
57
64
  puts "Conflict(s) Encountered!"
58
65
  @git.status
59
- if (last_commit_applied == commits.last)
60
- @file_util.delete_temp_file()
61
- else
62
- @file_util.write_temp_file(temp_data['starting_commit'], commits.last, commits)
63
- end
66
+ @file_util.write_temp_file(temp_data['starting_commit'], commits[i+1], commits)
64
67
  else
65
68
  @file_util.delete_temp_file()
69
+ puts "Cherrybase completed!"
66
70
  end
67
- puts "Cherrybase completed!"
68
71
  end
69
72
 
70
73
  def abort()
data/lib/git.rb CHANGED
@@ -17,13 +17,17 @@ module Cherrybase
17
17
  def resolve_commit(branch_name, commit_hash)
18
18
  if commit_hash
19
19
  raise "Please supply at least 5 characters for a commit hash" if commit_hash.length < 5
20
+ match = nil
20
21
  @cmd.run("git log #{branch_name} --pretty=oneline").each do |line|
21
22
  if line == commit_hash || line.include?(commit_hash)
22
- return line.split(' ')[0]
23
+ raise "Ambigous hash commit found! Please supply more of the commit hash (#{commit_hash})" if match
24
+ match = line.split(' ')[0]
23
25
  end
24
26
  end
27
+ match
28
+ else
29
+ nil
25
30
  end
26
- nil
27
31
  end
28
32
 
29
33
  def last_commit(branch_name)
data/spec/baser_spec.rb CHANGED
@@ -9,6 +9,16 @@ describe Cherrybase::Baser do
9
9
  @baser = Cherrybase::Baser.new(@git, @file_util)
10
10
  end
11
11
 
12
+ it "should raise an error if your try to continue with changes that are unstaged" do
13
+ @file_util.should_receive(:temp_file?).and_return(true)
14
+ @file_util.should_receive(:read_temp_file).and_return({})
15
+ @git.stub!(:has_conflicts?).and_return(true)
16
+
17
+ lambda {
18
+ @baser.continue(true)
19
+ }.should raise_error(RuntimeError, "Please stage all your changes before trying to --continue")
20
+ end
21
+
12
22
  it "should reset HEAD back to the last original commit before any cherry-picks" do
13
23
  @file_util.stub!(:temp_file?).and_return(true)
14
24
  @file_util.stub!(:read_temp_file).and_return({"starting_commit" => "start"})
@@ -57,6 +67,7 @@ describe Cherrybase::Baser do
57
67
  @file_util.should_receive(:git_repo?).and_return(true)
58
68
  @file_util.should_receive(:temp_file?).and_return(false)
59
69
  @git.should_receive(:has_branch?).with(BRANCH).and_return(true)
70
+
60
71
  lambda {
61
72
  @git.should_receive(:has_commit?).with(BRANCH, "doesNotExist").and_return(false)
62
73
  @baser.init(BRANCH, "doesNotExist", nil)
@@ -74,6 +85,21 @@ describe Cherrybase::Baser do
74
85
  @git.should_receive(:cherry_pick).with("commit1")
75
86
  @git.should_receive(:has_conflicts?).and_return(false)
76
87
  @file_util.should_receive(:delete_temp_file)
88
+ @git.stub!(:has_conflicts?).and_return(false)
89
+
90
+ @baser.continue(true)
91
+ end
92
+
93
+ it "should handle if the last commit had a conflict and you continue with committing" do
94
+ @file_util.should_receive(:temp_file?).and_return(true)
95
+ @file_util.should_receive(:read_temp_file).and_return({
96
+ "starting_commit" => "start",
97
+ "next_cherrypick" => nil,
98
+ "commits" => ["start", "commit1"]
99
+ })
100
+ @git.should_receive(:has_conflicts?).and_return(false)
101
+ @git.should_receive(:commit).with("commit1")
102
+ @file_util.should_receive(:delete_temp_file)
77
103
 
78
104
  @baser.continue(true)
79
105
  end
@@ -92,22 +118,23 @@ describe Cherrybase::Baser do
92
118
  @baser.continue
93
119
  end
94
120
 
95
- it "should cleanup the temp file if a conflict is encountered on the last commit" do
121
+ it "should stop cherrypicking if a conflict is found, with multiple commits left" do
96
122
  @file_util.should_receive(:temp_file?).and_return(true)
97
123
  @file_util.should_receive(:read_temp_file).and_return({
98
124
  "starting_commit" => "start",
99
125
  "next_cherrypick" => "start",
100
- "commits" => ["start"]
126
+ "commits" => ["start", "middle", "end"]
101
127
  })
102
128
  @git.should_receive(:cherry_pick).with("start")
103
129
  @git.should_receive(:has_conflicts?).and_return(true)
104
130
  @git.should_receive(:status)
105
- @file_util.should_receive(:delete_temp_file)
131
+ @file_util.should_receive(:write_temp_file).with("start", "middle", ["start", "middle", "end"])
106
132
 
107
133
  @baser.continue
108
134
  end
109
135
 
110
- it "should stop cherrypicking if a conflict is found" do
136
+
137
+ it "should stop cherrypicking if a conflict is found, only one commit left" do
111
138
  @file_util.should_receive(:temp_file?).and_return(true)
112
139
  @file_util.should_receive(:read_temp_file).and_return({
113
140
  "starting_commit" => "start",
data/spec/git_spec.rb CHANGED
@@ -7,6 +7,14 @@ describe Cherrybase::Git do
7
7
  @git = Cherrybase::Git.new(@cmd)
8
8
  end
9
9
 
10
+ it "should raise an error if another commit is found with the given has while resolving the commit" do
11
+ @cmd.stub!(:run).with("git log branch --pretty=oneline").and_return(["1234567", "123456"])
12
+
13
+ lambda {
14
+ @git.resolve_commit("branch", "12345")
15
+ }.should raise_error(RuntimeError, "Ambigous hash commit found! Please supply more of the commit hash (12345)")
16
+ end
17
+
10
18
  it "should reset the HEAD to the given commit" do
11
19
  @cmd.should_receive(:run).with("git reset --hard commit")
12
20
 
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.1
4
+ version: 0.0.2
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-12 00:00:00 -06:00
12
+ date: 2009-12-13 00:00:00 -06:00
13
13
  default_executable: cherrybase
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency