File tree 5 files changed +56
-45
lines changed
5 files changed +56
-45
lines changed Original file line number Diff line number Diff line change @@ -295,6 +295,20 @@ Some examples of more low-level index and tree operations
295
295
end
296
296
```
297
297
298
+ Managing git configuration
299
+
300
+ ``` ruby
301
+ # current git project config
302
+ Git ::GitConfig .config # returns whole config hash
303
+ Git ::GitConfig .config(' user.name' ) # returns 'Scott Chacon'
304
+ Git ::GitConfig .config(' user.name' , ' Scott Chacon' ) # sets new user.name
305
+
306
+ # global config
307
+ Git ::GitConfig .global_config # returns whole global config hash
308
+ Git ::GitConfig .global_config(' user.name' ) # returns 'Scott Chacon'
309
+ Git ::GitConfig .global_config(' user.name' , ' Scott Chacon' ) # sets new user.name
310
+ ```
311
+
298
312
## License
299
313
300
314
licensed under MIT License Copyright (c) 2008 Scott Chacon. See LICENSE for further details.
Original file line number Diff line number Diff line change 9
9
require 'git/branches'
10
10
require 'git/config'
11
11
require 'git/diff'
12
+ require 'git/git_config'
12
13
require 'git/index'
13
14
require 'git/lib'
14
15
require 'git/log'
42
43
# Author:: Scott Chacon (mailto:schacon@gmail.com)
43
44
# License:: MIT License
44
45
module Git
45
-
46
- #g.config('user.name', 'Scott Chacon') # sets value
47
- #g.config('user.email', 'email@email.com') # sets value
48
- #g.config('user.name') # returns 'Scott Chacon'
49
- #g.config # returns whole config hash
50
- def config ( name = nil , value = nil )
51
- lib = Git ::Lib . new
52
- if ( name && value )
53
- # set value
54
- lib . config_set ( name , value )
55
- elsif ( name )
56
- # return value
57
- lib . config_get ( name )
58
- else
59
- # return hash
60
- lib . config_list
61
- end
62
- end
63
46
64
47
def self . configure
65
48
yield Base . config
@@ -69,10 +52,6 @@ def self.config
69
52
return Base . config
70
53
end
71
54
72
- def global_config ( name = nil , value = nil )
73
- self . class . global_config ( name , value )
74
- end
75
-
76
55
# open a bare repository
77
56
#
78
57
# this takes the path to a bare git repo
Original file line number Diff line number Diff line change 1
1
require 'git/base/factory'
2
+ require 'git/git_config'
2
3
3
4
module Git
4
5
5
6
class Base
6
7
7
8
include Git ::Base ::Factory
9
+ include Git ::GitConfig
8
10
9
11
# opens a bare Git Repository - no working directory options
10
12
def self . bare ( git_dir , opts = { } )
@@ -106,24 +108,7 @@ def chdir # :yields: the Git::Path
106
108
yield dir . path
107
109
end
108
110
end
109
-
110
- #g.config('user.name', 'Scott Chacon') # sets value
111
- #g.config('user.email', 'email@email.com') # sets value
112
- #g.config('user.name') # returns 'Scott Chacon'
113
- #g.config # returns whole config hash
114
- def config ( name = nil , value = nil )
115
- if ( name && value )
116
- # set value
117
- lib . config_set ( name , value )
118
- elsif ( name )
119
- # return value
120
- lib . config_get ( name )
121
- else
122
- # return hash
123
- lib . config_list
124
- end
125
- end
126
-
111
+
127
112
# returns a reference to the working directory
128
113
# @git.dir.path
129
114
# @git.dir.writeable?
Original file line number Diff line number Diff line change
1
+ module Git
2
+ module GitConfig
3
+ extend self
4
+
5
+ #g.config('user.name', 'Scott Chacon') # sets value
6
+ #g.config('user.email', 'email@email.com') # sets value
7
+ #g.config('user.name') # returns 'Scott Chacon'
8
+ #g.config # returns whole config hash
9
+ def config ( name = nil , value = nil )
10
+ if ( name && value )
11
+ # set value
12
+ lib . config_set ( name , value )
13
+ elsif ( name )
14
+ # return value
15
+ lib . config_get ( name )
16
+ else
17
+ # return hash
18
+ lib . config_list
19
+ end
20
+ end
21
+
22
+ def global_config ( name = nil , value = nil )
23
+ Git . global_config ( name , value )
24
+ end
25
+
26
+ class << self
27
+ private
28
+
29
+ def lib
30
+ @lib ||= Git ::Lib . new
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ # Git::GitConfig.config
Original file line number Diff line number Diff line change 2
2
3
3
require File . dirname ( __FILE__ ) + '/../test_helper'
4
4
5
- class TestConfigModule < Test ::Unit ::TestCase
5
+ class TestGitConfig < Test ::Unit ::TestCase
6
6
def setup
7
7
set_file_paths
8
- git_class = Class . new do
9
- include Git
10
- end
11
- @git = git_class . new
8
+ @git = Git ::GitConfig
12
9
@old_dir = Dir . pwd
13
10
Dir . chdir ( @wdir )
14
11
end
You can’t perform that action at this time.
0 commit comments