Created
March 31, 2014 16:43
-
-
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.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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