diff --git a/.gitignore b/.gitignore index 911e38d6..ddc07ca5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ coverage rdoc pkg - +*.gem diff --git a/VERSION b/VERSION index c813fe11..5975b143 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.5 +1.2.8 \ No newline at end of file diff --git a/git.gemspec b/git.gemspec index 00e2b9f3..68e0c5de 100644 --- a/git.gemspec +++ b/git.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{git} - s.version = "1.2.5" + s.version = "1.2.13" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Scott Chacon"] diff --git a/lib/git/base.rb b/lib/git/base.rb index 5ad8906a..34e62a21 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -24,9 +24,18 @@ def self.init(working_dir, opts = {}) :working_directory => working_dir, :repository => File.join(working_dir, '.git') }.merge(opts) - + FileUtils.mkdir_p(opts[:working_directory]) if opts[:working_directory] && !File.directory?(opts[:working_directory]) - + + # Submodules have a .git *file* not a .git folder. + # This file's contents point to the location of + # where the git refs are held (In the parent repo) + if File.file?('.git') + git_file = File.open('.git').read[8..-1].strip + opts[:repository] = git_file + opts[:index] = git_file + '/index' + end + # run git_init there Git::Lib.new(opts).init @@ -264,6 +273,11 @@ def reset_hard(commitish = nil, opts = {}) self.lib.reset(commitish, opts) end + def clean(opts = {}) + opts = { :force => true, :d => true }.merge(opts) + self.lib.clean(opts) + end + # commits all pending changes in the index file to the git repository # # options: @@ -310,8 +324,12 @@ def push(remote = 'origin', branch = 'master', tags = false) # merges one or more branches into the current working branch # # you can specify more than one branch to merge by passing an array of branches - def merge(branch, message = 'merge') - self.lib.merge(branch, message) + def merge(branch, message = 'merge', arr = []) + self.lib.merge(branch, message, arr) + end + + def rebase(branch) + self.lib.rebase(branch) end # iterates over the files which are unmerged @@ -320,9 +338,8 @@ def each_conflict(&block) # :yields: file, your_version, their_version end # fetches a branch from a remote and merges it into the current working branch - def pull(remote = 'origin', branch = 'master', message = 'origin pull') - fetch(remote) - merge(branch, message) + def pull(remote = nil, branch = nil) + self.lib.pull(remote, branch) end # returns an array of Git:Remote objects diff --git a/lib/git/branch.rb b/lib/git/branch.rb index 15101b33..a0b3bff0 100644 --- a/lib/git/branch.rb +++ b/lib/git/branch.rb @@ -9,13 +9,13 @@ def initialize(base, name) @base = base @gcommit = nil @stashes = nil - + parts = name.split('/') - if parts[1] + if parts[0] == 'remotes' @remote = Git::Remote.new(@base, parts[0]) - @name = parts[1] + @name = parts[2..-1].join('/') else - @name = parts[0] + @name = name end end @@ -77,6 +77,11 @@ def merge(branch = nil, message = nil) @base.merge(@name) end end + + def rebase(branch) + @base.rebase(branch) + end + def update_ref(commit) @base.lib.update_ref(@full, commit) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 52fb2e6c..0d6c375f 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -144,7 +144,9 @@ def process_commit_data(data, sha = nil, indent = 4) value = data.join(' ') if key == 'commit' sha = value - hsh_array << hsh if hsh + if hsh_array + hsh_array << hsh if hsh + end hsh = {'sha' => sha, 'message' => '', 'parent' => []} end if key == 'parent' @@ -429,6 +431,13 @@ def reset(commit, opts = {}) arr_opts << commit if commit command('reset', arr_opts) end + + def clean(opts = {}) + arr_opts = [] + arr_opts << '--force' if opts[:force] + arr_opts << '-d' if opts[:d] + command('clean', arr_opts) + end def apply(patch_file) arr_opts = [] @@ -486,7 +495,7 @@ def branch_delete(branch) def checkout(branch, opts = {}) arr_opts = [] arr_opts << '-f' if opts[:force] - arr_opts << '-b' << opts[:new_branch] if opts[:new_branch] + arr_opts << '-b' if opts[:new_branch] arr_opts << branch command('checkout', arr_opts) @@ -499,13 +508,23 @@ def checkout_file(version, file) command('checkout', arr_opts) end - def merge(branch, message = nil) - arr_opts = [] + def merge(branch, message = nil, arr_opts = []) arr_opts << '-m' << message if message arr_opts += [branch] command('merge', arr_opts) end + def rebase(branch) + command('rebase', [branch]) + end + + def pull(remote = nil, branch = nil) + opts = [] + opts << remote if remote + opts << branch if branch + command('pull', opts) + end + def unmerged unmerged = [] command_lines('diff', ["--cached"]).each do |line| diff --git a/ruby-git.gemspec b/ruby-git.gemspec index d42ff3d9..3c9d683a 100644 --- a/ruby-git.gemspec +++ b/ruby-git.gemspec @@ -1,7 +1,7 @@ spec = Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = "git" - s.version = "1.1.1" + s.version = "1.1.13" s.author = "Scott Chacon" s.email = "schacon@gmail.com" s.homepage = "http://github.com/schacon/ruby-git/tree/master"