From 98c64b8ddea95bc87afe2e4979aa3e336a72c202 Mon Sep 17 00:00:00 2001
From: Niklas Larsson <metaniklas@gmail.com>
Date: Sat, 15 Dec 2012 15:49:30 +0100
Subject: [PATCH] Add "date" command to sync-all

The date command checks out all the repos to the last commit before the
date provided. The date formats supported are the same as "git log"
supports.

Examples of use:
./sync-all date "2012-12-01"
./sync-all date "Dec 1, 2012 10:00"
---
 sync-all | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/sync-all b/sync-all
index 225ad36..2046cc3 100755
--- a/sync-all
+++ b/sync-all
@@ -182,6 +182,23 @@ sub scm {
     }
 }
 
+sub checkout_date {
+    my $dir = shift;
+    if ($dir eq '.') {
+        message "== Getting last commit before @_";
+    } else {
+        message "== $dir: Getting last commit before @_";
+        chdir($dir);
+    }
+    open(SHA,"git log -1 --before=\"@_\" --format=\"\%H\" |");
+    my $sha = <SHA>;
+    system("git checkout $sha");
+    close(SHA);
+    if ($dir ne '.') {
+        chdir($initial_working_directory);
+    }
+}
+
 sub scmall {
     my $command = shift;
 
@@ -476,6 +493,9 @@ sub scmall {
         elsif ($command eq "tag") {
             scm ($localpath, $scm, "tag", @args);
         }
+        elsif ($command eq "date") {
+            checkout_date($localpath, @args) if $scm eq "git";
+        }
         else {
             die "Unknown command: $command";
         }
-- 
1.8.0.msysgit.0

