Module: Git::Base::Factory

Included in:
Git::Base
Defined in:
lib/git/base/factory.rb

Instance Method Summary collapse

Instance Method Details

#branch(branch_name = 'master') ⇒ Git::Branch

Returns an object for branch_name.

Returns:



8
9
10
# File 'lib/git/base/factory.rb', line 8

def branch(branch_name = 'master')
  Git::Branch.new(self, branch_name)
end

#branchesGit::Branches

Returns a collection of all the branches in the repository. Each branch is represented as a Git::Branch.

Returns:



14
15
16
# File 'lib/git/base/factory.rb', line 14

def branches
  Git::Branches.new(self)
end

#commit_tree(tree = nil, opts = {}) ⇒ Git::Object::Commit

Returns a commit object.

Returns:



30
31
32
# File 'lib/git/base/factory.rb', line 30

def commit_tree(tree = nil, opts = {})
  Git::Object::Commit.new(self, self.lib.commit_tree(tree, opts))
end

#diff(objectish = 'HEAD', obj2 = nil) ⇒ Git::Diff

Returns a Git::Diff object.

Returns:



35
36
37
# File 'lib/git/base/factory.rb', line 35

def diff(objectish = 'HEAD', obj2 = nil)
  Git::Diff.new(self, objectish, obj2)
end

#gblob(objectish) ⇒ Git::Object

Returns a Git object.

Returns:



40
41
42
# File 'lib/git/base/factory.rb', line 40

def gblob(objectish)
  Git::Object.new(self, objectish, 'blob')
end

#gcommit(objectish) ⇒ Git::Object

Returns a Git object.

Returns:



45
46
47
# File 'lib/git/base/factory.rb', line 45

def gcommit(objectish)
  Git::Object.new(self, objectish, 'commit')
end

#gtree(objectish) ⇒ Git::Object

Returns a Git object.

Returns:



50
51
52
# File 'lib/git/base/factory.rb', line 50

def gtree(objectish)
  Git::Object.new(self, objectish, 'tree')
end

#log(count = 30) ⇒ Git::Log

Returns a log with the specified number of commits.

Returns:

  • (Git::Log)

    a log with the specified number of commits



55
56
57
# File 'lib/git/base/factory.rb', line 55

def log(count = 30)
  Git::Log.new(self, count)
end

#merge_base(*args) ⇒ Array<Git::Object::Commit>

Find as good common ancestors as possible for a merge example: g.merge_base(‘master’, ‘some_branch’, ‘some_sha’, octopus: true)

Returns:



92
93
94
95
# File 'lib/git/base/factory.rb', line 92

def merge_base(*args)
  shas = self.lib.merge_base(*args)
  shas.map { |sha| gcommit(sha) }
end

#object(objectish) ⇒ Git::Object

returns a Git::Object of the appropriate type you can also call @git.gtree(‘tree’), but that’s just for readability. If you call @git.gtree(‘HEAD’) it will still return a Git::Object::Commit object.

object calls a factory method that will run a rev-parse on the objectish and determine the type of the object and return an appropriate object for that type

Returns:

  • (Git::Object)

    an instance of the appropriate type of Git::Object



69
70
71
# File 'lib/git/base/factory.rb', line 69

def object(objectish)
  Git::Object.new(self, objectish)
end

#remote(remote_name = 'origin') ⇒ Git::Remote

Returns a remote of the specified name.

Returns:



74
75
76
# File 'lib/git/base/factory.rb', line 74

def remote(remote_name = 'origin')
  Git::Remote.new(self, remote_name)
end

#statusGit::Status

Returns a status object.

Returns:



79
80
81
# File 'lib/git/base/factory.rb', line 79

def status
  Git::Status.new(self)
end

#tag(tag_name) ⇒ Git::Object::Tag

Returns a tag object.

Returns:



84
85
86
# File 'lib/git/base/factory.rb', line 84

def tag(tag_name)
  Git::Object.new(self, tag_name, 'tag', true)
end

#worktree(dir, commitish = nil) ⇒ Object

returns a Git::Worktree object for dir, commitish



19
20
21
# File 'lib/git/base/factory.rb', line 19

def worktree(dir, commitish = nil)
  Git::Worktree.new(self, dir, commitish)
end

#worktreesObject

returns a Git::worktrees object of all the Git::Worktrees objects for this repo



25
26
27
# File 'lib/git/base/factory.rb', line 25

def worktrees
  Git::Worktrees.new(self)
end