Skip to content

Commit

Permalink
Allow overriding the time spent working.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcrowley committed Jan 7, 2011
1 parent 735e571 commit c954154
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
8 changes: 5 additions & 3 deletions bin/gpend
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

set -e

#/ Usage: gpend [-m <message>] [-b <branch>] [-r <repo>]
#/ Usage: gpend [-m <message>] [-t <time>] [-b <branch>] [-r <repo>]
#/ -m commit message
#/ -t override time spent on this work session
#/ -b branch name (default master)
#/ -r repository path (default ~/.gitpaid)
#/ -h show this help message

. "$(dirname "$(dirname "$0")")/lib/gp.sh"

while getopts m:b:r:h NAME
while getopts m:t:b:r:h NAME
do
case "$NAME" in
m) MESSAGE="$OPTARG";;
t) TIME="$OPTARG";;
b) BRANCH="$OPTARG";;
r) REPO="$OPTARG";;
h)
Expand All @@ -38,4 +40,4 @@ gpinit
exit 1
}

gpcommit "$MESSAGE"
gpcommit "$MESSAGE" "$TIME"
12 changes: 10 additions & 2 deletions bin/gpinvoice
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ gpworkbegin() {
gpworkend() {
echo
echo "Ended: $(git show "$1" --pretty=format:%aD)"
MINUTES="$((($(git show "$1" --pretty=format:%at) - $BEGIN) / 60))"
AUTHOR_DATE="$(git show "$1" --pretty=format:%at)"
COMMITTER_DATE="$(git show "$1" --pretty=format:%ct)"
echo "AUTHOR_DATE: $AUTHOR_DATE, COMMITTER_DATE: $COMMITTER_DATE" >&2
[ "$AUTHOR_DATE" = "$COMMITTER_DATE" ] && {
MINUTES="$((($AUTHOR_DATE - $BEGIN) / 60))"
echo "Billed time: $(gpprettytime "$MINUTES")"
} || {
MINUTES="$(($COMMITTER_DATE - 1000000000))"
echo "Billed time (adjusted): $(gpprettytime "$MINUTES")"
}
echo "$MINUTES" >&3
echo "Billed time: $(gpprettytime "$MINUTES")"
}

HEAD="$(git rev-parse "$BRANCH")"
Expand Down
20 changes: 20 additions & 0 deletions lib/gp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ gpcommit() {
# done.
TREE="$(git write-tree)"

# Override the committer's date with the number of minutes to count for
# this work session.
[ -n "$2" ] && {
export GIT_COMMITTER_DATE="$((1000000000 + $(gpminutes "$2"))) +0000"
}

# Commit the tree with the user's message.
PARENT="$(git rev-parse --verify "$BRANCH" 2>/dev/null || true)"
[ -z "$PARENT" ] && {
Expand All @@ -34,11 +40,25 @@ gpcommit() {
COMMIT="$(echo "$1" | git commit-tree "$TREE" -p "$PARENT")"
}

# Clean up after overriding the date.
[ -n "$2" ] && unset GIT_COMMITTER_DATE

# Update the tip of the branch to reference the new commit.
echo "$COMMIT" >"refs/heads/$BRANCH"

}

gpminutes() {
echo "$1" | grep '^[0-9]*:[0-9][0-9]$' >/dev/null && {
HOURS="$(echo "$1" | cut -d: -f1)"
MINUTES="$(echo "$1" | cut -d: -f2)"
} || {
HOURS=0
MINUTES="$1"
}
echo "$((60 * $HOURS + $MINUTES))"
}

gpprettytime() {
[ -z "$1" ] && {
echo "0:00"
Expand Down
4 changes: 3 additions & 1 deletion man/man1/gpend.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ gpend(1) -- document the end of a work session

## SYNOPSIS

`gpend` [`-m` _message_] [`-b` _branch_] [`-r` _repo_]
`gpend` [`-m` _message_] [`-t` _time_] [`-b` _branch_] [`-r` _repo_]

## DESCRIPTION

Expand All @@ -15,6 +15,8 @@ gpend(1) -- document the end of a work session

* `-m` _message_:
Commit message.
* `-t` _time_:
Override time spent on this work session.
* `-b` _branch_:
Branch name (default _master_).
* `-r` _repo_:
Expand Down

0 comments on commit c954154

Please sign in to comment.