Skip to content

Instantly share code, notes, and snippets.

@aaren
Created November 19, 2014 16:35
Show Gist options
  • Save aaren/0fab3586c056184f3b3b to your computer and use it in GitHub Desktop.
Save aaren/0fab3586c056184f3b3b to your computer and use it in GitHub Desktop.
#!/bin/bash
# This is a script for migrating the python lesson out of
# bc/novice/python into swc-novice-python and then into the
# new lesson template (lesson-template)
# https://github.com/swcarpentry/workshop-template/pull/61
if [[ ! -d bc ]]; then
git clone https://github.com/swcarpentry/bc
cd bc
else
cd bc
git checkout gh-pages
git pull
fi
# use subtree to filter out the novice/python directory
# into a new branch 'novice-python-history'
git subtree split -P novice/python -b novice-python-history &&
git checkout novice-python-history &&
# attach missed older history (from bc reorgs)
# https://github.com/wking/swc-modular-shell/issues/3
# (lesson now in novice/python used to be in python/novice)
# goto the commit before the reorg
git checkout -b python-novice b8c7dc3^ &&
# move python/novice to root and rewrite all commits accordingly
git filter-branch -f --subdirectory-filter python/novice --prune-empty &&
# now rebase to add this to the history
git checkout novice-python-history &&
ORPHAN_COPY_COMMIT=$(git rev-parse 'HEAD^{/Reorganizing material}') &&
git rebase -p --onto python-novice "${ORPHAN_COPY_COMMIT}" &&
# delete the temp branch
git branch -D python-novice &&
# pull this branch into 'novice-python-history' branch of
# new repo (swc-novice-python)
cd ..
cd swc-novice-python
git checkout novice-python-history &&
git pull --force ../bc novice-python-history
# all of the files are now in the root, so we need to move them
# into pages/ before importing to the lesson template
# git filter-branch --tree-filter 'mkdir -p pages; mv * pages || true;' HEAD
# now pull into workshop-template
# cd ..
# git clone git@github.com:pipitone/workshop-template
# cd workshop-template
# git checkout -b pr-import-bc-setup-history
# git pull ../bc setup
@aaren
Copy link
Author

aaren commented Nov 19, 2014

@r-gaia-cs regarding the prune empty issue I think the problem is that git subtree doesn't take --prune-empty as an argument.

I should be able to do the same thing with filter-branch. Currently I'm using:

git subtree split -P novice/python -b novice-python-history
git checkout novice-python-history

Should replace with this:

git checkout -b novice-python-history
git filter-branch --subdirectory-filter novice/python --prune-empty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment