Skip to content

Commit 7e61b04

Browse files
jamesarosenschacon
authored andcommitted
added Git.export for exporting only the latest copy and no repository information
Signed-off-by: Scott Chacon <schacon@gmail.com>
1 parent d3afb14 commit 7e61b04

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/git.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,19 @@ def self.init(working_dir = '.', options = {})
9292
def self.clone(repository, name, options = {})
9393
Base.clone(repository, name, options)
9494
end
95+
96+
# Export the current HEAD (or a branch, if <tt>options[:branch]</tt>
97+
# is specified) into the +name+ directory, then remove all traces of git from the
98+
# directory.
99+
#
100+
# See +clone+ for options. Does not obey the <tt>:remote</tt> option,
101+
# since the .git info will be deleted anyway; always uses the default
102+
# remote, 'origin.'
103+
def self.export(repository, name, options = {})
104+
options.delete(:remote)
105+
repo = clone(repository, name, {:depth => 1}.merge(options))
106+
repo.checkout("origin/#{options[:branch]}") if options[:branch]
107+
Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' }
108+
end
95109

96110
end

0 commit comments

Comments
 (0)