Skip to content

Commit

Permalink
+ commit files into bare repository directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
snowyu committed May 24, 2012
1 parent 7219ef6 commit 5eae639
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
13 changes: 11 additions & 2 deletions lib/grit/git.rb
Expand Up @@ -93,9 +93,11 @@ def self.with_timeout(timeout = 10)

attr_accessor :git_dir, :bytes_read, :work_tree

def initialize(git_dir)
def initialize(git_dir, options = {})
options, self.work_tree = {}, options if !options.is_a?(Hash)
self.work_tree = nil if self.work_tree && self.work_tree.length <= 0
self.git_dir = git_dir
self.work_tree = git_dir.gsub(/\/\.git$/,'')
self.work_tree = options[:working_dir] || git_dir.gsub(/\/\.git$/,'') if !self.work_tree || (self.work_tree && !self.work_tree.is_a?(String))
self.bytes_read = 0
end

Expand Down Expand Up @@ -282,6 +284,8 @@ def apply_patch(options={}, head_sha=nil, patch=nil)
# use that number of seconds; when false or 0, disable timeout.
# :base - Set false to avoid passing the --git-dir argument when
# invoking the git command.
# :work - Set true to pass the --work-tree argument when
# invoking the git command if work_tree exists.
# :env - Hash of environment variable key/values that are set on the
# child process.
# :raise - When set true, commands that exit with a non-zero status
Expand Down Expand Up @@ -328,12 +332,17 @@ def native(cmd, options = {}, *args, &block)
input = options.delete(:input)
timeout = options.delete(:timeout); timeout = true if timeout.nil?
base = options.delete(:base); base = true if base.nil?
work = options.delete(:work); work = false if work.nil?
chdir = options.delete(:chdir)

# build up the git process argv
argv = []
argv << Git.git_binary
argv << "--git-dir=#{git_dir}" if base
if work && work_tree && work_tree.length > 0
p "work_tree=#{work_tree}"
argv << "--work-tree=#{work_tree}"
end
argv << cmd.to_s.tr('_', '-')
argv.concat(options_to_argv(options))
argv.concat(args)
Expand Down
15 changes: 8 additions & 7 deletions lib/grit/repo.rb
Expand Up @@ -46,14 +46,15 @@ def initialize(path, options = {})
@bare = false
elsif File.exist?(epath) && (epath =~ /\.git$/ || options[:is_bare])
self.path = epath
self.working_dir = options[:working_dir] if options[:working_dir]
@bare = true
elsif File.exist?(epath)
raise InvalidGitRepositoryError.new(epath)
else
raise NoSuchPathError.new(epath)
end

self.git = Git.new(self.path)
self.git = Git.new(self.path, self.working_dir)
end

# Public: Initialize a git repository (create it on the filesystem). By
Expand Down Expand Up @@ -234,20 +235,20 @@ def head
# Commits current index
#
# Returns true/false if commit worked
def commit_index(message)
self.git.commit({}, '-m', message)
def commit_index(message, options = {})
self.git.commit(options, '-m', message)
end

# Commits all tracked and modified files
#
# Returns true/false if commit worked
def commit_all(message)
self.git.commit({}, '-a', '-m', message)
def commit_all(message, options = {})
self.git.commit(options, '-a', '-m', message)
end

# Adds files to the index
def add(*files)
self.git.add({}, *files.flatten)
def add(*files, options = {})
self.git.add(options, *files.flatten)
end

# Remove files from the index
Expand Down

0 comments on commit 5eae639

Please sign in to comment.