diff options
author | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-14 10:24:22 -0800 |
---|---|---|
committer | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-14 10:24:22 -0800 |
commit | df27b5e7d6cb210b5a0870eb671a983336fb95c7 (patch) | |
tree | b2e1c449e04de4adb7048ee84e02c1cab50557e4 /lib/git/lib.rb | |
parent | cbf72e3bfd1f62b35cc2db623be531f7f9c9275c (diff) | |
download | third_party-ruby-git-df27b5e7d6cb210b5a0870eb671a983336fb95c7.tar.gz third_party-ruby-git-df27b5e7d6cb210b5a0870eb671a983336fb95c7.tar.xz third_party-ruby-git-df27b5e7d6cb210b5a0870eb671a983336fb95c7.zip |
added 'archive' and tests
Diffstat (limited to 'lib/git/lib.rb')
-rw-r--r-- | lib/git/lib.rb | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 051025c..6cebc95 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -1,3 +1,5 @@ +require 'tempfile' + module Git class GitExecuteError < StandardError @@ -344,6 +346,37 @@ module Git command('repack', ['-a', '-d']) end + # creates an archive file + # + # options + # :format (zip, tar) + # :prefix + # :remote + # :path + def archive(sha, file = nil, opts = {}) + opts[:format] = 'zip' if !opts[:format] + + if opts[:format] == 'tgz' + opts[:format] = 'tar' + opts[:add_gzip] = true + end + + if !file + file = Tempfile.new('archive').path + end + + arr_opts = [] + arr_opts << "--format=#{opts[:format]}" if opts[:format] + arr_opts << "--prefix=#{opts[:prefix]}" if opts[:prefix] + arr_opts << "--remote=#{opts[:remote]}" if opts[:remote] + arr_opts << sha + arr_opts << opts[:path] if opts[:path] + arr_opts << '| gzip' if opts[:add_gzip] + arr_opts << "> #{file.to_s}" + command('archive', arr_opts) + return file + end + private def command_lines(cmd, opts = {}) @@ -367,10 +400,11 @@ module Git #puts out #puts if $?.exitstatus > 0 + puts $?.exitstatus if $?.exitstatus == 1 && out == '' return '' end - raise Git::GitExecuteError.new(git_cmd + ':' + out.to_s) + raise Git::GitExecuteError.new(git_cmd + ':' + out.to_s) end out end |