summaryrefslogtreecommitdiffstats
path: root/lib/git
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-14 10:24:22 -0800
committerscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-14 10:24:22 -0800
commitdf27b5e7d6cb210b5a0870eb671a983336fb95c7 (patch)
treeb2e1c449e04de4adb7048ee84e02c1cab50557e4 /lib/git
parentcbf72e3bfd1f62b35cc2db623be531f7f9c9275c (diff)
downloadthird_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')
-rw-r--r--lib/git/base.rb5
-rw-r--r--lib/git/branch.rb7
-rw-r--r--lib/git/lib.rb36
-rw-r--r--lib/git/object.rb5
4 files changed, 50 insertions, 3 deletions
diff --git a/lib/git/base.rb b/lib/git/base.rb
index e7eaf22..6fb8adb 100644
--- a/lib/git/base.rb
+++ b/lib/git/base.rb
@@ -311,6 +311,11 @@ module Git
tag(tag_name)
end
+ # creates an archive file of the given tree-ish
+ def archive(treeish, file = nil, opts = {})
+ self.object(treeish).archive(file, opts)
+ end
+
# repacks the repository
def repack
self.lib.repack
diff --git a/lib/git/branch.rb b/lib/git/branch.rb
index 7cef94e..f9106ab 100644
--- a/lib/git/branch.rb
+++ b/lib/git/branch.rb
@@ -21,15 +21,18 @@ module Git
end
def gcommit
- @gcommit = @base.object(name) if !@gcommit
+ @gcommit = @base.object(@full) if !@gcommit
@gcommit
end
def checkout
check_if_create
- @base.checkout(@name)
+ @base.checkout(@full)
end
+ def archive(file, opts = {})
+ @base.lib.archive(@full, file, opts)
+ end
# g.branch('new_branch').in_branch do
# # create new file
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
diff --git a/lib/git/object.rb b/lib/git/object.rb
index 7702811..c811810 100644
--- a/lib/git/object.rb
+++ b/lib/git/object.rb
@@ -48,6 +48,11 @@ module Git
Git::Log.new(@base, count).object(@sha)
end
+ # creates an archive of this object (tree)
+ def archive(file = nil, opts = {})
+ @base.lib.archive(@sha, file, opts)
+ end
+
end