Simple time logging on top of git flow
My current team found out that we should have tracked some time over the last year. Extracting timelogs in retrosepct is not fun. Git helps a lot, combined with chat-logs from Slack, Google Calendars will give a good basis. A day of grep, sed, and awk, and you have some time-logs.
I decided that from now on, I want to track what I start and finish working on in a basic log. And I am using git with
git-flow by Peter van der Does, which is what you get when you
apt-get install git-flow
. This allows special git-flow hooks.
I want this to write logs to a simple textfile. But have a place where I could call external APIs to insert some tracking data into external trackers, when my team uses these.
The result is certainly not a replacement for actual timetracking. But a log that will aide with answering “when did you work on what?”.
These will be written out when using
It requires you to work with git-flow and use feature branches for everything. But you should use topic branches anyway.
Git-flow triggers its own hooks. So just create a simple utility script that is exectuable and logs an activity, or calls an external API or whatever you are using. Then call that script from the git-flow hooks.
Note that, as far as I can tell, the upsteam git-flow by nvie himself, does not have own git-hooks. Peter van der Does’ fork has this. Which is also the source used for the Debian package (so also for Ubuntu).
Write that to e.g. ~/bin/log-git-flow-feature
and make executable with
chmod +x ~/bin/log-git-flow-feature
.
Note: when you create scripts with git-foo
a subcommand git foo
is made available. You probably don’t want to name this
script git-flow-log-feature
or so, to prevent git flow log
from becoming
a command.
Now just add two hooks and make them exectuable. This will add hooks to a specific git repo:
When I need to call an external time-tracker, the ~/bin/log-git-flow-feature
script is the place to do this. An example:
I’ve create a gist with the contents of the files so if you want to enhance it, feel free to fork it!
There is a lot of room for improvement:
- make this work with “generic” git-hooks instead of relying on git-flow. Should probably match against patterns in branches that are created, merged, rebased etc.
- map directories with projects, log name of the project.
- don’t use “pwd” but determine the actual working copy of git instead, to allow this to work with fancy setups or when working from within subdirectories.
- log
git flow feature checkout
as well, to log switching between (long)running branches. - fall back on generic git-hooks