From 743ac297402ce8713d1c58db42c8a0540cb026a8 Mon Sep 17 00:00:00 2001 From: Scott Chacon Date: Tue, 27 May 2008 12:30:45 -0700 Subject: added apply and am functions and --until to logs --- lib/git/base.rb | 11 +++++++++++ lib/git/lib.rb | 15 +++++++++++++++ lib/git/log.rb | 9 ++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) (limited to 'lib/git') diff --git a/lib/git/base.rb b/lib/git/base.rb index 43a3c0d..6ce7efe 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -367,6 +367,17 @@ module Git self.lib.gc end + def apply(file) + if File.exists?(file) + self.lib.apply(file) + end + end + + def apply_mail(file) + if File.exists?(file) + self.lib.apply_mail(file) + end + end ## LOWER LEVEL INDEX OPERATIONS ## diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 033df12..5e597ad 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -67,6 +67,7 @@ module Git arr_opts = ['--pretty=oneline'] arr_opts << "-#{opts[:count]}" if opts[:count] arr_opts << "--since=\"#{opts[:since]}\"" if opts[:since].is_a? String + arr_opts << "--until=\"#{opts[:until]}\"" if opts[:until].is_a? String arr_opts << "#{opts[:between][0].to_s}..#{opts[:between][1].to_s}" if (opts[:between] && opts[:between].size == 2) arr_opts << opts[:object] if opts[:object].is_a? String arr_opts << '-- ' + opts[:path_limiter] if opts[:path_limiter].is_a? String @@ -78,6 +79,7 @@ module Git arr_opts = ['--pretty=raw'] arr_opts << "-#{opts[:count]}" if opts[:count] arr_opts << "--since=\"#{opts[:since]}\"" if opts[:since].is_a? String + arr_opts << "--until=\"#{opts[:until]}\"" if opts[:until].is_a? String arr_opts << "#{opts[:between][0].to_s}..#{opts[:between][1].to_s}" if (opts[:between] && opts[:between].size == 2) arr_opts << opts[:object] if opts[:object].is_a? String arr_opts << '-- ' + opts[:path_limiter] if opts[:path_limiter].is_a? String @@ -387,6 +389,18 @@ module Git command('reset', arr_opts) end + def apply(patch_file) + arr_opts = [] + arr_opts << patch_file.to_s if patch_file + command('apply', arr_opts) + end + + def apply_mail(patch_file) + arr_opts = [] + arr_opts << patch_file.to_s if patch_file + command('am', arr_opts) + end + def stashes_all arr = [] filename = File.join(@git_dir, 'logs/refs/stash') @@ -429,6 +443,7 @@ module Git def checkout(branch, opts = {}) arr_opts = [] arr_opts << '-f' if opts[:force] + arr_opts << ["-b '#{opts[:new_branch]}'"] if opts[:new_branch] arr_opts << branch.to_s command('checkout', arr_opts) diff --git a/lib/git/log.rb b/lib/git/log.rb index 9437ea6..d620652 100644 --- a/lib/git/log.rb +++ b/lib/git/log.rb @@ -11,6 +11,7 @@ module Git @path = nil @count = nil @since = nil + @until = nil @between = nil @dirty_flag = nil @@ -39,6 +40,12 @@ module Git return self end + def until(date) + dirty_log + @until = date + return self + end + def between(sha1, sha2 = nil) dirty_log @between = [sha1, sha2] @@ -85,7 +92,7 @@ module Git # actually run the 'git log' command def run_log log = @base.lib.full_log_commits(:count => @count, :object => @object, - :path_limiter => @path, :since => @since, :between => @between) + :path_limiter => @path, :since => @since, :until => @until, :between => @between) @commits = log.map { |c| Git::Object::Commit.new(@base, c['sha'], c) } end -- cgit