Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Raises Grit::Git::CommandFailed when the :raise option is set true an…
Browse files Browse the repository at this point in the history
…d the git command exits with a non-zero exit status.
  • Loading branch information
Nicolas Rodriguez committed Jul 21, 2014
1 parent 8791e47 commit 6e74534
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/gitolite/gitolite_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class GitoliteAdmin
DEBUG = false
TIMEOUT = 10

# See here form mode details :https://github.com/gitlabhq/grit/blob/master/lib/grit/git.rb#L283
RAISE_ERROR = true

# Gitolite gem's default commit message
DEFAULT_COMMIT_MSG = "Committed by the gitolite gem"

Expand Down Expand Up @@ -80,7 +83,10 @@ def initialize(path, options = {})
@config_file = options[:config_file] || CONFIG_FILE
@conf_dir = options[:conf_dir] || CONF_DIR
@key_dir = options[:key_dir] || KEY_DIR
@env = options[:env] || {}
git_env = options[:env] || {}
git_raise = options[:raise] || RAISE_ERROR

@git_options = {:env => git_env, :raise => git_raise}

@config_file_path = File.join(@path, @conf_dir, @config_file)
@conf_dir_path = File.join(@path, @conf_dir)
Expand Down Expand Up @@ -125,8 +131,8 @@ def rm_key(key)
# git repo to HEAD and reloading the entire repository
# Note that this will also delete all untracked files
def reset!
@gl_admin.git.native(:reset, {:env => @env, :hard => true}, 'HEAD')
@gl_admin.git.native(:clean, {:env => @env, :d => true, :q => true, :f => true})
@gl_admin.git.native(:reset, @git_options.merge(:hard => true), 'HEAD')
@gl_admin.git.native(:clean, @git_options.merge(:d => true, :q => true, :f => true))
reload!
end

Expand All @@ -146,7 +152,7 @@ def save(commit_message = DEFAULT_COMMIT_MSG, options = {})
#Process config file (if loaded, i.e. may be modified)
if @config
new_conf = @config.to_file(@conf_dir_path)
@gl_admin.git.native(:add, {:env => @env}, new_conf)
@gl_admin.git.native(:add, @git_options, new_conf)
end

#Process ssh keys (if loaded, i.e. may be modified)
Expand All @@ -156,15 +162,15 @@ def save(commit_message = DEFAULT_COMMIT_MSG, options = {})

to_remove = (files - keys).map { |f| File.join(@key_dir, f) }
to_remove.each do |key|
@gl_admin.git.native(:rm, {:env => @env}, key)
@gl_admin.git.native(:rm, @git_options, key)
end

@ssh_keys.each_value do |key|
# Write only keys from sets that has been modified
next if key.respond_to?(:dirty?) && !key.dirty?
key.each do |k|
new_key = k.to_file(@key_dir_path)
@gl_admin.git.native(:add, {:env => @env}, new_key)
@gl_admin.git.native(:add, @git_options, new_key)
end
end
end
Expand All @@ -179,13 +185,13 @@ def save(commit_message = DEFAULT_COMMIT_MSG, options = {})
args << "--author='#{options[:author]}'"
end

@gl_admin.git.native(:commit, {:env => @env}, *args)
@gl_admin.git.native(:commit, @git_options, *args)
end


# Push back to origin
def apply
@gl_admin.git.native(:push, {:env => @env}, "origin", "master")
@gl_admin.git.native(:push, @git_options, "origin", "master")
end


Expand All @@ -202,7 +208,7 @@ def update(options = {})

reset! if options[:reset]

@gl_admin.git.native(:pull, {:env => @env, :rebase => options[:rebase]}, "origin", "master")
@gl_admin.git.native(:pull, @git_options.merge(:rebase => options[:rebase]), "origin", "master")

reload!
end
Expand Down

0 comments on commit 6e74534

Please sign in to comment.