autogit icon indicating copy to clipboard operation
autogit copied to clipboard

AutoGit is an automatic package manager for Ruby (alternative to RubyGems)

AutoGit is an easy way to require specific versions of libraries, stored in git repositories. Basically, AutoGit is a smart and yet simple alternative to RubyGems. Any git-tracked gem can be required using autogit(url, commmitish) instead of gem(name, version).

EXAMPLE

Instead of:

system("sudo gem install oleganza-gem_console")
gem "oleganza-gem_console", "0.1"
require "gem_console"

you write:

autogit 'git://github.com/oleganza/gem_console.git', '0.1'
require "gem_console"

You can also specify any valid git commitish in place of version (e.g. "f2c55bd10cd9ca") Branch names are valid too, but don't expect AutoGit to update your branch heads automatically. After all, it is a bad practice to specify a branch head (the version is unknown in this case)

HOW IT WORKS

Suppose we have the following definition:

autogit 'git://github.com/oleganza/gem_console.git', 'f2c55bd10cd9cae14e5bf7bde523ac3a7b66561a'
  1. autogit creates a bare repository (--no-checkout):
~/.autogit/repositories/github.com-oleganza-gem_console
  1. Clones local repository with --shared flag into:
~/.autogit/checkouts/github.com-oleganza-gem_console/f2c55bd10cd9cae14e5bf7bde523ac3a7b66561a
  1. Checks out f2c55bd10cd9cae14e5bf7bde523ac3a7b66561a commit inside that repo

  2. Adds a checked out path to the $LOAD_PATH If ./lib subfolder exists, it is used instead (i.e. gem-like load path)

To clean a cache of checked out revisions: $ rm -rf ~/.autogit/checkouts

The library is very simple and could be easily extended whenever you need to. The following code shows how a list of gems could be organized for different environments:

sources = %w{ git://github.com/ git@localhost:github/ ~/github/ } libs = { "oleganza/declarations" => "f05be8ca8a77", "oleganza/autogit" => "84b14f0df", "rails/rails" => "2.2.2", "yrashk/strokedb" => "0.2.1" }

libs.each do |path, commit| autogit(sources.map{|s| s + path }, commit) end

HOW TO USE AUTOGIT IN A LIBRARY (GEM)

  1. Put all specifications into if defined?(AutoGit)...end block. This is crucial to let folks use your library without AutoGit (e.g. as a rubygem)
  2. Application may specify rewrite rules (AutoGit.rewrite) to modify URLs: remove, rewrite or append a mirror. (see comments in source code and examples/*.rb)

TODO

  • integration tests to cover all interesting cases

NOTES

  1. It is a bad idea to check out branch heads, so i don't even try to implement automatic pull for checkouts.
  2. There is no executable script like "gem install" or "gem update". AutoGit is, huh, "auto".
  3. To fix or optimize your repositories, go to ~/.autogit folder and use standard git tools.
  4. --quiet flag is not used to inform user when initial cloning or checkout is performed. Second run will not emit any verbose output.

META

Author: Oleg Andreev [email protected] Date: January 29, 2009 License: WTFPL http://sam.zoy.org/wtfpl/