From 85867b8e5be3bed7b79e7711a3d1bed2327f1188 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Mon, 23 Feb 2015 16:20:31 +0000 Subject: default timestamp to 0 if no recorded timestamp --- git-base.sh | 8 ++++++-- test-directories.sh | 11 ++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/git-base.sh b/git-base.sh index f147979..41e8833 100755 --- a/git-base.sh +++ b/git-base.sh @@ -13,6 +13,10 @@ in_current_dir() { fi } +echodebug() { + echo "$@" 1>&2 +} + debug_print() { local debug=$1 local message=$2 @@ -58,7 +62,7 @@ record_timestamp() { timestamp() { if is_repo; then - echo "$(stat -f%m "$(dot_git)/lastupdatetime")" + echo "$(stat -f%m "$(dot_git)/lastupdatetime" || echo 0)" fi } @@ -70,7 +74,7 @@ time_to_update() { if is_repo; then local timesincelastupdate="$(($(time_now) - $(timestamp)))" local fiveminutes="$((5 * 60))" - if (( "$timesincelastupdate" > "$5minutes" )); then + if (( "$timesincelastupdate" > "$fiveminutes" )); then # time to update return 0 (which is true) return 0 else diff --git a/test-directories.sh b/test-directories.sh index adf8ea8..1520ffb 100755 --- a/test-directories.sh +++ b/test-directories.sh @@ -12,7 +12,7 @@ cd_to_tmp() { rm_tmp() { cd $scriptDir - rm -r "$tmpfile" + rm -rf /tmp/git-prompt-tests* } test_git_root_in_repo() { @@ -73,4 +73,13 @@ test_not_time_to_update_when_just_recorded() { assertFalse time_to_update } +test_time_to_update_when_no_timestamp() { + cd_to_tmp + git init --quiet + + assertTrue time_to_update + + rm_tmp +} + . ./shunit/shunit2 -- cgit v1.2.3