Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Kentzo committed Oct 10, 2010
0 parents commit 17eb999
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Textmate - if you build your xcode projects with it
*.tm_build_errors

# osx noise
.DS_Store
profile

# emacs noise
*~
43 changes: 43 additions & 0 deletions git-archive-all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#! /usr/bin/python

from os import path, chdir
from subprocess import Popen, PIPE
from optparse import OptionParser
from sys import argv

git_repositary_path = path.abspath('')
git_repositary_name = path.basename(git_repositary_path)

parser = OptionParser(usage="usage: %prog [options] <tree-ish>", version="%prog 1.0")
parser.add_option('--format', type='choice', dest='format', choices=['zip','tar'], default='tar', help="Format of the resulting archive: tar or zip. The default output format is %default.")
parser.add_option('--prefix', type='string', dest='prefix', default='', help="Prepend %dest to each filename in the archive.")
parser.add_option('-o', '--output', type='string', dest='output_file', default=path.join(git_repositary_path, git_repositary_name), help='Write the archive to <file> instead of stdout')

(options, args) = parser.parse_args()

print options.output_file

def git_files(baselevel=''):
for filepath in Popen('git ls-files --cached --full-name --no-empty-directory', shell=True, stdout=PIPE).stdout.read().splitlines():
if not filepath.startswith('.git') and not path.isdir(filepath):
# baselevel is needed to tell the arhiver where it have to extract file
yield filepath, path.join(baselevel, filepath)
# get paths for every submodule
for submodule in Popen("git submodule --quiet foreach --recursive 'pwd'", shell=True, stdout=PIPE).stdout.read().splitlines():
chdir(submodule)
# in order to get output path we need to exclude repository path from the submodule path
submodule = submodule[len(git_repositary_path)+1:]
# recursion allows us to process repositories with more than one level of submodules
for git_file in git_files(submodule):
yield git_file

if options.format == 'zip':
from zipfile import ZipFile, ZIP_DEFLATED
output_archive = ZipFile(path.abspath(options.output_file), 'w')
for name, arcname in git_files():
output_archive.write(name, options.prefix + arcname, ZIP_DEFLATED)
elif options.format == 'tar':
from tarfile import TarFile
output_archive = TarFile(path.abspath(options.output_file), 'w')
for name, arcname in git_files():
output_archive.add(name, options.prefix + arcname)

0 comments on commit 17eb999

Please sign in to comment.