From a0e37297a96ae78c5c9b808affe924c5497aef4c Mon Sep 17 00:00:00 2001 From: Jared Ballou Date: Tue, 19 Jan 2016 13:45:22 -0500 Subject: [PATCH] Stopped trying to do my own hashing and rely on Git for now --- functions/github_hash.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/functions/github_hash.sh b/functions/github_hash.sh index fbc3fd1e6..e78450d58 100755 --- a/functions/github_hash.sh +++ b/functions/github_hash.sh @@ -14,13 +14,17 @@ # Calculate the Git hash for a file function fn_get_git_hash(){ filename=$1 - if [ -e $filename ] - then - filesize=$(stat --format='%s' $filename) - if [ "$(tail -c1 $filename)" == "" ]; then - printf "blob %d\0%s\n" "${filesize}" "$(cat $filename)" | sha1sum | awk '{print $1}' + if [ -e $filename ]; then + gitcmd="$(which git)" + if [ -x "${gitcmd}" ]; then + $gitcmd hash-object "${filename}" else - printf "blob %d\0%s" "${filesize}" "$(cat $filename)" | sha1sum | awk '{print $1}' + filesize=$(stat --format='%s' $filename) + if [ "$(tail -c1 $filename)" == "" ]; then + printf "blob %d\0%s\n" "${filesize}" "$(cat $filename)" | sha1sum | awk '{print $1}' + else + printf "blob %d\0%s" "${filesize}" "$(cat $filename)" | sha1sum | awk '{print $1}' + fi fi fi }