Skip to content

Instantly share code, notes, and snippets.

@joshuaflanagan
Created June 27, 2012 01:10

Revisions

  1. joshuaflanagan created this gist Jun 27, 2012.
    27 changes: 27 additions & 0 deletions watch_git.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    # I used this to monitor changes to the .git folder during
    # my Austin on Rails lightning talk on Understanding Git.
    #
    # I ignore any changes to the .git/logs folder, because they are
    # noisy and don't add a lot to understanding.
    # If you want "the whole truth", remove the :ignore parameter below.
    #
    # ruby listen.rb <path to .git folder>
    #
    # gem install listen # its the foundation of Guard
    require 'listen'
    path_to_watch = ARGV[0] || '.'
    last_change = Time.now

    Listen.to(path_to_watch,
    :relative_paths => true,
    :ignore => /logs\//) do |modified, added, removed|
    # cheap way to add some separation between output from git commands
    latest = Time.now
    if (latest - last_change > 1)
    last_change = latest
    puts "\n\n"
    end
    modified.each{|m| puts "\e[33mCHANGED\e[0m #{m}" }
    added.each{|m| puts "\e[32m ADDED\e[0m #{m}" }
    removed.each{|m| puts "\e[31mREMOVED\e[0m #{m}" }
    end