From b5d6b907b080992c2d0220eceb66f4ffa85207cd Mon Sep 17 00:00:00 2001 From: scott Chacon Date: Wed, 7 Nov 2007 16:24:15 -0800 Subject: [PATCH] got the first round working --- README | 2 +- lib/git.rb | 49 ++++++++++++++++++++++++++++++++++++ lib/git/base.rb | 59 ++++++++++++++++++++++++++++++++++++++++++++ lib/git/index.rb | 4 +++ lib/git/path.rb | 23 +++++++++++++++++ lib/git/repository.rb | 5 ++++ lib/git/working_directory.rb | 4 +++ 7 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 lib/git/base.rb create mode 100644 lib/git/index.rb create mode 100644 lib/git/path.rb create mode 100644 lib/git/repository.rb create mode 100644 lib/git/working_directory.rb diff --git a/README b/README index fa18dc1..e881eb2 100644 --- a/README +++ b/README @@ -28,7 +28,7 @@ require 'git' # needs read permission only -g = Git.new (working_dir = '.') +g = Git.open (working_dir = '.') (git_dir, index_file) g.index diff --git a/lib/git.rb b/lib/git.rb index 8d5c79f..25dc2b3 100644 --- a/lib/git.rb +++ b/lib/git.rb @@ -4,4 +4,53 @@ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) +require 'git/base' +require 'git/path' +#require 'git/lib' +require 'git/repository' +require 'git/index' +require 'git/working_directory' + +=begin +require 'git/object' + +require 'git/object/commit' +require 'git/object/blob' +require 'git/object/tree' +require 'git/object/tag' + +require 'git/author' +require 'git/ref' +require 'git/file' + +require 'git/log' +require 'git/sha' +require 'git/diff' + +require 'git/branch' +require 'git/remote' +=end + +module Git + + def self.repo(git_dir) + Base.repo(git_dir) + end + + def self.open(working_dir, options = {}) + Base.open(working_dir, options) + end + + def clone + Base.clone() + end + + def init(working_dir = '.') + Base.clone() + end + +end + +g = Git.open('/Users/schacon/Sites/glue') +g = Git.repo('/Users/schacon/Sites/glue/.git') diff --git a/lib/git/base.rb b/lib/git/base.rb new file mode 100644 index 0000000..6eb3455 --- /dev/null +++ b/lib/git/base.rb @@ -0,0 +1,59 @@ +module Git + + class Base + + @working_directory = nil + @repository = nil + @index = nil + + # opens a Git Repository - no working directory options + def self.repo(git_dir) + self.new :repository => git_dir + end + + # opens a new Git Project from a working directory + # you can specify non-standard git_dir and index file in the options + def self.open(working_dir, opts={}) + default = {:working_directory => working_dir, + :repository => File.join(working_dir, '.git'), + :index => File.join(working_dir, '.git', 'index')} + git_options = default.merge(opts) + + self.new(git_options) + end + + def initialize(options = {}) + @working_directory = Git::Repository.new(options[:working_directory]) if options[:working_directory] + @repository = Git::Repository.new(options[:repository]) if options[:repository] + @index = Git::Index.new(options[:index]) if options[:index] + end + + def self.clone + raise NotImplementedError + end + + def self.init + raise NotImplementedError + end + + + def dir + @working_directory + end + + def repo + @repository + end + + def index + @index + end + + private + + def is_git_dir(dir) + end + + end + +end \ No newline at end of file diff --git a/lib/git/index.rb b/lib/git/index.rb new file mode 100644 index 0000000..b96eedb --- /dev/null +++ b/lib/git/index.rb @@ -0,0 +1,4 @@ +module Git + class Index < Git::Path + end +end diff --git a/lib/git/path.rb b/lib/git/path.rb new file mode 100644 index 0000000..9d6ba49 --- /dev/null +++ b/lib/git/path.rb @@ -0,0 +1,23 @@ +module Git + class Path + + attr_accessor :path + + def initialize(path) + if File.exists?(path) + @path = path + else + raise ArgumentError, "path does not exist", path + end + end + + def readable? + File.readable?(@path) + end + + def writable? + File.writable?(@path) + end + + end +end \ No newline at end of file diff --git a/lib/git/repository.rb b/lib/git/repository.rb new file mode 100644 index 0000000..d76dc8b --- /dev/null +++ b/lib/git/repository.rb @@ -0,0 +1,5 @@ +module Git + class Repository < Path + + end +end diff --git a/lib/git/working_directory.rb b/lib/git/working_directory.rb new file mode 100644 index 0000000..3f37f1a --- /dev/null +++ b/lib/git/working_directory.rb @@ -0,0 +1,4 @@ +module Git + class WorkingDirectory < Git::Path + end +end -- 2.11.4.GIT