-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 17eb999
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |