Class Git::Base
In: lib/git/base.rb
Parent: Object

Methods

add   add_remote   add_tag   bare   branch   branches   chdir   checkout   clone   commit   commit_all   config   current_branch   diff   dir   fetch   gblob   gcommit   grep   gtree   index   init   lib   log   merge   new   object   open   pull   push   remote   remotes   remove   repack   repo   repo_size   reset   reset_hard   revparse   status   tag   tags  

Public Class methods

opens a bare Git Repository - no working directory options

[Source]

# File lib/git/base.rb, line 10
    def self.bare(git_dir)
      self.new :repository => git_dir
    end

clones a git repository locally

 repository - http://repo.or.cz/w/sinatra.git
 name - sinatra

options:

  :repository

   :bare
  or
   :working_directory
   :index_file

[Source]

# File lib/git/base.rb, line 58
    def self.clone(repository, name, opts = {})
      # run git-clone 
      self.new(Git::Lib.new.clone(repository, name, opts))
    end

initializes a git repository

options:

 :repository
 :index_file

[Source]

# File lib/git/base.rb, line 29
    def self.init(working_dir, opts = {})
      default = {:working_directory => working_dir,
                 :repository => File.join(working_dir, '.git')}
      git_options = default.merge(opts)
      
      if git_options[:working_directory]
        # if !working_dir, make it
        FileUtils.mkdir_p(git_options[:working_directory]) if !File.directory?(git_options[:working_directory])
      end
      
      # run git_init there
      Git::Lib.new(git_options).init
       
      self.new(git_options)
    end

[Source]

# File lib/git/base.rb, line 63
    def initialize(options = {})
      if working_dir = options[:working_directory]
        options[:repository] = File.join(working_dir, '.git') if !options[:repository]
        options[:index] = File.join(working_dir, '.git', 'index') if !options[:index]
      end
      
      @working_directory = Git::WorkingDirectory.new(options[:working_directory]) if options[:working_directory]
      @repository = Git::Repository.new(options[:repository]) if options[:repository]
      @index = Git::Index.new(options[:index], false) if options[:index]
    end

opens a new Git Project from a working directory you can specify non-standard git_dir and index file in the options

[Source]

# File lib/git/base.rb, line 16
    def self.open(working_dir, opts={})    
      default = {:working_directory => working_dir}
      git_options = default.merge(opts)
      
      self.new(git_options)
    end

Public Instance methods

adds files from the working directory to the git repository

[Source]

# File lib/git/base.rb, line 162
    def add(path = '.')
      self.lib.add(path)
    end

[Source]

# File lib/git/base.rb, line 213
    def add_remote(name, url, opts = {})
      if url.is_a?(Git::Base)
        url = url.repo.path
      end
      self.lib.remote_add(name, url, opts)
      Git::Remote.new(self, name)
    end

[Source]

# File lib/git/base.rb, line 229
    def add_tag(tag_name)
      self.lib.tag(tag_name)
      tag(tag_name)
    end

[Source]

# File lib/git/base.rb, line 140
    def branch(branch_name = 'master')
      Git::Branch.new(self, branch_name)
    end

[Source]

# File lib/git/base.rb, line 136
    def branches
      Git::Branches.new(self)
    end

[Source]

# File lib/git/base.rb, line 87
    def chdir
      Dir.chdir(dir.path) do
        yield dir.path
      end
    end

[Source]

# File lib/git/base.rb, line 188
    def checkout(branch = 'master', opts = {})
      self.lib.checkout(branch, opts)
    end

[Source]

# File lib/git/base.rb, line 179
    def commit(message, opts = {})
      self.lib.commit(message, opts)
    end

[Source]

# File lib/git/base.rb, line 183
    def commit_all(message, opts = {})
      opts = {:add_all => true}.merge(opts)
      self.lib.commit(message, opts)
    end

g.config(‘user.name’, ‘Scott Chacon’) # sets value g.config(‘user.email’, ‘email@email.com’) # sets value g.config(‘user.name’) # returns ‘Scott Chacon’ g.config # returns whole config hash

[Source]

# File lib/git/base.rb, line 105
    def config(name = nil, value = nil)
      if(name && value)
        # set value
        lib.config_set(name, value)
      elsif (name)
        # return value
        lib.config_get(name)
      else
        # return hash
        lib.config_list
      end
    end

[Source]

# File lib/git/base.rb, line 244
    def current_branch
      self.lib.branch_current
    end

[Source]

# File lib/git/base.rb, line 157
    def diff(objectish = 'HEAD', obj2 = nil)
      Git::Diff.new(self, objectish, obj2)
    end

[Source]

# File lib/git/base.rb, line 75
    def dir
      @working_directory
    end

[Source]

# File lib/git/base.rb, line 192
    def fetch(remote = 'origin')
      self.lib.fetch(remote)
    end
gblob(objectish)

Alias for object

gcommit(objectish)

Alias for object

[Source]

# File lib/git/base.rb, line 153
    def grep(string)
      self.object('HEAD').grep(string)
    end
gtree(objectish)

Alias for object

[Source]

# File lib/git/base.rb, line 83
    def index
      @index
    end

[Source]

# File lib/git/base.rb, line 149
    def lib
      Git::Lib.new(self)
    end

[Source]

# File lib/git/base.rb, line 128
    def log(count = 30)
      Git::Log.new(self, count)
    end

[Source]

# File lib/git/base.rb, line 200
    def merge(branch, message = 'merge')
      self.lib.merge(branch, message)
    end

factory methods

[Source]

# File lib/git/base.rb, line 120
    def object(objectish)
      Git::Object.new(self, objectish)
    end

[Source]

# File lib/git/base.rb, line 204
    def pull(remote = 'origin', branch = 'master', message = 'origin pull')
      fetch(remote)
      merge(branch, message)
    end

[Source]

# File lib/git/base.rb, line 196
    def push(remote = 'origin', branch = 'master')
      self.lib.push(remote, branch)
    end

[Source]

# File lib/git/base.rb, line 144
    def remote(remote_name = 'origin')
      Git::Remote.new(self, remote_name)
    end

[Source]

# File lib/git/base.rb, line 209
    def remotes
      self.lib.remotes.map { |r| Git::Remote.new(self, r) }
    end

[Source]

# File lib/git/base.rb, line 166
    def remove(path = '.', opts = {})
      self.lib.remove(path, opts)
    end

convenience methods

[Source]

# File lib/git/base.rb, line 236
    def repack
      self.lib.repack
    end

[Source]

# File lib/git/base.rb, line 79
    def repo
      @repository
    end

[Source]

# File lib/git/base.rb, line 93
    def repo_size
      size = 0
      Dir.chdir(repo.path) do
        (size, dot) = `du -d0`.chomp.split
      end
      size.to_i
    end

[Source]

# File lib/git/base.rb, line 170
    def reset(commitish = nil, opts = {})
      self.lib.reset(commitish, opts)
    end

[Source]

# File lib/git/base.rb, line 174
    def reset_hard(commitish = nil, opts = {})
      opts = {:hard => true}.merge(opts)
      self.lib.reset(commitish, opts)
    end

[Source]

# File lib/git/base.rb, line 240
    def revparse(objectish)
      self.lib.revparse(objectish)
    end

[Source]

# File lib/git/base.rb, line 132
    def status
      Git::Status.new(self)
    end

[Source]

# File lib/git/base.rb, line 225
    def tag(tag_name)
      Git::Object.new(self, tag_name, true)
    end

[Source]

# File lib/git/base.rb, line 221
    def tags
      self.lib.tags.map { |r| tag(r) }
    end

[Validate]