Created
April 13, 2014 09:07
-
-
Save simonswine/10575715 to your computer and use it in GitHub Desktop.
Integrate existing submodules as subtree
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
#!/usr/bin/env python | |
from __future__ import print_function | |
from git import Repo | |
import sys | |
import os | |
import shutil | |
def convert_submodule_to_subtree(r, sm, squash=True): | |
url = sm.url | |
path = sm.path | |
commit = sm.binsha.encode('hex') | |
# Remove submodule | |
#sm.remove(force=True) | |
# Remove files | |
r.git.rm('-rf', path) | |
# Commit removement of submodule | |
r.git.commit( | |
'-a', | |
'-m', | |
"[TASK] Removes submodule '%s' for later adding as subtree" % path | |
) | |
r.git.fetch(url) | |
# Add submodule as subtree | |
r.git.subtree( | |
'add', | |
"-P", path, | |
url, | |
commit, | |
'--squash' | |
) | |
def convert_submodules_to_subtree(): | |
r = Repo("") | |
print ( | |
"converting submodules to squashed subtrees in rep '%s#" % r.git_dir | |
) | |
if r.is_dirty(): | |
print ("repo is dirty", file=sys.stderr) | |
sys.exit(1) | |
for submodule in r.submodules: | |
print ("Converting Submodule: %s" % submodule) | |
convert_submodule_to_subtree(r, submodule) | |
convert_submodules_to_subtree() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment