Created
October 31, 2011 04:35
-
-
Save brendanp/1326923 to your computer and use it in GitHub Desktop.
This script can be run on a Git repository to record its current state without changing the history. It records a hash (if something has changed) into a log file. It is meant to be run every X minutes to essentially auto-save a git-repo. It is working. A
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
########################### | |
# | |
# | |
# | |
################ | |
# | |
# notes: | |
# | |
################## | |
branchName=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'` | |
gitPrimeFile=gitPrime.log | |
gitPrimeStashHash=$(git stash create) ; | |
gitPrimeHEADHash=$(git rev-parse HEAD) ; | |
gitPrimeLastStash=".git/gitPrimeLast.log"; | |
message=$(date; echo " branch: $branchName -- stash object created by git-prime (DIRTY Working Directory)") ; | |
echo $message | |
# check if there is a stashable hash | |
echo $gitPrimeStashHash | |
foo=( $gitPrimeStashHash ) | |
echo ${#gitPrimeStashHash} | |
length=${#gitPrimeStashHash} | |
lengthNum=$((length)) | |
echo $lengthNum | |
if [ $lengthNum -gt 10 ]; then | |
echo "dirty working dir - might write stash" | |
echo `grep $gitPrimeStashHash $gitPrimeFile ` | |
echo $gitPrimeStashHash $gitPrimeFile | |
foo=`grep $gitPrimeStashHash $gitPrimeFile ` | |
echo "foo1 $foo" | |
lastStashHash=`cat $gitPrimeLastStash` | |
foo=`git diff $lastStashHash $gitPrimeStashHash` | |
echo "foo is:::" $foo | |
length=${#foo} | |
lengthNum=$((length)) | |
echo "lastStashHash: $lastStashHash" | |
echo "thisStashHash $gitPrimeStashHash" | |
if [ $lengthNum -gt 5 ]; then | |
# echo $gitPrimeStashHash $message >> $gitPrimeFile; | |
echo "writing stash" | |
echo $gitPrimeStashHash $message >> $gitPrimeFile; | |
echo $gitPrimeStashHash > $gitPrimeLastStash | |
else | |
echo "last stash obj has no differences with current. not writing stash hash" | |
fi | |
else | |
echo "no dirty working dir. so might write HEAD hash" | |
foo=`grep $gitPrimeHEADHash $gitPrimeFile ` | |
echo "foo1 $foo" | |
if [ -z "$foo" ]; then | |
echo "writing HEAD hash" | |
message=$(date; echo " branch: $branchName -- HEAD hash captured by git-prime (CLEAN Working Directory)") ; | |
echo $gitPrimeHEADHash $message >> $gitPrimeFile; | |
else | |
echo "NOT writing HEAD hash because it was found in the gitPrime log file" | |
fi | |
fi | |
echo "Script END" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment