git-mtime

BooK on 2009-11-23T12:41:17

Ever complained that on a checkout Git did not reset the mtime of your files to the date when they were commited?

My home page is generated with Template Toolkit but a script stored in the post-receive hook. On a checkout Git only updates the files that have changed, so normally I can trust template.modtime to be correct and use it to show a Last mofidied date.

But I'm a perfectionist, and I want to be extra sure. So I created this little utility, that I called git-mtime:

    #!/bin/sh
    git log --name-only --date=iso --reverse --pretty=format:%at "$@" \
    | perl -00ln -e '($d,@f)=split/\n/;$d{$_}=$d for grep{-e}@f' \
                 -e '}{utime undef,$d{$_},$_ for keys%d'

Note that it passes all parameters to git log, so you can apply it on a subdirectory (using --), or even use the dates from another branch (though I'm not sure what use this can have).

And for extra bonus points, it uses the secret eskimo greeting operator!

Now that I have a few gadgets based on Git, I thought I might as well publish them somewhere. A quick look on Github ruled out git-tools, git-utils and git-extras (come on people, most of these things could be done with Git aliases!). git-aid (especially the plural) didn't seem like a good name either. So after looking around for synonyms, I settled on git-gadgets.

Clone it from http://github.com/book/git-gadgets.