Created
March 18, 2012 16:42
-
-
Save nicokruger/2077166 to your computer and use it in GitHub Desktop.
Execute a command for all commits in a git repository.
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
#!/bin/bash | |
if ! [ -d ".git" ]; then | |
echo "Script must be run from within a git repository" | |
exit 1 | |
fi | |
if [ $# -ne 1 ]; then | |
echo "Please specify a script to execute for each commit" | |
echo "Script will recieve <repo_dir> <commit ref> as arguments" | |
echo "where repo_dir will already be checked out to the appropriate commit" | |
exit 1 | |
fi | |
SCRIPT=$1 | |
TMP=$(mktemp -d -q) | |
REPO=$(pwd) | |
# clone the git repository | |
pushd $TMP > /dev/null 2>&1 | |
git clone $REPO 2> /dev/null 1>&2 | |
cd $(basename $REPO) | |
# get all | |
for F in $(git log --children | grep commit\ | sed "s;commit ;;" | tac | xargs echo); do | |
git checkout $F 2> /dev/null 1>&2 | |
bash $SCRIPT $F | |
done | |
popd > /dev/null | |
rm -rf $TMP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment