laughedelic / gtm

:stopwatch: git task/time manager
86 stars 10 forks source link

Duplicated notes after git commit --amend #75

Closed trygub closed 9 years ago

trygub commented 9 years ago

gtm: line 531: 7237 + 101

437 : syntax error in expression (error token is "437 ")

Line 531 is the last line in this if block:

    if [ "$t" ]; then
        fmt=${format/_human_time_/$(human_time $t)}
        fmt=${fmt/_time_/$(human_time $t --short)}
        [ "${fmt// /}" ] && git --no-pager show --format="$fmt" $h | head -1
        # [[ "$t" =~ [^0-9] ]] && err "$(pwd): $h"
        total=$(( $total + $t ))
    fi
laughedelic commented 9 years ago

Hi @trygub! I tried gtm report and it seems to work for me. Do you call it with any specific arguments? Also could you just try bar=2; foo=$((1 + $bar)); echo $foo in your bash (should output 3)?

trygub commented 9 years ago

bar=2; foo=$((1 + $bar)); echo $foo

the above does output 3, yes

Do you call it with any specific arguments?

no, just "gtm report", I'm affraid

laughedelic commented 9 years ago

Ok, try to run gtm report -t ' ' (there is a space between ')

trygub commented 9 years ago

No luck, Sir.

The above produces

gtm: line 531: 7237 + 101

437 : syntax error in expression (error token is "437 ")

If you push up a branch with some more debug output around these lines of code maybe, I could run it and send the output to you...

laughedelic commented 9 years ago

Hey @trygub, sorry but right now I don't have much time for this. I'll try to take a look at it this weekend. Also it may help if you tell me whatever details about your system (actually I think only bash version matters, but you use something specific, tell me).

trygub commented 9 years ago

Latest Ubuntu 14.04 with default bash.

bash --version GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html

This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

I don't speak bash, but I can do some poking around if you give me some pointers as to where...

trygub commented 9 years ago

Hey @laughedelic , I've worked out what the problem is. It seems that gtm got somehow into a state where there are two timestamp notes attached to a single commit, e.g.

Notes (timetracker): Time-spent: 923

Time-spent: 47

This makes gtm fail on parse of notes for that commit. Not sure how this happened, but I've found 3-4 such commits and they are ordinary (non-merge) commits (with a single parent).

trygub commented 9 years ago

Hey @laughedelic , I've worked out how this happens. If gtm timer is running and a commit is made, a note is added to that commit and gtm timer is reset (but continues to run). If you then run "gtm commit --amend" (a command frequently used to tweak the commit message if something went wrong), after modification another note will be added to that commit (or more if you keep amending!).

laughedelic commented 9 years ago

Hi @trygub! Sorry, I completely forgot about this project.. Thank you for spending time to investigate this issue! :+1: Look, this is from the git help notes:

notes.rewrite.<command> When rewriting commits with <command> (currently amend or rebase), if this variable is false, git will not copy notes from the original to the rewritten commit. Defaults to true.

if notes.rewrite.amend is not set to false, the following setting defines the behaviour:

notes.rewriteMode When copying notes during a rewrite, what to do if the target commit already has a note. Must be one of overwrite, concatenate, and ignore. Defaults to concatenate.

So you can solve it by

git config --global notes.rewrite.amend false

this will overwrite notes when you do git commit --amend. Otherwise you can set it to true and then change notes.rewriteMode to something different than concatenate.

Also, take a look at these two commands:

trygub commented 9 years ago

"git config --global notes.rewrite.amend false"

worked for me --- thanks!

laughedelic commented 9 years ago

great! :+1: