Skip to content

Instantly share code, notes, and snippets.

@ikonst
Created March 31, 2014 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikonst/9896580 to your computer and use it in GitHub Desktop.
Save ikonst/9896580 to your computer and use it in GitHub Desktop.
git commit message filter that adds the original committer timestamp to the comment. (This is due to the fact that it's impossible to specify a timestamp during TFS checkin.)
#!/usr/bin/perl
#
# Execute with:
#
# git filter-branch -f --msg-filter 'perl /path/to/git_tfs_add_date.pl' HEAD
#
use POSIX;
open INPUT, "<-";
$ENV{'GIT_COMMITTER_DATE'} =~ /^@(.*) \+(\d\d)(\d\d)/;
# Unix timestamp, timezone hours, timezone minutes
($c,$zh,$zm) = ($1,$2,$3);
$comment = join('', <INPUT>);
# Convert into time_t without system timezone offseting
# but add the timezone ourselves
$time = gmtime ($c + (3600*$zh) + $zm);
$iso_date = strftime("%Y-%m-%d %H:%M:%S", $time);
# Format the comment date
$comment_date = "${iso_date} +$zh$zm";
# Chop off the last newline, so we could check whether the comment is empty
chomp $comment;
# If there's a comment, print the comment with two pending newlines
print "$comment$/$/" if ($comment ne '');
# Avoid printing last EOL so TFS comments won't have a trailing empty line
print "(git timestamp: ${comment_date})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment