grit 2.4.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grit might be problematic. Click here for more details.
- data/History.txt +5 -0
- data/grit.gemspec +2 -2
- data/lib/grit.rb +1 -1
- data/lib/grit/git.rb +40 -36
- metadata +4 -4
data/History.txt
CHANGED
data/grit.gemspec
CHANGED
data/lib/grit.rb
CHANGED
data/lib/grit/git.rb
CHANGED
@@ -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
|
-
|
184
|
-
|
185
|
-
|
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
|
-
(
|
191
|
-
|
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
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
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
|
-
|
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:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 2.4.
|
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-
|
19
|
+
date: 2011-01-13 00:00:00 -08:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|