git 1.1.1 → 1.2.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.

Files changed (3) hide show
  1. data/lib/git.rb +50 -0
  2. data/lib/git/lib.rb +63 -26
  3. metadata +9 -7
data/lib/git.rb CHANGED
@@ -26,6 +26,14 @@ require 'git/author'
26
26
  require 'git/stashes'
27
27
  require 'git/stash'
28
28
 
29
+ minimum_version = [1, 6, 0, 0]
30
+ current_version = Git::Lib.new(nil, nil).command_version
31
+ if current_version[0] < minimum_version[0] ||
32
+ current_version[1] < minimum_version[1] ||
33
+ current_version[2] < minimum_version[2] ||
34
+ current_version[3] < minimum_version[3]
35
+ $stderr.puts "The git gem requires git #{minimum_version.join('.')} or later, but only found #{current_version.join('.')}. You should probably upgrad.e"
36
+ end
29
37
 
30
38
  # Git/Ruby Library
31
39
  #
@@ -106,5 +114,47 @@ module Git
106
114
  repo.checkout("origin/#{options[:branch]}") if options[:branch]
107
115
  Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' }
108
116
  end
117
+
118
+ #g.config('user.name', 'Scott Chacon') # sets value
119
+ #g.config('user.email', 'email@email.com') # sets value
120
+ #g.config('user.name') # returns 'Scott Chacon'
121
+ #g.config # returns whole config hash
122
+ def config(name = nil, value = nil)
123
+ lib = Git::Lib.new
124
+ if(name && value)
125
+ # set value
126
+ lib.config_set(name, value)
127
+ elsif (name)
128
+ # return value
129
+ lib.config_get(name)
130
+ else
131
+ # return hash
132
+ lib.config_list
133
+ end
134
+ end
135
+
136
+ # Same as g.config, but forces it to be at the global level
137
+ #
138
+ #g.config('user.name', 'Scott Chacon') # sets value
139
+ #g.config('user.email', 'email@email.com') # sets value
140
+ #g.config('user.name') # returns 'Scott Chacon'
141
+ #g.config # returns whole config hash
142
+ def self.global_config(name = nil, value = nil)
143
+ lib = Git::Lib.new(nil, nil)
144
+ if(name && value)
145
+ # set value
146
+ lib.global_config_set(name, value)
147
+ elsif (name)
148
+ # return value
149
+ lib.global_config_get(name)
150
+ else
151
+ # return hash
152
+ lib.global_config_list
153
+ end
154
+ end
155
+
156
+ def global_config(name = nil, value = nil)
157
+ self.class.global_config(name, value)
158
+ end
109
159
 
110
160
  end
@@ -321,46 +321,76 @@ module Git
321
321
  end
322
322
 
323
323
  def config_get(name)
324
- config_list[name]
325
- #command('config', ['--get', name])
324
+ do_get = lambda do
325
+ command('config', ['--get', name])
326
+ end
327
+
328
+ if @git_dir
329
+ Dir.chdir(@git_dir, &do_get)
330
+ else
331
+ build_list.call
332
+ end
333
+ end
334
+
335
+ def global_config_get(name)
336
+ command('config', ['--global', '--get', name], false)
326
337
  end
327
338
 
328
339
  def config_list
329
- config = {}
330
- config.merge!(parse_config('~/.gitconfig'))
331
- config.merge!(parse_config(File.join(@git_dir, 'config')))
332
- #hsh = {}
333
- #command_lines('config', ['--list']).each do |line|
334
- # (key, value) = line.split('=')
335
- # hsh[key] = value
336
- #end
337
- #hsh
340
+ build_list = lambda do
341
+ parse_config_list command_lines('config', ['--list'])
342
+ end
343
+
344
+ if @git_dir
345
+ Dir.chdir(@git_dir, &build_list)
346
+ else
347
+ build_list.call
348
+ end
349
+ end
350
+
351
+ def global_config_list
352
+ parse_config_list command_lines('config', ['--global', '--list'], false)
338
353
  end
339
354
 
340
- def parse_config(file)
355
+ def parse_config_list(lines)
341
356
  hsh = {}
342
- file = File.expand_path(file)
343
- if File.file?(file)
344
- current_section = nil
345
- File.readlines(file).each do |line|
346
- if m = /\[(\w+)\]/.match(line)
347
- current_section = m[1]
348
- elsif m = /\[(\w+?) "(.*?)"\]/.match(line)
349
- current_section = "#{m[1]}.#{m[2]}"
350
- elsif m = /(\w+?) = (.*)/.match(line)
351
- key = "#{current_section}.#{m[1]}"
352
- hsh[key] = m[2]
353
- end
354
- end
357
+ lines.each do |line|
358
+ (key, *values) = line.split('=')
359
+ hsh[key] = values.join('=')
355
360
  end
356
361
  hsh
357
362
  end
363
+
364
+ def parse_config(file)
365
+ hsh = {}
366
+ parse_config_list command_lines('config', ['--list', '--file', file], false)
367
+ #hsh = {}
368
+ #file = File.expand_path(file)
369
+ #if File.file?(file)
370
+ # current_section = nil
371
+ # File.readlines(file).each do |line|
372
+ # if m = /\[(\w+)\]/.match(line)
373
+ # current_section = m[1]
374
+ # elsif m = /\[(\w+?) "(.*?)"\]/.match(line)
375
+ # current_section = "#{m[1]}.#{m[2]}"
376
+ # elsif m = /(\w+?) = (.*)/.match(line)
377
+ # key = "#{current_section}.#{m[1]}"
378
+ # hsh[key] = m[2]
379
+ # end
380
+ # end
381
+ #end
382
+ #hsh
383
+ end
358
384
 
359
385
  ## WRITE COMMANDS ##
360
386
 
361
387
  def config_set(name, value)
362
388
  command('config', [name, value])
363
389
  end
390
+
391
+ def global_config_set(name, value)
392
+ command('config', ['--global', name, value], false)
393
+ end
364
394
 
365
395
  def add(path = '.')
366
396
  arr_opts = ['--']
@@ -613,7 +643,14 @@ module Git
613
643
  command('archive', arr_opts, true, (opts[:add_gzip] ? '| gzip' : '') + " > #{escape file}")
614
644
  return file
615
645
  end
616
-
646
+
647
+ # returns the current version of git, as an Array of Fixnums.
648
+ def command_version
649
+ output = command('version', [], false)
650
+ version = output[/(\d+)\.(\d+)\.(\d+)\.(\d+)/]
651
+ version.split('.').collect {|i| i.to_i}
652
+ end
653
+
617
654
  private
618
655
 
619
656
  def command_lines(cmd, opts = [], chdir = true, redirect = '')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chacon
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-04 00:00:00 -07:00
12
+ date: 2009-08-01 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -42,6 +42,8 @@ files:
42
42
  - README
43
43
  has_rdoc: true
44
44
  homepage: http://github.com/schacon/ruby-git
45
+ licenses: []
46
+
45
47
  post_install_message:
46
48
  rdoc_options:
47
49
  - --charset=UTF-8
@@ -59,12 +61,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
61
  - !ruby/object:Gem::Version
60
62
  version: "0"
61
63
  version:
62
- requirements: []
63
-
64
+ requirements:
65
+ - git 1.6.0.0, or greater
64
66
  rubyforge_project: git
65
- rubygems_version: 1.3.1
67
+ rubygems_version: 1.3.5
66
68
  signing_key:
67
- specification_version: 2
68
- summary: TODO
69
+ specification_version: 3
70
+ 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
69
71
  test_files: []
70
72