1
+ require 'git/base/factories'
2
+
1
3
module Git
2
4
3
5
class Base
4
6
7
+ include Git ::Base ::Factories
8
+
5
9
# opens a bare Git Repository - no working directory options
6
10
def self . bare ( git_dir , opts = { } )
7
11
self . new ( { :repository => git_dir } . merge ( opts ) )
8
12
end
9
13
10
- # opens a new Git Project from a working directory
11
- # you can specify non-standard git_dir and index file in the options
12
- def self . open ( working_dir , opts = { } )
13
- self . new ( { :working_directory => working_dir } . merge ( opts ) )
14
+ # clones a git repository locally
15
+ #
16
+ # repository - http://repo.or.cz/w/sinatra.git
17
+ # name - sinatra
18
+ #
19
+ # options:
20
+ # :repository
21
+ #
22
+ # :bare
23
+ # or
24
+ # :working_directory
25
+ # :index_file
26
+ #
27
+ def self . clone ( repository , name , opts = { } )
28
+ # run git-clone
29
+ self . new ( Git ::Lib . new . clone ( repository , name , opts ) )
30
+ end
31
+
32
+ # Returns (and initialize if needed) a Git::Config instance
33
+ #
34
+ # @return [Git::Config] the current config instance.
35
+ def self . config
36
+ return @@config ||= Config . new
14
37
end
15
38
16
39
# initializes a git repository
@@ -36,25 +59,13 @@ def self.init(working_dir, opts = {})
36
59
37
60
self . new ( opts )
38
61
end
39
-
40
- # clones a git repository locally
41
- #
42
- # repository - http://repo.or.cz/w/sinatra.git
43
- # name - sinatra
44
- #
45
- # options:
46
- # :repository
47
- #
48
- # :bare
49
- # or
50
- # :working_directory
51
- # :index_file
52
- #
53
- def self . clone ( repository , name , opts = { } )
54
- # run git-clone
55
- self . new ( Git ::Lib . new . clone ( repository , name , opts ) )
62
+
63
+ # opens a new Git Project from a working directory
64
+ # you can specify non-standard git_dir and index file in the options
65
+ def self . open ( working_dir , opts = { } )
66
+ self . new ( { :working_directory => working_dir } . merge ( opts ) )
56
67
end
57
-
68
+
58
69
def initialize ( options = { } )
59
70
if working_dir = options [ :working_directory ]
60
71
options [ :repository ] ||= File . join ( working_dir , '.git' )
@@ -71,36 +82,6 @@ def initialize(options = {})
71
82
@repository = options [ :repository ] ? Git ::Repository . new ( options [ :repository ] ) : nil
72
83
@index = options [ :index ] ? Git ::Index . new ( options [ :index ] , false ) : nil
73
84
end
74
-
75
-
76
- # returns a reference to the working directory
77
- # @git.dir.path
78
- # @git.dir.writeable?
79
- def dir
80
- @working_directory
81
- end
82
-
83
- # returns reference to the git repository directory
84
- # @git.dir.path
85
- def repo
86
- @repository
87
- end
88
-
89
- # returns reference to the git index file
90
- def index
91
- @index
92
- end
93
-
94
-
95
- def set_working ( work_dir , check = true )
96
- @lib = nil
97
- @working_directory = Git ::WorkingDirectory . new ( work_dir . to_s , check )
98
- end
99
-
100
- def set_index ( index_file , check = true )
101
- @lib = nil
102
- @index = Git ::Index . new ( index_file . to_s , check )
103
- end
104
85
105
86
# changes current working directory for a block
106
87
# to the git working directory
@@ -117,13 +98,6 @@ def chdir # :yields: the Git::Path
117
98
end
118
99
end
119
100
120
- # returns the repository size in bytes
121
- def repo_size
122
- Dir . chdir ( repo . path ) do
123
- return `du -s` . chomp . split . first . to_i
124
- end
125
- end
126
-
127
101
#g.config('user.name', 'Scott Chacon') # sets value
128
102
#g.config('user.email', 'email@email.com') # sets value
129
103
#g.config('user.name') # returns 'Scott Chacon'
@@ -140,56 +114,43 @@ def config(name = nil, value = nil)
140
114
lib . config_list
141
115
end
142
116
end
143
-
144
- def self . config
145
- return @@config ||= Config . new
117
+
118
+ # returns a reference to the working directory
119
+ # @git.dir.path
120
+ # @git.dir.writeable?
121
+ def dir
122
+ @working_directory
146
123
end
147
124
148
- # factory methods
149
-
150
- # returns a Git::Object of the appropriate type
151
- # you can also call @git.gtree('tree'), but that's
152
- # just for readability. If you call @git.gtree('HEAD') it will
153
- # still return a Git::Object::Commit object.
154
- #
155
- # @git.object calls a factory method that will run a rev-parse
156
- # on the objectish and determine the type of the object and return
157
- # an appropriate object for that type
158
- def object ( objectish )
159
- Git ::Object . new ( self , objectish )
125
+ # returns reference to the git index file
126
+ def index
127
+ @index
160
128
end
161
-
162
- def gtree ( objectish )
163
- Git ::Object . new ( self , objectish , 'tree' )
129
+
130
+ # returns reference to the git repository directory
131
+ # @git.dir.path
132
+ def repo
133
+ @repository
164
134
end
165
135
166
- def gcommit ( objectish )
167
- Git ::Object . new ( self , objectish , 'commit' )
136
+ # returns the repository size in bytes
137
+ def repo_size
138
+ Dir . chdir ( repo . path ) do
139
+ return `du -s` . chomp . split . first . to_i
140
+ end
168
141
end
169
142
170
- def gblob ( objectish )
171
- Git ::Object . new ( self , objectish , 'blob' )
143
+ def set_index ( index_file , check = true )
144
+ @lib = nil
145
+ @index = Git ::Index . new ( index_file . to_s , check )
172
146
end
173
147
174
- # returns a Git::Log object with count commits
175
- def log ( count = 30 )
176
- Git ::Log . new ( self , count )
148
+ def set_working ( work_dir , check = true )
149
+ @lib = nil
150
+ @working_directory = Git ::WorkingDirectory . new ( work_dir . to_s , check )
177
151
end
178
152
179
- # returns a Git::Status object
180
- def status
181
- Git ::Status . new ( self )
182
- end
183
-
184
- # returns a Git::Branches object of all the Git::Branch objects for this repo
185
- def branches
186
- Git ::Branches . new ( self )
187
- end
188
-
189
- # returns a Git::Branch object for branch_name
190
- def branch ( branch_name = 'master' )
191
- Git ::Branch . new ( self , branch_name )
192
- end
153
+
193
154
194
155
# returns +true+ if the branch exists locally
195
156
def is_local_branch? ( branch )
0 commit comments