scm 0.1.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,355 @@
1
+ require 'scm/util'
2
+
3
+ require 'pathname'
4
+
5
+ module SCM
6
+ class Repository
7
+
8
+ include Util
9
+
10
+ # The path of the repository
11
+ attr_reader :path
12
+
13
+ #
14
+ # Creates a new repository.
15
+ #
16
+ # @param [String] path
17
+ # The path to the repository.
18
+ #
19
+ def initialize(path)
20
+ @path = Pathname.new(File.expand_path(path))
21
+ end
22
+
23
+ #
24
+ # Creates a new repository.
25
+ #
26
+ # @param [String] path
27
+ # Path to the repository.
28
+ #
29
+ # @param [Hash] options
30
+ # Additional options.
31
+ #
32
+ # @return [Repository]
33
+ # The newly created repository.
34
+ #
35
+ # @abstract
36
+ #
37
+ def self.create(path,options={})
38
+ new(path)
39
+ end
40
+
41
+ #
42
+ # Clones a remote repository.
43
+ #
44
+ # @param [URI, String] uri
45
+ # The URI of the remote repository.
46
+ #
47
+ # @param [Hash] options
48
+ # Additional options.
49
+ #
50
+ # @return [Boolean]
51
+ # Specifies whether the clone was successful.
52
+ #
53
+ # @abstract
54
+ #
55
+ def self.clone(uri,options={})
56
+ false
57
+ end
58
+
59
+ #
60
+ # Queries the status of the files.
61
+ #
62
+ # @param [Array] paths
63
+ # The optional paths to query.
64
+ #
65
+ # @return [Hash{String => Symbol}]
66
+ # The file paths and their statuses.
67
+ #
68
+ # @abstract
69
+ #
70
+ def status(*paths)
71
+ {}
72
+ end
73
+
74
+ #
75
+ # Adds files or directories to the repository.
76
+ #
77
+ # @param [Array] paths
78
+ # The paths of the files/directories to add.
79
+ #
80
+ # @abstract
81
+ #
82
+ def add(*paths)
83
+ end
84
+
85
+ #
86
+ # Moves a file or directory.
87
+ #
88
+ # @param [String] source
89
+ # The path of the source file/directory.
90
+ #
91
+ # @param [String] dest
92
+ # The new destination path.
93
+ #
94
+ # @param [Boolean] force
95
+ # Specifies whether to force the move.
96
+ #
97
+ # @abstract
98
+ #
99
+ def move(source,dest,force=false)
100
+ end
101
+
102
+ #
103
+ # Removes files or directories.
104
+ #
105
+ # @param [String, Array] paths
106
+ # The path(s) to remove.
107
+ #
108
+ # @param [Hash] options
109
+ # Additional options.
110
+ #
111
+ # @option options [Boolean] :force (false)
112
+ # Specifies whether to forcibly remove the files/directories.
113
+ #
114
+ # @option options [Boolean] :recursive (false)
115
+ # Specifies whether to recursively remove the files/directories.
116
+ #
117
+ # @abstract
118
+ #
119
+ def remove(paths,options={})
120
+ end
121
+
122
+ #
123
+ # Makes a commit.
124
+ #
125
+ # @param [String] message
126
+ # The message for the commit.
127
+ #
128
+ # @param [Hash] options
129
+ # Commit options.
130
+ #
131
+ # @option options [String] :paths
132
+ # The path of the file to commit.
133
+ #
134
+ # @return [Boolean]
135
+ # Specifies whether the commit was successfully made.
136
+ #
137
+ # @abstract
138
+ #
139
+ def commit(message=nil,options={})
140
+ false
141
+ end
142
+
143
+ #
144
+ # Lists branches.
145
+ #
146
+ # @return [Array<String>]
147
+ # The branch names.
148
+ #
149
+ # @abstract
150
+ #
151
+ def branches
152
+ []
153
+ end
154
+
155
+ #
156
+ # The current branch.
157
+ #
158
+ # @return [String]
159
+ # The name of the current branch.
160
+ #
161
+ # @abstract
162
+ #
163
+ def current_branch
164
+ end
165
+
166
+ #
167
+ # Swtiches to a branch.
168
+ #
169
+ # @param [String, Symbol] name
170
+ # The name of the branch to switch to.
171
+ #
172
+ # @return [Boolean]
173
+ # Specifies whether the branch was successfully switched.
174
+ #
175
+ # @abstract
176
+ #
177
+ def switch_branch(name)
178
+ false
179
+ end
180
+
181
+ #
182
+ # Deletes a branch.
183
+ #
184
+ # @param [String] name
185
+ # The name of the branch to delete.
186
+ #
187
+ # @return [Boolean]
188
+ # Specifies whether the branch was successfully deleted.
189
+ #
190
+ # @abstract
191
+ #
192
+ def delete_branch(name)
193
+ false
194
+ end
195
+
196
+ #
197
+ # Lists tags.
198
+ #
199
+ # @return [Array<String>]
200
+ # The tag names.
201
+ #
202
+ # @abstract
203
+ #
204
+ def tags
205
+ []
206
+ end
207
+
208
+ #
209
+ # Tags a release.
210
+ #
211
+ # @param [String] name
212
+ # The name for the tag.
213
+ #
214
+ # @param [String] commit
215
+ # The specific commit to make the tag at.
216
+ #
217
+ # @return [Boolean]
218
+ # Specifies whether the tag was successfully created.
219
+ #
220
+ # @abstract
221
+ #
222
+ def tag(name,commit=nil)
223
+ false
224
+ end
225
+
226
+ #
227
+ # Deletes a tag.
228
+ #
229
+ # @param [String] name
230
+ # The name of the tag.
231
+ #
232
+ # @return [Boolean]
233
+ # Specifies whether the tag was successfully deleted.
234
+ #
235
+ # @abstract
236
+ #
237
+ def delete_tag(name)
238
+ false
239
+ end
240
+
241
+ #
242
+ # Prints a log of commits.
243
+ #
244
+ # @param [String] :commit
245
+ # Commit to begin the log at.
246
+ #
247
+ # @param [String] :paths
248
+ # File to list commits for.
249
+ #
250
+ # @abstract
251
+ #
252
+ def log(options={})
253
+ false
254
+ end
255
+
256
+ #
257
+ # Pushes changes to the remote repository.
258
+ #
259
+ # @param [Hash] options
260
+ # Additional options.
261
+ #
262
+ # @return [Boolean]
263
+ # Specifies whether the changes were successfully pushed.
264
+ #
265
+ # @abstract
266
+ #
267
+ def push(options={})
268
+ false
269
+ end
270
+
271
+ #
272
+ # Pulls changes from the remote repository.
273
+ #
274
+ # @param [Hash] options
275
+ # Additional options.
276
+ #
277
+ # @return [Boolean]
278
+ # Specifies whether the changes were successfully pulled.
279
+ #
280
+ # @abstract
281
+ #
282
+ def pull(options={})
283
+ false
284
+ end
285
+
286
+ #
287
+ # Lists commits.
288
+ #
289
+ # @param [Hash] options
290
+ # Additional options.
291
+ #
292
+ # @return [Enumerator<SCM::Commit>]
293
+ # The commits within the repository.
294
+ #
295
+ # @raise [NotImplementedError]
296
+ # If a subclass does not provide its own implementation.
297
+ #
298
+ # @abstract
299
+ #
300
+ def commits(options={})
301
+ raise(NotImplementedError,"This method is not implemented for #{self.class}")
302
+ end
303
+
304
+ #
305
+ # Converts the repository to a String.
306
+ #
307
+ # @return [String]
308
+ # The path of the repository.
309
+ #
310
+ def to_s
311
+ @path.to_s
312
+ end
313
+
314
+ protected
315
+
316
+ #
317
+ # Runs a command within the repository.
318
+ #
319
+ # @param [Symbol] command
320
+ # The command to run.
321
+ #
322
+ # @param [Array] arguments
323
+ # Additional arguments to pass to the command.
324
+ #
325
+ # @return [Boolean]
326
+ # Specifies whether the SVN command exited successfully.
327
+ #
328
+ def run(command,*arguments)
329
+ Dir.chdir(@path) { super(command,*arguments) }
330
+ end
331
+
332
+ #
333
+ # Runs a command as a separate process.
334
+ #
335
+ # @param [Symbol] command
336
+ # The command to run.
337
+ #
338
+ # @param [Array] arguments
339
+ # Additional arguments to pass to the command.
340
+ #
341
+ # @yield [line]
342
+ # The given block will be passed each line read-in.
343
+ #
344
+ # @yieldparam [String] line
345
+ # A line read from the program.
346
+ #
347
+ # @return [IO]
348
+ # The stdout of the command being ran.
349
+ #
350
+ def popen(command,*arguments)
351
+ Dir.chdir(@path) { super(command,*arguments) }
352
+ end
353
+
354
+ end
355
+ end
data/lib/scm/scm.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'scm/git'
2
+ require 'scm/hg'
3
+ require 'scm/svn'
4
+
5
+ module SCM
6
+ # SCM control directories and the SCM classes
7
+ DIRS = {
8
+ '.git' => Git,
9
+ '.hg' => Hg,
10
+ '.svn' => SVN
11
+ }
12
+
13
+ #
14
+ # Determines the SCM used for a repository.
15
+ #
16
+ # @param [String] path
17
+ # The path of the repository.
18
+ #
19
+ # @return [Repository]
20
+ # The SCM repository.
21
+ #
22
+ # @raise [RuntimeError]
23
+ # The exact SCM could not be determined.
24
+ #
25
+ def SCM.new(path)
26
+ path = File.expand_path(path)
27
+
28
+ DIRS.each do |name,repo|
29
+ dir = File.join(path,name)
30
+
31
+ return repo.new(path) if File.directory?(dir)
32
+ end
33
+
34
+ raise("could not determine the SCM of #{path.dump}")
35
+ end
36
+ end