From b5d6b907b080992c2d0220eceb66f4ffa85207cd Mon Sep 17 00:00:00 2001 From: scott Chacon Date: Wed, 7 Nov 2007 16:24:15 -0800 Subject: got the first round working --- 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 +++ 5 files changed, 95 insertions(+) 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 (limited to 'lib/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 -- cgit