Last active
January 14, 2016 10:12
-
-
Save xeonchen/6e33f7312fc9d8b6e1d1 to your computer and use it in GitHub Desktop.
import large repos to github
This file contains hidden or 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
#!/usr/bin/env python2 | |
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
import subprocess | |
MAX_SIZE = 2000000 | |
def check_size(path): | |
return int(subprocess.check_output(['du', '-s', path]).split()[0]) | |
def add_item(path): | |
if check_size(path) > MAX_SIZE: | |
if os.path.isdir(path): | |
items = [] | |
for subpath in os.listdir(path): | |
items += add_item(os.path.join(path, subpath)) | |
return sorted(items) | |
else: | |
raise RuntimeError('file %s over-sized' % path) | |
return [path] | |
def main(args): | |
for item in args: | |
for path in sorted(add_item(item)): | |
msg = 'import %s' % path | |
print msg | |
os.system('git add -Af %s' % path); | |
os.system('git commit -m "%s"' % msg); | |
if __name__ == '__main__': | |
main(sys.argv[1:]) |
This file contains hidden or 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
#!/usr/bin/env python2 | |
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
import subprocess | |
REMOTE = 'origin' | |
def system(cmd): | |
return subprocess.check_output(cmd.split(' ')) | |
def get_branch(): | |
cmd = "git branch --no-color" | |
return filter(lambda s: s.startswith('*'), system(cmd).split('\n'))[0].split()[1] | |
def get_revisions(): | |
cmd = "git log --abbrev-commit --date=relative --pretty=format:%h" | |
cmd += ' %s/%s..HEAD' % (REMOTE, get_branch()) | |
return reversed(system(cmd).split()) | |
def main(): | |
branch = get_branch() | |
for rev in get_revisions(): | |
cmd = 'git push %s %s:%s' % (REMOTE, rev, branch) | |
print cmd | |
os.system(cmd); | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment