Created
September 20, 2012 06:18
-
-
Save crowding/3754239 to your computer and use it in GitHub Desktop.
Extracting a number of subdirectories into submodules
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
#!/bin/bash | |
set -v verbose | |
trap exit ERR | |
#I want to extract a number of submodules from a larger project. | |
#Also to preserve untracked files (e.g. lengthy data build products) | |
CWD=`pwd` | |
REPO_DIR="direction_discrimination_analysis" | |
SUBMODULES="mothballed_writing previous_draft newer_draft" | |
REMOTE_REPO_ROOT_ABS="[email protected]:writing" | |
REMOTE_REPO_ROOT_RELATIVE="../writing" | |
#ptools | |
for i in $SUBMODULES; do | |
git clone --bare $REPO_DIR $i.git | |
cd $CWD/$i.git | |
git filter-branch --subdirectory-filter $i | |
cd $CWD | |
git clone --bare file://$CWD/$i.git $i-clean.git | |
done | |
for i in $SUBMODULES; do | |
cd $CWD/$i-clean.git | |
git remote rm origin | |
git remote add origin $REMOTE_REPO_ROOT_ABS/$i.git | |
git fetch #Gitolite will automatically create a repo here. | |
git push origin --all | |
done | |
for i in $SUBMODULES; do | |
cd $CWD/$REPO_DIR | |
mv $i $i.old | |
git rm -r $i | |
git submodule add $REMOTE_REPO_ROOT_RELATIVE/$i.git | |
done | |
#then move over untracked files. | |
for i in $SUBMODULES; do | |
cd $CWD/$REPO_DIR | |
FILES=$(comm -13 <(find $i | cut -f 2- -d / | sort) \ | |
<(find $i.old | cut -f 2- -d / | sort)) | |
for j in $FILES; do | |
if test -e $i.old/$j; then | |
#skip subfiles that were moved when their parent dirs moved | |
mv $i.old/$j $i/$j | |
fi | |
done | |
cp .gitignore $i/.gitignore | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment