Skip to content

Commit 456f1b6

Browse files
Moving some Git::Base methods into the Factories module
1 parent 5f3699a commit 456f1b6

File tree

2 files changed

+44
-46
lines changed

2 files changed

+44
-46
lines changed

lib/git/base.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ def set_working(work_dir, check = true)
149149
@lib = nil
150150
@working_directory = Git::WorkingDirectory.new(work_dir.to_s, check)
151151
end
152-
153-
154152

155153
# returns +true+ if the branch exists locally
156154
def is_local_branch?(branch)
@@ -170,11 +168,6 @@ def is_branch?(branch)
170168
branch_names.include?(branch)
171169
end
172170

173-
# returns a Git::Remote object
174-
def remote(remote_name = 'origin')
175-
Git::Remote.new(self, remote_name)
176-
end
177-
178171
# this is a convenience method for accessing the class that wraps all the
179172
# actual 'git' forked system calls. At some point I hope to replace the Git::Lib
180173
# class with one that uses native methods or libgit C bindings
@@ -205,11 +198,6 @@ def grep(string, path_limiter = nil, opts = {})
205198
self.object('HEAD').grep(string, path_limiter, opts)
206199
end
207200

208-
# returns a Git::Diff object
209-
def diff(objectish = 'HEAD', obj2 = nil)
210-
Git::Diff.new(self, objectish, obj2)
211-
end
212-
213201
# updates the repository index using the workig dorectory content
214202
#
215203
# @git.add('path/to/file')
@@ -386,11 +374,6 @@ def remove_remote(name)
386374
def tags
387375
self.lib.tags.map { |r| tag(r) }
388376
end
389-
390-
# returns a Git::Tag object
391-
def tag(tag_name)
392-
Git::Object.new(self, tag_name, 'tag', true)
393-
end
394377

395378
# Creates a new git tag (Git::Tag)
396379
# Usage:
@@ -476,10 +459,6 @@ def write_tree
476459
self.lib.write_tree
477460
end
478461

479-
def commit_tree(tree = nil, opts = {})
480-
Git::Object::Commit.new(self, self.lib.commit_tree(tree, opts))
481-
end
482-
483462
def write_and_commit_tree(opts = {})
484463
tree = write_tree
485464
commit_tree(tree, opts)
@@ -537,7 +516,6 @@ def cat_file(objectish)
537516
def current_branch
538517
self.lib.branch_current
539518
end
540-
541519

542520
end
543521

lib/git/base/factories.rb

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,69 @@ module Git
33
class Base
44

55
module Factories
6+
7+
# returns a Git::Branch object for branch_name
8+
def branch(branch_name = 'master')
9+
Git::Branch.new(self, branch_name)
10+
end
611

7-
# returns a Git::Object of the appropriate type
8-
# you can also call @git.gtree('tree'), but that's
9-
# just for readability. If you call @git.gtree('HEAD') it will
10-
# still return a Git::Object::Commit object.
11-
#
12-
# @git.object calls a factory method that will run a rev-parse
13-
# on the objectish and determine the type of the object and return
14-
# an appropriate object for that type
15-
def object(objectish)
16-
Git::Object.new(self, objectish)
12+
# returns a Git::Branches object of all the Git::Branch
13+
# objects for this repo
14+
def branches
15+
Git::Branches.new(self)
1716
end
1817

19-
def gtree(objectish)
20-
Git::Object.new(self, objectish, 'tree')
18+
def commit_tree(tree = nil, opts = {})
19+
Git::Object::Commit.new(self, self.lib.commit_tree(tree, opts))
2120
end
22-
23-
def gcommit(objectish)
24-
Git::Object.new(self, objectish, 'commit')
21+
22+
# returns a Git::Diff object
23+
def diff(objectish = 'HEAD', obj2 = nil)
24+
Git::Diff.new(self, objectish, obj2)
2525
end
2626

2727
def gblob(objectish)
2828
Git::Object.new(self, objectish, 'blob')
2929
end
3030

31+
def gcommit(objectish)
32+
Git::Object.new(self, objectish, 'commit')
33+
end
34+
35+
def gtree(objectish)
36+
Git::Object.new(self, objectish, 'tree')
37+
end
38+
3139
# returns a Git::Log object with count commits
3240
def log(count = 30)
3341
Git::Log.new(self, count)
3442
end
43+
44+
# returns a Git::Object of the appropriate type
45+
# you can also call @git.gtree('tree'), but that's
46+
# just for readability. If you call @git.gtree('HEAD') it will
47+
# still return a Git::Object::Commit object.
48+
#
49+
# @git.object calls a factory method that will run a rev-parse
50+
# on the objectish and determine the type of the object and return
51+
# an appropriate object for that type
52+
def object(objectish)
53+
Git::Object.new(self, objectish)
54+
end
3555

56+
# returns a Git::Remote object
57+
def remote(remote_name = 'origin')
58+
Git::Remote.new(self, remote_name)
59+
end
60+
3661
# returns a Git::Status object
3762
def status
3863
Git::Status.new(self)
3964
end
40-
41-
# returns a Git::Branches object of all the Git::Branch objects for this repo
42-
def branches
43-
Git::Branches.new(self)
44-
end
45-
46-
# returns a Git::Branch object for branch_name
47-
def branch(branch_name = 'master')
48-
Git::Branch.new(self, branch_name)
65+
66+
# returns a Git::Tag object
67+
def tag(tag_name)
68+
Git::Object.new(self, tag_name, 'tag', true)
4969
end
5070

5171
end

0 commit comments

Comments
 (0)