Skip to content

Commit 30f131e

Browse files
committed
Merge remote-tracking branch 'base/master'
2 parents 0d8cb45 + a223fcf commit 30f131e

File tree

8 files changed

+237
-199
lines changed

8 files changed

+237
-199
lines changed

.travis.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
language: ruby
22
rvm:
3-
- 1.8.7
43
- 1.9.2
54
- 1.9.3
65
- 2.0.0
76
- 2.1.1
87
- 2.1.2
98
- jruby-18mode
109
- jruby-19mode
11-
- ree
12-
matrix:
13-
allow_failures:
14-
- rbx-18mode
15-
- rbx-19mode
10+
before_install:
11+
- gem install bundler
12+
- bundle --version

CHANGELOG

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
== 1.3.0
2+
3+
* Dropping Ruby 1.8.x support
4+
5+
== 1.2.10
6+
7+
* Adding Git::Diff.name_status
8+
* Checking and fixing encoding on commands output to prevent encoding errors afterwards
9+
110
== 1.2.9
211

312
* Adding Git.configure (to configure the git env)
@@ -14,17 +23,17 @@
1423
* Improving Git::Object::Tag. Adding annotated?, tagger and message
1524
* Supporting a submodule path as a valid repo
1625
* Git.checkout - supporting -f and -b
17-
* Git.clone - supporting --branch
26+
* Git.clone - supporting --branch
1827
* Git.fetch - supporting --prune
19-
* Git.tag - supporting
28+
* Git.tag - supporting
2029

2130
== 1.2.8
2231

2332
* Keeping the old escape format for windows users
2433
* revparse: Supporting ref names containing SHA like substrings (40-hex strings)
2534
* Fix warnings on Ruby 2.1.2
2635

27-
== 1.2.7
36+
== 1.2.7
2837

2938
* Fixing mesages encoding
3039
* Fixing -f flag in git push
@@ -47,9 +56,9 @@
4756
* Git.add - supporting --fore
4857
* Git.init - supporting --bare
4958
* Git.commit - supporting --all and --amend
50-
* Added Git.remote_remote, Git.revert and Git.clean
59+
* Added Git.remote_remote, Git.revert and Git.clean
5160
* Added Bundler to the formula
52-
* Travis configuration
61+
* Travis configuration
5362
* Licence included with the gem
5463

5564
== 1.0.4

README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ http://github.com/schacon/ruby-git
1313
You can install Ruby/Git like this:
1414

1515
$ sudo gem install git
16-
16+
1717
## Code Status
1818

1919
* [![Build Status](https://api.travis-ci.org/schacon/ruby-git.png)](https://travis-ci.org/schacon/ruby-git)
@@ -46,7 +46,7 @@ like:
4646

4747
Here are a bunch of examples of how to use the Ruby/Git package.
4848

49-
Ruby < 1.9 will require rubygems to be loaded.
49+
Ruby < 1.9 will require rubygems to be loaded.
5050

5151
```ruby
5252
require 'rubygems'
@@ -127,12 +127,13 @@ Here are the operations that need read permission only.
127127
g.grep('hello') # implies HEAD
128128
g.blob('v2.5:Makefile').grep('hello')
129129
g.tag('v2.5').grep('hello', 'docs/')
130-
g.describe()
130+
g.describe()
131131
g.describe('0djf2aa')
132132
g.describe('HEAD', {:all => true, :tags => true})
133-
133+
134134
g.diff(commit1, commit2).size
135135
g.diff(commit1, commit2).stats
136+
g.diff(commit1, commit2).name_status
136137
g.gtree('v2.5').diff('v2.6').insertions
137138
g.diff('gitsearch1', 'v2.5').path('lib/')
138139
g.diff('gitsearch1', @git.gtree('v2.5'))
@@ -149,7 +150,7 @@ Here are the operations that need read permission only.
149150
g.config # returns whole config hash
150151

151152
g.tags # returns array of Git::Tag objects
152-
153+
153154
g.show()
154155
g.show('HEAD')
155156
g.show('v2.8', 'README.md')
@@ -178,9 +179,11 @@ And here are the operations that will need to write to your git repository.
178179
g.add('file_path') # git add -- "file_path"
179180
g.add(['file_path_1', 'file_path_2']) # git add -- "file_path_1" "file_path_2"
180181

181-
182-
g.remove('file.txt')
183-
g.remove(['file.txt', 'file2.txt'])
182+
g.remove() # git rm -f -- "."
183+
g.remove('file.txt') # git rm -f -- "file.txt"
184+
g.remove(['file.txt', 'file2.txt']) # git rm -f -- "file.txt" "file2.txt"
185+
g.remove('file.txt', :recursive => true) # git rm -f -r -- "file.txt"
186+
g.remove('file.txt', :cached => true) # git rm -f --cached -- "file.txt"
184187

185188
g.commit('message')
186189
g.commit_all('message')

VERSION

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
1.2.9.1
1+
1.3.0
2+

git.gemspec

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
Gem::Specification.new do |s|
22
s.authors = ['Scott Chacon']
3-
s.date = '2015-01-13'
3+
s.date = '2016-02-25'
44
s.email = '[email protected]'
55
s.homepage = 'http://github.com/schacon/ruby-git'
66
s.license = 'MIT'
77
s.name = 'git'
88
s.summary = 'Ruby/Git is a Ruby library that can be used to create, read and manipulate Git repositories by wrapping system calls to the git binary.'
9-
s.version = '1.2.9.1'
9+
s.version = '1.3.0'
1010

11-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
1211
s.require_paths = ['lib']
12+
s.required_ruby_version = '>= 1.9'
13+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
1314
s.requirements = ['git 1.6.0.0, or greater']
1415

1516
s.add_development_dependency 'rake'
1617
s.add_development_dependency 'rdoc'
1718
s.add_development_dependency 'test-unit', '>=2', '< 4'
18-
19+
1920
s.extra_rdoc_files = ['README.md']
2021
s.rdoc_options = ['--charset=UTF-8']
2122

lib/git/diff.rb

+41-34
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module Git
2-
2+
33
# object that holds the last X commits on given branch
44
class Diff
55
include Enumerable
6-
6+
77
def initialize(base, from = nil, to = nil)
88
@base = base
9-
@from = from && from.to_s
9+
@from = from && from.to_s
1010
@to = to && to.to_s
1111

1212
@path = nil
@@ -15,60 +15,64 @@ def initialize(base, from = nil, to = nil)
1515
@stats = nil
1616
end
1717
attr_reader :from, :to
18-
18+
19+
def name_status
20+
cache_name_status
21+
end
22+
1923
def path(path)
2024
@path = path
2125
return self
2226
end
23-
27+
2428
def size
2529
cache_stats
2630
@stats[:total][:files]
2731
end
28-
32+
2933
def lines
3034
cache_stats
3135
@stats[:total][:lines]
3236
end
33-
37+
3438
def deletions
3539
cache_stats
3640
@stats[:total][:deletions]
3741
end
38-
42+
3943
def insertions
4044
cache_stats
4145
@stats[:total][:insertions]
4246
end
43-
47+
4448
def stats
4549
cache_stats
4650
@stats
4751
end
48-
52+
4953
# if file is provided and is writable, it will write the patch into the file
5054
def patch(file = nil)
5155
cache_full
5256
@full_diff
5357
end
5458
alias_method :to_s, :patch
55-
59+
5660
# enumerable methods
57-
61+
5862
def [](key)
5963
process_full
6064
@full_diff_files.assoc(key)[1]
6165
end
62-
66+
6367
def each(&block) # :yields: each Git::DiffFile in turn
6468
process_full
6569
@full_diff_files.map { |file| file[1] }.each(&block)
6670
end
67-
71+
6872
class DiffFile
6973
attr_accessor :patch, :path, :mode, :src, :dst, :type
7074
@base = nil
71-
75+
7276
def initialize(base, hash)
7377
@base = base
7478
@patch = hash[:patch]
@@ -83,7 +87,7 @@ def initialize(base, hash)
8387
def binary?
8488
!!@binary
8589
end
86-
90+
8791
def blob(type = :dst)
8892
if type == :src
8993
@base.object(@src) if @src != '0000000'
@@ -92,28 +96,27 @@ def blob(type = :dst)
9296
end
9397
end
9498
end
95-
99+
96100
private
97-
101+
98102
def cache_full
99-
unless @full_diff
100-
@full_diff = @base.lib.diff_full(@from, @to, {:path_limiter => @path})
101-
end
103+
@full_diff ||= @base.lib.diff_full(@from, @to, {:path_limiter => @path})
102104
end
103-
105+
104106
def process_full
105-
unless @full_diff_files
106-
cache_full
107-
@full_diff_files = process_full_diff
108-
end
107+
return if @full_diff_files
108+
cache_full
109+
@full_diff_files = process_full_diff
109110
end
110-
111+
111112
def cache_stats
112-
unless @stats
113-
@stats = @base.lib.diff_stats(@from, @to, {:path_limiter => @path})
114-
end
113+
@stats ||= @base.lib.diff_stats(@from, @to, {:path_limiter => @path})
115114
end
116-
115+
116+
def cache_name_status
117+
@name_status ||= @base.lib.diff_name_status(@from, @to, {:path => @path})
118+
end
119+
117120
# break up @diff_full
118121
def process_full_diff
119122
defaults = {
@@ -124,7 +127,11 @@ def process_full_diff
124127
}
125128
final = {}
126129
current_file = nil
127-
@full_diff.split("\n").each do |line|
130+
full_diff_utf8_encoded = @full_diff.encode("UTF-8", "binary", {
131+
:invalid => :replace,
132+
:undef => :replace
133+
})
134+
full_diff_utf8_encoded.split("\n").each do |line|
128135
if m = /^diff --git a\/(.*?) b\/(.*?)/.match(line)
129136
current_file = m[1]
130137
final[current_file] = defaults.merge({:patch => line, :path => current_file})
@@ -141,11 +148,11 @@ def process_full_diff
141148
if m = /^Binary files /.match(line)
142149
final[current_file][:binary] = true
143150
end
144-
final[current_file][:patch] << "\n" + line
151+
final[current_file][:patch] << "\n" + line
145152
end
146153
end
147154
final.map { |e| [e[0], DiffFile.new(@base, e[1])] }
148155
end
149-
156+
150157
end
151158
end

0 commit comments

Comments
 (0)