schacon-git 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/git.rb +50 -0
- data/lib/git/lib.rb +63 -26
- metadata +15 -15
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
|
data/lib/git/lib.rb
CHANGED
@@ -321,46 +321,76 @@ module Git
|
|
321
321
|
end
|
322
322
|
|
323
323
|
def config_get(name)
|
324
|
-
|
325
|
-
|
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
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
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
|
355
|
+
def parse_config_list(lines)
|
341
356
|
hsh = {}
|
342
|
-
|
343
|
-
|
344
|
-
|
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,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schacon-git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Chacon
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,7 +22,7 @@ extensions: []
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README
|
24
24
|
files:
|
25
|
-
- lib/git
|
25
|
+
- lib/git.rb
|
26
26
|
- lib/git/author.rb
|
27
27
|
- lib/git/base.rb
|
28
28
|
- lib/git/branch.rb
|
@@ -39,13 +39,13 @@ files:
|
|
39
39
|
- lib/git/stashes.rb
|
40
40
|
- lib/git/status.rb
|
41
41
|
- lib/git/working_directory.rb
|
42
|
-
- lib/git.rb
|
43
42
|
- README
|
44
|
-
has_rdoc:
|
45
|
-
homepage: http://github.com/schacon/ruby-git
|
43
|
+
has_rdoc: false
|
44
|
+
homepage: http://github.com/schacon/ruby-git
|
45
|
+
licenses:
|
46
46
|
post_install_message:
|
47
|
-
rdoc_options:
|
48
|
-
|
47
|
+
rdoc_options:
|
48
|
+
- --charset=UTF-8
|
49
49
|
require_paths:
|
50
50
|
- lib
|
51
51
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -60,12 +60,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: "0"
|
62
62
|
version:
|
63
|
-
requirements:
|
64
|
-
|
65
|
-
rubyforge_project:
|
66
|
-
rubygems_version: 1.
|
63
|
+
requirements:
|
64
|
+
- git 1.6.0.0, or greater
|
65
|
+
rubyforge_project: git
|
66
|
+
rubygems_version: 1.3.5
|
67
67
|
signing_key:
|
68
|
-
specification_version:
|
69
|
-
summary:
|
68
|
+
specification_version: 3
|
69
|
+
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
|
70
70
|
test_files: []
|
71
71
|
|