From 7baf05194211f5a67a8b9aff94955c2e096f38b7 Mon Sep 17 00:00:00 2001 From: Paul Mansfield Date: Sat, 29 Aug 2009 21:13:38 +0100 Subject: [PATCH] Bug Fix: do: no safeguard to do twice Tests item is not marked done before attempting to mark item as "done". --- tests/t1500-do.sh | 8 ++++++++ todo.sh | 19 ++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tests/t1500-do.sh b/tests/t1500-do.sh index c9b9a76..8d0ba0a 100755 --- a/tests/t1500-do.sh +++ b/tests/t1500-do.sh @@ -69,4 +69,12 @@ TODO: $HOME/todo.txt archived. TODO: 3 of 3 tasks shown from $HOME/todo.txt EOF +test_todo_session 'fail multiple do attempts' <>> todo.sh -a do 3 +3: x 2009-02-13 stop +TODO: 3 marked as done. + +>>> todo.sh -a do 3 +3 is already marked done +EOF test_done diff --git a/todo.sh b/todo.sh index 9c60c87..778862d 100755 --- a/todo.sh +++ b/todo.sh @@ -705,13 +705,18 @@ case $action in todo=$(sed "$item!d" "$TODO_FILE") [ -z "$todo" ] && die "$item: No such todo." - now=`date '+%Y-%m-%d'` - # remove priority once item is done - sed -i.bak $item"s/^(.) //" "$TODO_FILE" - sed -i.bak $item"s|^|&x $now |" "$TODO_FILE" - newtodo=$(sed "$item!d" "$TODO_FILE") - [ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo" - [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item marked as done." + # Check if this item has already been done + if [ `echo $todo | grep -c "^x "` -eq 0 ] ; then + now=`date '+%Y-%m-%d'` + # remove priority once item is done + sed -i.bak $item"s/^(.) //" "$TODO_FILE" + sed -i.bak $item"s|^|&x $now |" "$TODO_FILE" + newtodo=$(sed "$item!d" "$TODO_FILE") + [ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo" + [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item marked as done." + else + echo "$item is already marked done" + fi done if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then