Skip to content

Instantly share code, notes, and snippets.

@tueda
Last active October 19, 2015 12:53
Show Gist options
  • Select an option

  • Save tueda/6a7c81745b612c28dd4f to your computer and use it in GitHub Desktop.

Select an option

Save tueda/6a7c81745b612c28dd4f to your computer and use it in GitHub Desktop.
Print the last commit date of the current repository. #bin
#! /bin/sh
# Get the last commit date from the repository.
if [ -d .git ] || [ -d ../.git ] || [ -d ../../.git ] || [ -d ../../../.git ] || [ -d ../../../../.git ] ; then
date=`git log -1 --format=%ci`
elif [ -d .svn ]; then
date=`svn info | grep '^Last Changed Date:' | sed 's/.*Last Changed Date: *\([^(]*\)(.*/\1/'`
elif [ -d CVS ]; then
date=`cvs log -N 2>/dev/null | grep '^date:' | sort | tail -n 1 | sed 's/.*date: *\([^;]*\);.*/\1/' | sed 's|/|-|g'`' +0000'
else
# Or the current time.
date=`perl -e '
my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(time);
printf "%04d-%02d-%02d %02d:%02d:%02d +0000\n", $year + 1900, $mon + 1, $mday, $hour, $min, $sec;
'`
fi
# Now $date looks like 'YYYY-MM-DD hh:mm:ss +timezone'.
perl -e '
use POSIX;
my $YYYY = $ARGV[0]; $YYYY =~ s/(....)-..-.. ..:..:.. ...../$1/;
my $MM = $ARGV[0]; $MM =~ s/....-(..)-.. ..:..:.. ...../$1/;
my $DD = $ARGV[0]; $DD =~ s/....-..-(..) ..:..:.. ...../$1/;
my $hh = $ARGV[0]; $hh =~ s/....-..-.. (..):..:.. ...../$1/;
my $mm = $ARGV[0]; $mm =~ s/....-..-.. ..:(..):.. ...../$1/;
my $ss = $ARGV[0]; $ss =~ s/....-..-.. ..:..:(..) ...../$1/;
my $ds = $ARGV[0]; $ds =~ s/....-..-.. ..:..:.. (.)..../$1/;
my $dhh = $ARGV[0]; $dhh =~ s/....-..-.. ..:..:.. .(..)../$1/;
my $dmm = $ARGV[0]; $dmm =~ s/....-..-.. ..:..:.. ...(..)/$1/;
#print "$YYYY $MM $DD $hh $mm $ss $ds $dhh $dmm\n";
my $time = mktime($ss, $mm, $hh, $DD, $MM - 1, $YYYY - 1900);
if ($ds eq "+") {
$time -= ($dhh * 60 + $dmm) * 60;
} else {
$time += ($dhh * 60 + $dmm) * 60;
}
my ($sec, $min, $hour, $mday, $mon, $year) = localtime($time);
my @monthes = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
printf "%3s %2d %4d\n", $monthes[$mon], $mday, $year + 1900;
' "$date"
# The result looks like 'Feb 29 2012' in UTC.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment