git 1.2.9.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of git might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6345c26432a4a89a14892294e9626305746cfc43
4
- data.tar.gz: 1c6fa07d75bcbd5947fd523416c36949b9c65ae8
3
+ metadata.gz: 57559d500d07f7561f8a62e21f87fb73b0759b98
4
+ data.tar.gz: 4946775180b583063b68a9fa2ca507bbe2f3242f
5
5
  SHA512:
6
- metadata.gz: a9d68fd1d7e5644ca79a31ee30cdce423c505178536a875386a41eaf8d42320a98fa738e09956f81e06845de1ccd48176c73c0e7cab3fa96b7fb335f8bf0054f
7
- data.tar.gz: cd5b1a434f47f1b50da03721f4bbc9d343349e1f0287e342ce62378dc23dee37566ca262475204f1e6c46a2a4f0d373cb07d168119efe1b836c164414fb73c07
6
+ metadata.gz: a5f355d639e30163b6f56c0aacfc0bd5bb441dbfcf961b22b838a25dc8e2775afa8528e90f021b750c3431c9fdcce5795e04fd8b6b5eb2e271d32bfdeb26e3ce
7
+ data.tar.gz: c49b547f7c47b6f0cc522ae4f0767c1f3a86817c45fb01f1d712bee8c9e1144075ab832e8eb863263bd55caad6a38b38b3c19c7059091abb7f7fe626fc6c92d1
data/CHANGELOG CHANGED
@@ -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
+
1
10
  == 1.2.9
2
11
 
3
12
  * Adding Git.configure (to configure the git env)
@@ -14,9 +23,9 @@
14
23
  * Improving Git::Object::Tag. Adding annotated?, tagger and message
15
24
  * Supporting a submodule path as a valid repo
16
25
  * Git.checkout - supporting -f and -b
17
- * Git.clone - supporting --branch
26
+ * Git.clone - supporting --branch
18
27
  * Git.fetch - supporting --prune
19
- * Git.tag - supporting
28
+ * Git.tag - supporting
20
29
 
21
30
  == 1.2.8
22
31
 
@@ -24,7 +33,7 @@
24
33
  * revparse: Supporting ref names containing SHA like substrings (40-hex strings)
25
34
  * Fix warnings on Ruby 2.1.2
26
35
 
27
- == 1.2.7
36
+ == 1.2.7
28
37
 
29
38
  * Fixing mesages encoding
30
39
  * Fixing -f flag in git push
@@ -47,9 +56,9 @@
47
56
  * Git.add - supporting --fore
48
57
  * Git.init - supporting --bare
49
58
  * 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
51
60
  * Added Bundler to the formula
52
- * Travis configuration
61
+ * Travis configuration
53
62
  * Licence included with the gem
54
63
 
55
64
  == 1.0.4
data/README.md CHANGED
@@ -13,7 +13,7 @@ http://github.com/schacon/ruby-git
13
13
  You can install Ruby/Git like this:
14
14
 
15
15
  $ sudo gem install git
16
-
16
+
17
17
  ## Code Status
18
18
 
19
19
  * [![Build Status](https://api.travis-ci.org/schacon/ruby-git.png)](https://travis-ci.org/schacon/ruby-git)
@@ -46,7 +46,7 @@ like:
46
46
 
47
47
  Here are a bunch of examples of how to use the Ruby/Git package.
48
48
 
49
- Ruby < 1.9 will require rubygems to be loaded.
49
+ Ruby < 1.9 will require rubygems to be loaded.
50
50
 
51
51
  ```ruby
52
52
  require 'rubygems'
@@ -127,12 +127,13 @@ Here are the operations that need read permission only.
127
127
  g.grep('hello') # implies HEAD
128
128
  g.blob('v2.5:Makefile').grep('hello')
129
129
  g.tag('v2.5').grep('hello', 'docs/')
130
- g.describe()
130
+ g.describe()
131
131
  g.describe('0djf2aa')
132
132
  g.describe('HEAD', {:all => true, :tags => true})
133
-
133
+
134
134
  g.diff(commit1, commit2).size
135
135
  g.diff(commit1, commit2).stats
136
+ g.diff(commit1, commit2).name_status
136
137
  g.gtree('v2.5').diff('v2.6').insertions
137
138
  g.diff('gitsearch1', 'v2.5').path('lib/')
138
139
  g.diff('gitsearch1', @git.gtree('v2.5'))
@@ -149,7 +150,7 @@ Here are the operations that need read permission only.
149
150
  g.config # returns whole config hash
150
151
 
151
152
  g.tags # returns array of Git::Tag objects
152
-
153
+
153
154
  g.show()
154
155
  g.show('HEAD')
155
156
  g.show('v2.8', 'README.md')
@@ -178,9 +179,11 @@ And here are the operations that will need to write to your git repository.
178
179
  g.add('file_path') # git add -- "file_path"
179
180
  g.add(['file_path_1', 'file_path_2']) # git add -- "file_path_1" "file_path_2"
180
181
 
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"
184
187
 
185
188
  g.commit('message')
186
189
  g.commit_all('message')
data/VERSION CHANGED
@@ -1 +1,2 @@
1
- 1.2.9.1
1
+ 1.3.0
2
+
@@ -1,12 +1,12 @@
1
1
  module Git
2
-
2
+
3
3
  # object that holds the last X commits on given branch
4
4
  class Diff
5
5
  include Enumerable
6
-
6
+
7
7
  def initialize(base, from = nil, to = nil)
8
8
  @base = base
9
- @from = from && from.to_s
9
+ @from = from && from.to_s
10
10
  @to = to && to.to_s
11
11
 
12
12
  @path = nil
@@ -15,60 +15,64 @@ module Git
15
15
  @stats = nil
16
16
  end
17
17
  attr_reader :from, :to
18
-
18
+
19
+ def name_status
20
+ cache_name_status
21
+ end
22
+
19
23
  def path(path)
20
24
  @path = path
21
25
  return self
22
26
  end
23
-
27
+
24
28
  def size
25
29
  cache_stats
26
30
  @stats[:total][:files]
27
31
  end
28
-
32
+
29
33
  def lines
30
34
  cache_stats
31
35
  @stats[:total][:lines]
32
36
  end
33
-
37
+
34
38
  def deletions
35
39
  cache_stats
36
40
  @stats[:total][:deletions]
37
41
  end
38
-
42
+
39
43
  def insertions
40
44
  cache_stats
41
45
  @stats[:total][:insertions]
42
46
  end
43
-
47
+
44
48
  def stats
45
49
  cache_stats
46
50
  @stats
47
51
  end
48
-
52
+
49
53
  # if file is provided and is writable, it will write the patch into the file
50
54
  def patch(file = nil)
51
55
  cache_full
52
56
  @full_diff
53
57
  end
54
58
  alias_method :to_s, :patch
55
-
59
+
56
60
  # enumerable methods
57
-
61
+
58
62
  def [](key)
59
63
  process_full
60
64
  @full_diff_files.assoc(key)[1]
61
65
  end
62
-
66
+
63
67
  def each(&block) # :yields: each Git::DiffFile in turn
64
68
  process_full
65
69
  @full_diff_files.map { |file| file[1] }.each(&block)
66
70
  end
67
-
71
+
68
72
  class DiffFile
69
73
  attr_accessor :patch, :path, :mode, :src, :dst, :type
70
74
  @base = nil
71
-
75
+
72
76
  def initialize(base, hash)
73
77
  @base = base
74
78
  @patch = hash[:patch]
@@ -83,7 +87,7 @@ module Git
83
87
  def binary?
84
88
  !!@binary
85
89
  end
86
-
90
+
87
91
  def blob(type = :dst)
88
92
  if type == :src
89
93
  @base.object(@src) if @src != '0000000'
@@ -92,28 +96,27 @@ module Git
92
96
  end
93
97
  end
94
98
  end
95
-
99
+
96
100
  private
97
-
101
+
98
102
  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})
102
104
  end
103
-
105
+
104
106
  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
109
110
  end
110
-
111
+
111
112
  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})
115
114
  end
116
-
115
+
116
+ def cache_name_status
117
+ @name_status ||= @base.lib.diff_name_status(@from, @to, {:path => @path})
118
+ end
119
+
117
120
  # break up @diff_full
118
121
  def process_full_diff
119
122
  defaults = {
@@ -124,7 +127,11 @@ module Git
124
127
  }
125
128
  final = {}
126
129
  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|
128
135
  if m = /^diff --git a\/(.*?) b\/(.*?)/.match(line)
129
136
  current_file = m[1]
130
137
  final[current_file] = defaults.merge({:patch => line, :path => current_file})
@@ -141,11 +148,11 @@ module Git
141
148
  if m = /^Binary files /.match(line)
142
149
  final[current_file][:binary] = true
143
150
  end
144
- final[current_file][:patch] << "\n" + line
151
+ final[current_file][:patch] << "\n" + line
145
152
  end
146
153
  end
147
154
  final.map { |e| [e[0], DiffFile.new(@base, e[1])] }
148
155
  end
149
-
156
+
150
157
  end
151
158
  end
@@ -1,12 +1,12 @@
1
1
  require 'tempfile'
2
2
 
3
3
  module Git
4
-
5
- class GitExecuteError < StandardError
4
+
5
+ class GitExecuteError < StandardError
6
6
  end
7
-
7
+
8
8
  class Lib
9
-
9
+
10
10
  @@semaphore = Mutex.new
11
11
 
12
12
  def initialize(base = nil, logger = nil)
@@ -14,14 +14,14 @@ module Git
14
14
  @git_index_file = nil
15
15
  @git_work_dir = nil
16
16
  @path = nil
17
-
17
+
18
18
  if base.is_a?(Git::Base)
19
19
  @git_dir = base.repo.path
20
20
  @git_index_file = base.index.path if base.index
21
21
  @git_work_dir = base.dir.path if base.dir
22
22
  elsif base.is_a?(Hash)
23
23
  @git_dir = base[:repository]
24
- @git_index_file = base[:index]
24
+ @git_index_file = base[:index]
25
25
  @git_work_dir = base[:working_directory]
26
26
  end
27
27
  @logger = logger
@@ -39,7 +39,7 @@ module Git
39
39
 
40
40
  command('init', arr_opts, false)
41
41
  end
42
-
42
+
43
43
  # tries to clone the given repo
44
44
  #
45
45
  # returns {:repository} (if bare)
@@ -53,13 +53,13 @@ module Git
53
53
  # :path:: directory where the repo will be cloned
54
54
  # :remote:: name of remote (rather than 'origin')
55
55
  # :recursive:: after the clone is created, initialize all submodules within, using their default settings.
56
- #
56
+ #
57
57
  # TODO - make this work with SSH password or auth_key
58
58
  #
59
59
  def clone(repository, name, opts = {})
60
60
  @path = opts[:path] || '.'
61
61
  clone_dir = opts[:path] ? File.join(@path, name) : name
62
-
62
+
63
63
  arr_opts = []
64
64
  arr_opts << '--bare' if opts[:bare]
65
65
  arr_opts << '--branch' << opts[:branch] if opts[:branch]
@@ -72,15 +72,15 @@ module Git
72
72
 
73
73
  arr_opts << repository
74
74
  arr_opts << clone_dir
75
-
75
+
76
76
  command('clone', arr_opts)
77
-
77
+
78
78
  opts[:bare] ? {:repository => clone_dir} : {:working_directory => clone_dir}
79
79
  end
80
-
81
-
80
+
81
+
82
82
  ## READ COMMANDS ##
83
-
83
+
84
84
  #
85
85
  # Returns most recent tag that is reachable from a commit
86
86
  #
@@ -111,14 +111,14 @@ module Git
111
111
  arr_opts << '--long' if opts[:long]
112
112
  arr_opts << '--always' if opts[:always]
113
113
  arr_opts << '--exact-match' if opts[:exact_match] || opts[:"exact-match"]
114
-
114
+
115
115
  arr_opts << '--dirty' if opts['dirty'] == true
116
116
  arr_opts << "--dirty=#{opts['dirty']}" if opts['dirty'].is_a?(String)
117
117
 
118
118
  arr_opts << "--abbrev=#{opts['abbrev']}" if opts[:abbrev]
119
119
  arr_opts << "--candidates=#{opts['candidates']}" if opts[:candidates]
120
120
  arr_opts << "--match=#{opts['match']}" if opts[:match]
121
-
121
+
122
122
  arr_opts << committish if committish
123
123
 
124
124
  return command('describe', arr_opts)
@@ -126,27 +126,27 @@ module Git
126
126
 
127
127
  def log_commits(opts={})
128
128
  arr_opts = log_common_options(opts)
129
-
129
+
130
130
  arr_opts << '--pretty=oneline'
131
-
131
+
132
132
  arr_opts += log_path_options(opts)
133
133
 
134
134
  command_lines('log', arr_opts, true).map { |l| l.split.first }
135
135
  end
136
-
136
+
137
137
  def full_log_commits(opts={})
138
138
  arr_opts = log_common_options(opts)
139
-
139
+
140
140
  arr_opts << '--pretty=raw'
141
141
  arr_opts << "--skip=#{opts[:skip]}" if opts[:skip]
142
-
142
+
143
143
  arr_opts += log_path_options(opts)
144
-
144
+
145
145
  full_log = command_lines('log', arr_opts, true)
146
146
 
147
147
  process_commit_log_data(full_log)
148
148
  end
149
-
149
+
150
150
  def revparse(string)
151
151
  return string if string =~ /^[A-Fa-f0-9]{40}$/ # passing in a sha - just no-op it
152
152
  rev = ['head', 'remotes', 'tags'].map do |d|
@@ -157,33 +157,33 @@ module Git
157
157
  return File.read(rev).chomp if rev
158
158
  command('rev-parse', string)
159
159
  end
160
-
160
+
161
161
  def namerev(string)
162
162
  command('name-rev', string).split[1]
163
163
  end
164
-
164
+
165
165
  def object_type(sha)
166
166
  command('cat-file', ['-t', sha])
167
167
  end
168
-
168
+
169
169
  def object_size(sha)
170
170
  command('cat-file', ['-s', sha]).to_i
171
171
  end
172
-
172
+
173
173
  # returns useful array of raw commit object data
174
174
  def commit_data(sha)
175
175
  sha = sha.to_s
176
176
  cdata = command_lines('cat-file', ['commit', sha])
177
177
  process_commit_data(cdata, sha, 0)
178
178
  end
179
-
179
+
180
180
  def process_commit_data(data, sha = nil, indent = 4)
181
181
  hsh = {
182
182
  'sha' => sha,
183
183
  'message' => '',
184
184
  'parent' => []
185
185
  }
186
-
186
+
187
187
  loop do
188
188
  key, *value = data.shift.split
189
189
 
@@ -195,7 +195,7 @@ module Git
195
195
  hsh[key] = value.join(' ')
196
196
  end
197
197
  end
198
-
198
+
199
199
  hsh['message'] = data.collect {|line| line[indent..-1]}.join("\n") + "\n"
200
200
 
201
201
  return hsh
@@ -220,27 +220,27 @@ module Git
220
220
 
221
221
  hsh[key] = value.join(' ')
222
222
  end
223
-
223
+
224
224
  hsh['message'] = data.collect {|line| line[indent..-1]}.join("\n") + "\n"
225
225
 
226
226
  return hsh
227
227
  end
228
-
228
+
229
229
  def process_commit_log_data(data)
230
230
  in_message = false
231
-
232
- hsh_array = []
231
+
232
+ hsh_array = []
233
233
 
234
234
  hsh = nil
235
-
235
+
236
236
  data.each do |line|
237
237
  line = line.chomp
238
-
238
+
239
239
  if line[0].nil?
240
- in_message = !in_message
240
+ in_message = !in_message
241
241
  next
242
242
  end
243
-
243
+
244
244
  if in_message
245
245
  hsh['message'] << "#{line[4..-1]}\n"
246
246
  next
@@ -248,7 +248,7 @@ module Git
248
248
 
249
249
  key, *value = line.split
250
250
  value = value.join(' ')
251
-
251
+
252
252
  case key
253
253
  when 'commit'
254
254
  hsh_array << hsh if hsh
@@ -259,36 +259,36 @@ module Git
259
259
  hsh[key] = value
260
260
  end
261
261
  end
262
-
262
+
263
263
  hsh_array << hsh if hsh
264
-
264
+
265
265
  return hsh_array
266
266
  end
267
-
267
+
268
268
  def object_contents(sha, &block)
269
269
  command('cat-file', ['-p', sha], &block)
270
270
  end
271
271
 
272
272
  def ls_tree(sha)
273
273
  data = {'blob' => {}, 'tree' => {}}
274
-
274
+
275
275
  command_lines('ls-tree', sha).each do |line|
276
276
  (info, filenm) = line.split("\t")
277
277
  (mode, type, sha) = info.split
278
278
  data[type][filenm] = {:mode => mode, :sha => sha}
279
279
  end
280
-
280
+
281
281
  data
282
282
  end
283
283
 
284
284
  def mv(file1, file2)
285
285
  command_lines('mv', ['--', file1, file2])
286
286
  end
287
-
287
+
288
288
  def full_tree(sha)
289
289
  command_lines('ls-tree', ['-r', sha])
290
290
  end
291
-
291
+
292
292
  def tree_depth(sha)
293
293
  full_tree(sha).size
294
294
  end
@@ -296,10 +296,10 @@ module Git
296
296
  def change_head_branch(branch_name)
297
297
  command('symbolic-ref', ['HEAD', "refs/heads/#{branch_name}"])
298
298
  end
299
-
299
+
300
300
  def branches_all
301
301
  arr = []
302
- command_lines('branch', '-a').each do |b|
302
+ command_lines('branch', '-a').each do |b|
303
303
  current = (b[0, 2] == '* ')
304
304
  arr << [b.gsub('* ', '').strip, current]
305
305
  end
@@ -312,7 +312,7 @@ module Git
312
312
  Dir.chdir(dir) { files = Dir.glob('**/*').select { |f| File.file?(f) } } rescue nil
313
313
  files
314
314
  end
315
-
315
+
316
316
  def branch_current
317
317
  branches_all.select { |b| b[1] }.first[0] rescue nil
318
318
  end
@@ -334,14 +334,14 @@ module Git
334
334
 
335
335
  hsh = {}
336
336
  command_lines('grep', grep_opts).each do |line|
337
- if m = /(.*)\:(\d+)\:(.*)/.match(line)
337
+ if m = /(.*)\:(\d+)\:(.*)/.match(line)
338
338
  hsh[m[1]] ||= []
339
- hsh[m[1]] << [m[2].to_i, m[3]]
339
+ hsh[m[1]] << [m[2].to_i, m[3]]
340
340
  end
341
341
  end
342
342
  hsh
343
343
  end
344
-
344
+
345
345
  def diff_full(obj1 = 'HEAD', obj2 = nil, opts = {})
346
346
  diff_opts = ['-p']
347
347
  diff_opts << obj1
@@ -350,7 +350,7 @@ module Git
350
350
 
351
351
  command('diff', diff_opts)
352
352
  end
353
-
353
+
354
354
  def diff_stats(obj1 = 'HEAD', obj2 = nil, opts = {})
355
355
  diff_opts = ['--numstat']
356
356
  diff_opts << obj1
@@ -358,7 +358,7 @@ module Git
358
358
  diff_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String
359
359
 
360
360
  hsh = {:total => {:insertions => 0, :deletions => 0, :lines => 0, :files => 0}, :files => {}}
361
-
361
+
362
362
  command_lines('diff', diff_opts).each do |file|
363
363
  (insertions, deletions, filename) = file.split("\t")
364
364
  hsh[:total][:insertions] += insertions.to_i
@@ -367,20 +367,34 @@ module Git
367
367
  hsh[:total][:files] += 1
368
368
  hsh[:files][filename] = {:insertions => insertions.to_i, :deletions => deletions.to_i}
369
369
  end
370
-
370
+
371
371
  hsh
372
372
  end
373
373
 
374
+ def diff_name_status(reference1 = nil, reference2 = nil, opts = {})
375
+ opts_arr = ['--name-status']
376
+ opts_arr << reference1 if reference1
377
+ opts_arr << reference2 if reference2
378
+
379
+ opts_arr << '--' << opts[:path] if opts[:path]
380
+
381
+ command_lines('diff', opts_arr).inject({}) do |memo, line|
382
+ status, path = line.split("\t")
383
+ memo[path] = status
384
+ memo
385
+ end
386
+ end
387
+
374
388
  # compares the index and the working directory
375
389
  def diff_files
376
390
  diff_as_hash('diff-files')
377
391
  end
378
-
392
+
379
393
  # compares the index and the repository
380
394
  def diff_index(treeish)
381
395
  diff_as_hash('diff-index', treeish)
382
396
  end
383
-
397
+
384
398
  def ls_files(location=nil)
385
399
  hsh = {}
386
400
  command_lines('ls-files', ['--stage', location]).each do |line|
@@ -436,12 +450,12 @@ module Git
436
450
  def global_config_get(name)
437
451
  command('config', ['--global', '--get', name], false)
438
452
  end
439
-
453
+
440
454
  def config_list
441
455
  build_list = lambda do |path|
442
456
  parse_config_list command_lines('config', ['--list'])
443
457
  end
444
-
458
+
445
459
  if @git_dir
446
460
  Dir.chdir(@git_dir, &build_list)
447
461
  else
@@ -452,7 +466,7 @@ module Git
452
466
  def global_config_list
453
467
  parse_config_list command_lines('config', ['--global', '--list'], false)
454
468
  end
455
-
469
+
456
470
  def parse_config_list(lines)
457
471
  hsh = {}
458
472
  lines.each do |line|
@@ -475,12 +489,12 @@ module Git
475
489
  arr_opts = []
476
490
 
477
491
  arr_opts << (path ? "#{objectish}:#{path}" : objectish)
478
-
492
+
479
493
  command('show', arr_opts.compact)
480
494
  end
481
-
495
+
482
496
  ## WRITE COMMANDS ##
483
-
497
+
484
498
  def config_set(name, value)
485
499
  command('config', [name, value])
486
500
  end
@@ -488,9 +502,9 @@ module Git
488
502
  def global_config_set(name, value)
489
503
  command('config', ['--global', name, value], false)
490
504
  end
491
-
505
+
492
506
  # updates the repository index using the working directory content
493
- #
507
+ #
494
508
  # lib.add('path/to/file')
495
509
  # lib.add(['path/to/file1','path/to/file2'])
496
510
  # lib.add(:all => true)
@@ -503,22 +517,23 @@ module Git
503
517
  # @param [Hash] options
504
518
  def add(paths='.',options={})
505
519
  arr_opts = []
506
-
520
+
507
521
  arr_opts << '--all' if options[:all]
508
522
  arr_opts << '--force' if options[:force]
509
523
 
510
- arr_opts << '--'
524
+ arr_opts << '--'
511
525
 
512
526
  arr_opts << paths
513
-
527
+
514
528
  arr_opts.flatten!
515
529
 
516
530
  command('add', arr_opts)
517
531
  end
518
-
532
+
519
533
  def remove(path = '.', opts = {})
520
534
  arr_opts = ['-f'] # overrides the up-to-date check by default
521
535
  arr_opts << ['-r'] if opts[:recursive]
536
+ arr_opts << ['--cached'] if opts[:cached]
522
537
  arr_opts << '--'
523
538
  if path.is_a?(Array)
524
539
  arr_opts += path
@@ -533,10 +548,10 @@ module Git
533
548
  arr_opts = []
534
549
  arr_opts << "--message=#{message}" if message
535
550
  arr_opts << '--amend' << '--no-edit' if opts[:amend]
536
- arr_opts << '--all' if opts[:add_all] || opts[:all]
551
+ arr_opts << '--all' if opts[:add_all] || opts[:all]
537
552
  arr_opts << '--allow-empty' if opts[:allow_empty]
538
553
  arr_opts << "--author=#{opts[:author]}" if opts[:author]
539
-
554
+
540
555
  command('commit', arr_opts)
541
556
  end
542
557
 
@@ -548,20 +563,20 @@ module Git
548
563
  end
549
564
 
550
565
  def clean(opts = {})
551
- arr_opts = []
566
+ arr_opts = []
552
567
  arr_opts << '--force' if opts[:force]
553
568
  arr_opts << '-d' if opts[:d]
554
569
  arr_opts << '-x' if opts[:x]
555
570
 
556
571
  command('clean', arr_opts)
557
572
  end
558
-
573
+
559
574
  def revert(commitish, opts = {})
560
575
  # Forcing --no-edit as default since it's not an interactive session.
561
576
  opts = {:no_edit => true}.merge(opts)
562
-
577
+
563
578
  arr_opts = []
564
- arr_opts << '--no-edit' if opts[:no_edit]
579
+ arr_opts << '--no-edit' if opts[:no_edit]
565
580
  arr_opts << commitish
566
581
 
567
582
  command('revert', arr_opts)
@@ -572,13 +587,13 @@ module Git
572
587
  arr_opts << '--' << patch_file if patch_file
573
588
  command('apply', arr_opts)
574
589
  end
575
-
590
+
576
591
  def apply_mail(patch_file)
577
592
  arr_opts = []
578
593
  arr_opts << '--' << patch_file if patch_file
579
594
  command('am', arr_opts)
580
595
  end
581
-
596
+
582
597
  def stashes_all
583
598
  arr = []
584
599
  filename = File.join(@git_dir, 'logs/refs/stash')
@@ -590,7 +605,7 @@ module Git
590
605
  end
591
606
  arr
592
607
  end
593
-
608
+
594
609
  def stash_save(message)
595
610
  output = command('stash save', ['--', message])
596
611
  output =~ /HEAD is now at/
@@ -603,29 +618,29 @@ module Git
603
618
  command('stash apply')
604
619
  end
605
620
  end
606
-
621
+
607
622
  def stash_clear
608
623
  command('stash clear')
609
624
  end
610
-
625
+
611
626
  def stash_list
612
627
  command('stash list')
613
628
  end
614
-
629
+
615
630
  def branch_new(branch)
616
631
  command('branch', branch)
617
632
  end
618
-
633
+
619
634
  def branch_delete(branch)
620
635
  command('branch', ['-D', branch])
621
636
  end
622
-
637
+
623
638
  def checkout(branch, opts = {})
624
639
  arr_opts = []
625
640
  arr_opts << '-b' if opts[:new_branch] || opts[:b]
626
641
  arr_opts << '--force' if opts[:force] || opts[:f]
627
642
  arr_opts << branch
628
-
643
+
629
644
  command('checkout', arr_opts)
630
645
  end
631
646
 
@@ -635,8 +650,8 @@ module Git
635
650
  arr_opts << file
636
651
  command('checkout', arr_opts)
637
652
  end
638
-
639
- def merge(branch, message = nil)
653
+
654
+ def merge(branch, message = nil)
640
655
  arr_opts = []
641
656
  arr_opts << '-m' << message if message
642
657
  arr_opts += [branch]
@@ -654,10 +669,10 @@ module Git
654
669
  def conflicts # :yields: file, your, their
655
670
  self.unmerged.each do |f|
656
671
  your = Tempfile.new("YOUR-#{File.basename(f)}").path
657
- command('show', ":2:#{f}", true, "> #{escape your}")
672
+ command('show', ":2:#{f}", true, "> #{escape your}")
658
673
 
659
674
  their = Tempfile.new("THEIR-#{File.basename(f)}").path
660
- command('show', ":3:#{f}", true, "> #{escape their}")
675
+ command('show', ":3:#{f}", true, "> #{escape their}")
661
676
  yield(f, your, their)
662
677
  end
663
678
  end
@@ -669,14 +684,14 @@ module Git
669
684
  arr_opts << '--'
670
685
  arr_opts << name
671
686
  arr_opts << url
672
-
687
+
673
688
  command('remote', arr_opts)
674
689
  end
675
-
690
+
676
691
  def remote_remove(name)
677
692
  command('remote', ['rm', name])
678
693
  end
679
-
694
+
680
695
  def remotes
681
696
  command_lines('remote')
682
697
  end
@@ -687,7 +702,7 @@ module Git
687
702
 
688
703
  def tag(name, *opts)
689
704
  target = opts[0].instance_of?(String) ? opts[0] : nil
690
-
705
+
691
706
  opts = opts.last.instance_of?(Hash) ? opts.last : {}
692
707
 
693
708
  if (opts[:a] || opts[:annotate]) && !(opts[:m] || opts[:message])
@@ -703,11 +718,11 @@ module Git
703
718
  arr_opts << name
704
719
  arr_opts << target if target
705
720
  arr_opts << "-m #{opts[:m] || opts[:message]}" if opts[:m] || opts[:message]
706
-
721
+
707
722
  command('tag', arr_opts)
708
723
  end
709
724
 
710
-
725
+
711
726
  def fetch(remote, opts)
712
727
  arr_opts = [remote]
713
728
  arr_opts << '--tags' if opts[:t] || opts[:tags]
@@ -715,11 +730,11 @@ module Git
715
730
 
716
731
  command('fetch', arr_opts)
717
732
  end
718
-
733
+
719
734
  def push(remote, branch = 'master', opts = {})
720
735
  # Small hack to keep backwards compatibility with the 'push(remote, branch, tags)' method signature.
721
- opts = {:tags => opts} if [true, false].include?(opts)
722
-
736
+ opts = {:tags => opts} if [true, false].include?(opts)
737
+
723
738
  arr_opts = []
724
739
  arr_opts << '--force' if opts[:force] || opts[:f]
725
740
  arr_opts << remote
@@ -735,18 +750,18 @@ module Git
735
750
  def tag_sha(tag_name)
736
751
  head = File.join(@git_dir, 'refs', 'tags', tag_name)
737
752
  return File.read(head).chomp if File.exist?(head)
738
-
753
+
739
754
  command('show-ref', ['--tags', '-s', tag_name])
740
- end
741
-
755
+ end
756
+
742
757
  def repack
743
758
  command('repack', ['-a', '-d'])
744
759
  end
745
-
760
+
746
761
  def gc
747
762
  command('gc', ['--prune', '--aggressive', '--auto'])
748
763
  end
749
-
764
+
750
765
  # reads a tree into the current index file
751
766
  def read_tree(treeish, opts = {})
752
767
  arr_opts = []
@@ -754,28 +769,28 @@ module Git
754
769
  arr_opts += [treeish]
755
770
  command('read-tree', arr_opts)
756
771
  end
757
-
772
+
758
773
  def write_tree
759
774
  command('write-tree')
760
775
  end
761
-
776
+
762
777
  def commit_tree(tree, opts = {})
763
778
  opts[:message] ||= "commit tree #{tree}"
764
779
  t = Tempfile.new('commit-message')
765
780
  t.write(opts[:message])
766
781
  t.close
767
-
782
+
768
783
  arr_opts = []
769
784
  arr_opts << tree
770
785
  arr_opts << '-p' << opts[:parent] if opts[:parent]
771
786
  arr_opts += [opts[:parents]].map { |p| ['-p', p] }.flatten if opts[:parents]
772
787
  command('commit-tree', arr_opts, true, "< #{escape t.path}")
773
788
  end
774
-
789
+
775
790
  def update_ref(branch, commit)
776
791
  command('update-ref', [branch, commit])
777
792
  end
778
-
793
+
779
794
  def checkout_index(opts = {})
780
795
  arr_opts = []
781
796
  arr_opts << "--prefix=#{opts[:prefix]}" if opts[:prefix]
@@ -785,7 +800,7 @@ module Git
785
800
 
786
801
  command('checkout-index', arr_opts)
787
802
  end
788
-
803
+
789
804
  # creates an archive file
790
805
  #
791
806
  # options
@@ -795,12 +810,12 @@ module Git
795
810
  # :path
796
811
  def archive(sha, file = nil, opts = {})
797
812
  opts[:format] ||= 'zip'
798
-
813
+
799
814
  if opts[:format] == 'tgz'
800
- opts[:format] = 'tar'
815
+ opts[:format] = 'tar'
801
816
  opts[:add_gzip] = true
802
817
  end
803
-
818
+
804
819
  if !file
805
820
  tempfile = Tempfile.new('archive')
806
821
  file = tempfile.path
@@ -839,13 +854,18 @@ module Git
839
854
 
840
855
  # Systen ENV variables involved in the git commands.
841
856
  #
842
- # @return [<String>] the names of the EVN variables involved in the git commands
857
+ # @return [<String>] the names of the EVN variables involved in the git commands
843
858
  ENV_VARIABLE_NAMES = ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_SSH']
844
-
859
+
845
860
  def command_lines(cmd, opts = [], chdir = true, redirect = '')
846
- command(cmd, opts, chdir).split("\n")
861
+ cmd_op = command(cmd, opts, chdir)
862
+ op = cmd_op.encode("UTF-8", "binary", {
863
+ :invalid => :replace,
864
+ :undef => :replace
865
+ })
866
+ op.split("\n")
847
867
  end
848
-
868
+
849
869
  # Takes the current git's system ENV variables and store them.
850
870
  def store_git_system_env_variables
851
871
  @git_system_env_variables = {}
@@ -857,7 +877,7 @@ module Git
857
877
  # Takes the previously stored git's ENV variables and set them again on ENV.
858
878
  def restore_git_system_env_variables
859
879
  ENV_VARIABLE_NAMES.each do |env_variable_name|
860
- ENV[env_variable_name] = @git_system_env_variables[env_variable_name]
880
+ ENV[env_variable_name] = @git_system_env_variables[env_variable_name]
861
881
  end
862
882
  end
863
883
 
@@ -882,26 +902,26 @@ module Git
882
902
  ensure
883
903
  restore_git_system_env_variables()
884
904
  end
885
-
905
+
886
906
  def command(cmd, opts = [], chdir = true, redirect = '', &block)
887
907
  global_opts = []
888
908
  global_opts << "--git-dir=#{@git_dir}" if !@git_dir.nil?
889
909
  global_opts << "--work-tree=#{@git_work_dir}" if !@git_work_dir.nil?
890
-
910
+
891
911
  opts = [opts].flatten.map {|s| escape(s) }.join(' ')
892
-
912
+
893
913
  global_opts = global_opts.flatten.map {|s| escape(s) }.join(' ')
894
-
914
+
895
915
  git_cmd = "#{Git::Base.config.binary_path} #{global_opts} #{cmd} #{opts} #{redirect} 2>&1"
896
-
916
+
897
917
  output = nil
898
-
899
- command_thread = nil;
900
-
918
+
919
+ command_thread = nil;
920
+
901
921
  exitstatus = nil
902
922
 
903
923
  with_custom_env_variables do
904
- command_thread = Thread.new do
924
+ command_thread = Thread.new do
905
925
  output = run_command(git_cmd, &block)
906
926
  exitstatus = $?.exitstatus
907
927
  end
@@ -912,9 +932,9 @@ module Git
912
932
  @logger.info(git_cmd)
913
933
  @logger.debug(output)
914
934
  end
915
-
935
+
916
936
  if exitstatus > 1 || (exitstatus == 1 && output != '')
917
- raise Git::GitExecuteError.new(git_cmd + ':' + output.to_s)
937
+ raise Git::GitExecuteError.new(git_cmd + ':' + output.to_s)
918
938
  end
919
939
 
920
940
  return output
@@ -929,21 +949,21 @@ module Git
929
949
  command_lines(diff_command, opts).inject({}) do |memo, line|
930
950
  info, file = line.split("\t")
931
951
  mode_src, mode_dest, sha_src, sha_dest, type = info.split
932
-
952
+
933
953
  memo[file] = {
934
- :mode_index => mode_dest,
935
- :mode_repo => mode_src.to_s[1, 7],
936
- :path => file,
937
- :sha_repo => sha_src,
938
- :sha_index => sha_dest,
954
+ :mode_index => mode_dest,
955
+ :mode_repo => mode_src.to_s[1, 7],
956
+ :path => file,
957
+ :sha_repo => sha_src,
958
+ :sha_index => sha_dest,
939
959
  :type => type
940
960
  }
941
961
 
942
962
  memo
943
963
  end
944
964
  end
945
-
946
- # Returns an array holding the common options for the log commands
965
+
966
+ # Returns an array holding the common options for the log commands
947
967
  #
948
968
  # @param [Hash] opts the given options
949
969
  # @return [Array] the set of common options that the log command will use
@@ -960,28 +980,28 @@ module Git
960
980
 
961
981
  arr_opts
962
982
  end
963
-
983
+
964
984
  # Retrurns an array holding path options for the log commands
965
985
  #
966
986
  # @param [Hash] opts the given options
967
987
  # @return [Array] the set of path options that the log command will use
968
988
  def log_path_options(opts)
969
989
  arr_opts = []
970
-
990
+
971
991
  arr_opts << opts[:object] if opts[:object].is_a? String
972
992
  arr_opts << '--' << opts[:path_limiter] if opts[:path_limiter]
973
993
  arr_opts
974
994
  end
975
-
995
+
976
996
  def run_command(git_cmd, &block)
977
997
  return IO.popen(git_cmd, &block) if block_given?
978
-
998
+
979
999
  `#{git_cmd}`.chomp
980
1000
  end
981
1001
 
982
1002
  def escape(s)
983
1003
  return "'#{s && s.to_s.gsub('\'','\'"\'"\'')}'" if RUBY_PLATFORM !~ /mingw|mswin/
984
-
1004
+
985
1005
  # Keeping the old escape format for windows users
986
1006
  escaped = s.to_s.gsub('\'', '\'\\\'\'')
987
1007
  return %Q{"#{escaped}"}
@@ -2,6 +2,6 @@ module Git
2
2
 
3
3
  # The current gem version
4
4
  # @return [String] the current gem version.
5
- VERSION='1.2.9'
5
+ VERSION='1.3.0'
6
6
 
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.9.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chacon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-13 00:00:00.000000000 Z
11
+ date: 2016-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -102,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
102
  requirements:
103
103
  - - ">="
104
104
  - !ruby/object:Gem::Version
105
- version: '0'
105
+ version: '1.9'
106
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
112
  - git 1.6.0.0, or greater
113
113
  rubyforge_project:
114
- rubygems_version: 2.4.5
114
+ rubygems_version: 2.5.0
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: Ruby/Git is a Ruby library that can be used to create, read and manipulate