git export

63 views
Skip to first unread message

Bryan Cardillo

unread,
Jan 17, 2009, 9:19:35 PM1/17/09
to capis...@googlegroups.com
Hi all,

I'd like to suggest an alternate implementation for export in the git
scm class. Currently, git export performs a clone and checkout (just
like checkout), then removes the .git directory. I think git archive
is better suited for this since it doesn't require transferring the
entire repository. As an added bonus, you can specify paths within
the repository to the archive command, allowing specific directories
to be deployed (a feature I've seen requested from time to time, and
my original motivation for ever looking at the git scm code). Anyway,
I've been using my patched git class for a bit now, and thought I'd
offer it here in case others find it useful.

Cheers,
Bryan

git.rb | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)

--- src/ruby/capistrano/recipes/deploy/scm/git.rb.orig
+++ src/ruby/capistrano/recipes/deploy/scm/git.rb
@@ -157,10 +157,26 @@
execute.join(" && ")
end

- # An expensive export. Performs a checkout as above, then
- # removes the repo.
+ # use git archive to export repository
def export(revision, destination)
- checkout(revision, destination) << " && rm -Rf #{destination}/.git"
+ git = command
+ execute = []
+ args = []
+
+ args << '--format=tar'
+ args << "--remote=#{configuration[:repository]}"
+ if project = configuration[:project]
+ args << "#{revision}:#{project}"
+ else
+ args << revision
+ end
+
+ # export (using git archive)
+ execute << "mkdir -p #{destination}"
+ execute << "cd #{destination}"
+ execute << "#{git} archive #{args.join(' ')} | tar xf -"
+
+ execute.join(" && ")
end

# Merges the changes to 'head' since the last fetch, for remote_cache

Jamis Buck

unread,
Jan 17, 2009, 9:29:06 PM1/17/09
to capis...@googlegroups.com
Bryan,

That's a neat idea. I like the side benefit of letting subdirectories be
deployed, too. Could you post that patch on the capistrano lighthouse
(http://capistrano.lighthouseapp.com/projects/8716-capistrano/tickets)
so that it doesn't get lost?

- Jamis

Mislav Marohnić

unread,
Jan 18, 2009, 2:16:33 PM1/18/09
to capis...@googlegroups.com
W00t, I didn't know about remote archive! Thanks a lot for sharing
Reply all
Reply to author
Forward
0 new messages