<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/gitty_migrator.rb</filename>
    </added>
    <added>
      <filename>lib/migration_settings.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -2,7 +2,7 @@ GittyMigrations
 ===============
 
 Requires a extended 'rubygit' gem that has stashes
-cd vendor/plugins/smart_migrations/extended_rubygit_gem
+cd vendor/plugins/gitty_migrations/extended_rubygit_gem
 sudo gem install git-1.0.5
 
 Example
@@ -10,11 +10,7 @@ Example
 
 class MyMigration &lt; ActiveRecord::Migration
   
-	# Would be better if you used a git-tag to tag the revision
-	# You now don't have to put in a sha1 hash. If you don't it will take the migration that you migration was checked in on
-  use_git_revision
-	# or
-	# use_git_revision &quot;675bacdd870a098a98aa3f858d92e1047ba28a7d&quot; # if you want to be explicit
+  git_fu
 
   def self.up
     puts &quot;This is a test migration&quot;</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,6 @@
 require 'git'
+require 'migration_settings'
 require 'gitty_migration'
-ActiveRecord::Migration.send(:include, GittyMigration)
\ No newline at end of file
+#require 'gitty_migrator'
+#ActiveRecord::Migrator.send(:extend, GittyMigrator)
+ActiveRecord::Migration.send(:include, GittyMigration)</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -19,91 +19,64 @@ module GittyMigration
   
   def self.included(base)
     base.extend ClassMethods
-    base.class_eval do
-      class &lt;&lt; self
-        alias_method_chain :migrate, :git
-      end
-    end
   end
   
   module ClassMethods
-    
-    @@gitty_migration ||= {}
-    @@gitty_migration[:enabled] = false
-        
-    def use_git_revision(revision_name=nil)
-      g = Git.open(&quot;#{RAILS_ROOT}&quot;)
-      raise &quot;Couldn't find the .git directory. Does this project use git?&quot; if g.nil?
-  
-      # TODO
-      # See if there are any stashes already. If there arent' then set a flag to clear the stash after we are done.
-      @@gitty_migration[:git] = g
-      @@gitty_migration[:enabled] = true
-      @@gitty_migration[:stash] = (g.status.changed.size &gt; 0) ? true : false
-      @@gitty_migration[:clear_stash] = (g.branch.stashes.size &gt; 0) ? true : false
-      @@gitty_migration[:branch] = &quot;smart_migration_&quot;.concat Digest::MD5.hexdigest(&quot;#{Time.now}-#{revision_name}&quot;)
-      @@gitty_migration[:revision] = revision_name
-      @@gitty_migration[:original_branch] = g.branch.name
-    end
-
-    def migrate_with_git(direction, migration_version)      
-      before_migrate(migration_version) if @@gitty_migration[:enabled] == true
-      migrate_without_git(direction)
-      after_migrate if @@gitty_migration[:enabled] == true
-    end
-
-    def before_migrate(migration_version)
-      m = @@gitty_migration
-      if m[:enabled]
-        g = m[:git]
-        
-        if m[:revision].nil?
-          filename = &quot;#{migration_version}_#{self.to_s.underscore}.rb&quot;
-          file = Dir[&quot;db/migrate/0*#{filename}&quot;].first
-          commit = g.log(1000).object(file).each{|c|c}.reverse.first
-          #puts commit.author.name
-          #puts commit.author.email
-          #puts commit.author.date.to_s
-          #puts commit.sha
-          @@gitty_migration[:revision] = commit.sha
-        end
         
-        say &quot;Migrating with git revision #{m[:revision]}&quot;
-        
-        g.branch(m[:original_branch]).stashes.save(m[:revision]) if @@gitty_migration[:stash]
-        g.branch(m[:branch]).checkout
-        commit = g.gcommit(&quot;#{m[:revision]}&quot;)
-
-        # If we can't find the commit, 
-        # let the user know and revert back to the original branch
-        if commit.nil?
-          say &quot;Could not find git revision #{m[:revision]}. Using HEAD&quot;
-          revert_to_original
-        else
-          g.reset_hard(commit)
+    def git_fu
+      class_eval do
+        class &lt;&lt; self
+          alias_method_chain :migrate, :git
         end
-        
       end
     end
 
-    def after_migrate
-      revert_to_original
+    def migrate_with_git(direction, version)
+      settings = MigrationSettings.new(
+        :version =&gt; version,
+        :klass =&gt; self.to_s.underscore
+      )
+      before_migrate(settings) 
+      migrate_without_git(direction)
+      after_migrate(settings)
     end
 
-    def revert_to_original
-      m = @@gitty_migration
-      if m[:enabled]
-        say &quot;Done migration. Switching back to your normal branch&quot;
-        g = @@gitty_migration[:git]
-        g.branch(m[:original_branch]).checkout
-        g.branch(m[:original_branch]).stashes.apply if @@gitty_migration[:stash]
-        # g.branch(m[:original_branch]).stashes.clear if @@gitty_migration[:clear_stash]
-        g.branch(m[:branch]).delete
-        # If we've already deleted the branch, then don't revert again
-        # revert_to_original will be called in the after migrate even if we couldn't find the commit
-        @@gitty_migration[:enabled] = false
+    def before_migrate(settings)
+      g = settings.git
+      # Find the commit that matches your sha1
+      commit = g.gcommit(&quot;#{settings.revision}&quot;)
+      # If we can't find the commit, continue without using gitty migrations
+      if commit.nil?
+        say &quot;Could not find git sha1 that matches '#{settings.revision}'. The migration will continue without git_fu&quot;
+      else
+        say &quot;Migrating with git&quot;
+        say &quot;SHA1: #{settings.revision}&quot;
+        say &quot;AUTHOR: #{settings.revision_author}&quot;
+        say &quot;DATE: #{settings.revision_date}&quot;
+        say &quot;MESSAGE: #{settings.revision_message}&quot;
+        # Stash any changes that you may have in your current branch
+        g.branch(settings.original_branch).stashes.save(settings.revision) if settings.stash?
+        # Checkout a new branch to use for your migration
+        g.branch(settings.migration_branch).checkout
+        # Rollback to the commit that you wanted
+        g.reset_hard(commit)
       end
     end
     
+    def after_migrate(settings)
+      say &quot;Done migration. Switching back to your normal branch&quot;
+      g = settings.git
+      # Checkout your original branch
+      g.branch(settings.original_branch).checkout
+      # Apply your stash if you have one
+      g.branch(settings.original_branch).stashes.apply if settings.stash?
+      # Clear your stashes if you have only the one that we used
+      # g.branch(m[:original_branch]).stashes.clear if @@gitty_migration[:clear_stash]
+      # Delete the branch that you used for the migration
+      g.branch(settings.migration_branch).delete
+      # If we've already deleted the branch, then don't revert again
+      # revert_to_original will be called in the after migrate even if we couldn't find the commit
+    end
+    
   end
 end</diff>
      <filename>lib/gitty_migration.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d645f8d4ce786f55c23fd5aced0535c76ce62c0d</id>
    </parent>
  </parents>
  <author>
    <name>Eric Goodwin</name>
    <email>eric@ericgoodwin.com</email>
  </author>
  <url>http://github.com/ericgoodwin/gitty-migrations/commit/0fdf502ece8922723be1fd54df4bbe0b9f5de11c</url>
  <id>0fdf502ece8922723be1fd54df4bbe0b9f5de11c</id>
  <committed-date>2008-03-30T18:29:18-07:00</committed-date>
  <authored-date>2008-03-30T18:29:18-07:00</authored-date>
  <message>Clean up
Moved most of the settings into the migration settings class
Updated the README</message>
  <tree>f6471633f1585e0b58782eb2cdfdcfed4074dc4f</tree>
  <committer>
    <name>Eric Goodwin</name>
    <email>eric@ericgoodwin.com</email>
  </committer>
</commit>
