grit 2.4.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/History.txt +5 -0
  2. data/grit.gemspec +2 -2
  3. data/lib/grit.rb +1 -1
  4. data/lib/grit/git.rb +40 -36
  5. metadata +4 -4
@@ -1,3 +1,8 @@
1
+ == 2.4.1 / 2011-01-13
2
+ * Minor Enhancements
3
+ * Grit::Process is used to implement Grit::Git#check_applies,
4
+ Grit::Git#get_patch, and Grit::Git#apply_patch.
5
+
1
6
  == 2.4.0 / 2011-01-06
2
7
  * Major Enhancements
3
8
  * Add support for parsing git notes.
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'grit'
7
- s.version = '2.4.0'
8
- s.date = '2011-01-06'
7
+ s.version = '2.4.1'
8
+ s.date = '2011-01-13'
9
9
  s.rubyforge_project = 'grit'
10
10
 
11
11
  s.summary = "Ruby Git bindings."
@@ -55,7 +55,7 @@ if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
55
55
  end
56
56
 
57
57
  module Grit
58
- VERSION = '2.4.0'
58
+ VERSION = '2.4.1'
59
59
 
60
60
  class << self
61
61
  # Set +debug+ to true to log all git calls and responses
@@ -178,56 +178,60 @@ module Grit
178
178
  end
179
179
  end
180
180
 
181
+ # Checks if the patch of a commit can be applied to the given head.
182
+ #
183
+ # head_sha - String SHA or ref to check the patch against.
184
+ # applies_sha - String SHA of the patch. The patch itself is retrieved
185
+ # with #get_patch.
186
+ #
187
+ # Returns 0 if the patch applies cleanly (according to `git apply`), or
188
+ # an Integer that is the sum of the failed exit statuses.
181
189
  def check_applies(head_sha, applies_sha)
182
190
  git_index = create_tempfile('index', true)
183
- (o1, exit1) = raw_git("git read-tree #{head_sha} 2>/dev/null", git_index)
184
- (o2, exit2) = raw_git("git diff #{applies_sha}^ #{applies_sha} | git apply --check --cached >/dev/null 2>/dev/null", git_index)
185
- return (exit1 + exit2)
191
+ options = {:env => {'GIT_INDEX_FILE' => git_index}, :raise => true}
192
+ status = 0
193
+ begin
194
+ native(:read_tree, options.dup, head_sha)
195
+ stdin = native(:diff, options.dup, "#{applies_sha}^", applies_sha)
196
+ native(:apply, options.merge(:check => true, :cached => true, :input => stdin))
197
+ rescue CommandFailed => fail
198
+ status += fail.exitstatus
199
+ end
200
+ status
186
201
  end
187
202
 
203
+ # Gets a patch for a given SHA using `git diff`.
204
+ #
205
+ # applies_sha - String SHA to get the patch from, using this command:
206
+ # `git diff #{applies_sha}^ #{applies_sha}`
207
+ #
208
+ # Returns the String patch from `git diff`.
188
209
  def get_patch(applies_sha)
189
210
  git_index = create_tempfile('index', true)
190
- (patch, exit2) = raw_git("git diff #{applies_sha}^ #{applies_sha}", git_index)
191
- patch
211
+ native(:diff, {
212
+ :env => {'GIT_INDEX_FILE' => git_index}},
213
+ "#{applies_sha}^", applies_sha)
192
214
  end
193
215
 
216
+ # Applies the given patch against the given SHA of the current repo.
217
+ #
218
+ # head_sha - String SHA or ref to apply the patch to.
219
+ # patch - The String patch to apply. Get this from #get_patch.
220
+ #
221
+ # Returns the String Tree SHA on a successful patch application, or false.
194
222
  def apply_patch(head_sha, patch)
195
223
  git_index = create_tempfile('index', true)
196
224
 
197
- git_patch = create_tempfile('patch')
198
- File.open(git_patch, 'w+') { |f| f.print patch }
199
-
200
- raw_git("git read-tree #{head_sha} 2>/dev/null", git_index)
201
- (op, exit) = raw_git("git apply --cached < #{git_patch}", git_index)
202
- if exit == 0
203
- return raw_git("git write-tree", git_index).first.chomp
225
+ options = {:env => {'GIT_INDEX_FILE' => git_index}, :raise => true}
226
+ begin
227
+ native(:read_tree, options.dup, head_sha)
228
+ native(:apply, options.merge(:cached => true, :input => patch))
229
+ rescue CommandFailed
230
+ return false
204
231
  end
205
- false
232
+ native(:write_tree, :env => options[:env]).to_s.chomp!
206
233
  end
207
234
 
208
- # RAW CALLS WITH ENV SETTINGS
209
- def raw_git_call(command, index)
210
- tmp = ENV['GIT_INDEX_FILE']
211
- ENV['GIT_INDEX_FILE'] = index
212
- out = `#{command}`
213
- after = ENV['GIT_INDEX_FILE'] # someone fucking with us ??
214
- ENV['GIT_INDEX_FILE'] = tmp
215
- if after != index
216
- raise 'environment was changed for the git call'
217
- end
218
- [out, $?.exitstatus]
219
- end
220
-
221
- def raw_git(command, index)
222
- output = nil
223
- Dir.chdir(self.git_dir) do
224
- output = raw_git_call(command, index)
225
- end
226
- output
227
- end
228
- # RAW CALLS WITH ENV SETTINGS END
229
-
230
-
231
235
  # Execute a git command, bypassing any library implementation.
232
236
  #
233
237
  # cmd - The name of the git command as a Symbol. Underscores are
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 4
9
- - 0
10
- version: 2.4.0
9
+ - 1
10
+ version: 2.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tom Preston-Werner
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-01-06 00:00:00 -08:00
19
+ date: 2011-01-13 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency