#!/bin/bash # Author: Luis R. Rodriguez # Generates a range of diffs based on a git commit log # There has to be an easier way to do this... # License: GPL if [[ $# -ne 2 ]]; then echo "Usage $0 " exit fi LOG=$1 if [[ ! -f $LOG ]]; then echo "Log file doesn't exist" exit fi DIR=$2 if [[ ! -d $DIR ]]; then mkdir -p $DIR if [[ $? -ne 0 ]]; then exit fi fi COUNT=`wc -l $LOG | awk '{print $1}'` echo "Log has $COUNT commits, generating diffs..." i=$COUNT NUM_DIFFS=1 while [ $i -ne 0 ]; do CURR_LINE=$i PREV_LINE=$((CURR_LINE-1)) CURR_COMMIT=`head -${CURR_LINE} $LOG | tail -1` PREV_COMMIT=`head -${PREV_LINE} $LOG | tail -1` if [[ ! -n $PREV_COMMIT ]]; then echo "Done! $PREV_COMMIT" break fi echo "diff $CURR_COMMIT .. $PREV_COMMIT" git-log -p ${CURR_COMMIT}..${PREV_COMMIT} > $DIR/${NUM_DIFFS}.diff if [[ $NUM_DIFFS -eq 1 ]]; then cat $DIR/${NUM_DIFFS}.diff > $DIR/all.diff else cat $DIR/${NUM_DIFFS}.diff >> $DIR/all.diff fi let NUM_DIFFS=$NUM_DIFFS+1 let i=$i-1 done