diff --git a/VERSION b/VERSION deleted file mode 100644 index c813fe11..00000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.2.5 diff --git a/lib/git/base.rb b/lib/git/base.rb index 5ad8906a..9129514e 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -181,8 +181,11 @@ def branches end # returns a Git::Branch object for branch_name - def branch(branch_name = 'master') - Git::Branch.new(self, branch_name) + # -- addition of options noticeably to implement + # --t switch on 'git branch' command + def branch(branch_name = 'master', options={}) + # + Git::Branch.new(self, branch_name, options[:track]) end # returns +true+ if the branch exists locally @@ -460,8 +463,11 @@ def revparse(objectish) self.lib.revparse(objectish) end - def ls_tree(objectish) - self.lib.ls_tree(objectish) + # -- addition of options noticeably to implement + # a recursive ls_tree + def ls_tree(objectish, options={}) + # + self.lib.ls_tree(objectish, options) end def cat_file(objectish) diff --git a/lib/git/branch.rb b/lib/git/branch.rb index 15101b33..01765e43 100644 --- a/lib/git/branch.rb +++ b/lib/git/branch.rb @@ -3,20 +3,25 @@ class Branch < Path attr_accessor :full, :remote, :name - def initialize(base, name) + # -- addition of track parameter for --t switch + def initialize(base, name, track=nil) + # @remote = nil @full = name @base = base @gcommit = nil @stashes = nil - parts = name.split('/') - if parts[1] - @remote = Git::Remote.new(@base, parts[0]) - @name = parts[1] - else - @name = parts[0] + # -- addition of track attribute to implement + # --t switch + @track = track + name, remote = name.split(' ').first.split('/').reverse + if remote + @remote = Git::Remote.new(@base, remote) + name = "#{remote}/#{name}" end + @name = name + # end def gcommit @@ -93,7 +98,9 @@ def to_s private def check_if_create - @base.lib.branch_new(@name) rescue nil + # -- addition of track attribute + @base.lib.branch_new(@name, @track) rescue nil + # end def determine_current diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 52fb2e6c..b1dda932 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -50,10 +50,14 @@ def clone(repository, name, opts = {}) arr_opts << "-o" << opts[:remote] if opts[:remote] arr_opts << "--depth" << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0 + # -- allow processing of switches added as array elements + Array(opts[:switches]).each { |switch| arr_opts << switch } + # + arr_opts << '--' arr_opts << repository arr_opts << clone_dir - + command('clone', arr_opts) opts[:bare] ? {:repository => clone_dir} : {:working_directory => clone_dir} @@ -72,7 +76,12 @@ def log_commits(opts = {}) arr_opts << "--author=#{opts[:author]}" if opts[:author].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 + + # -- always add '--' at the end of command line to allow git to + # understand commands like 'git log `branch`' + arr_opts << '--' + arr_opts << opts[:path_limiter] if opts[:path_limiter].is_a? String + # command_lines('log', arr_opts, true).map { |l| l.split.first } end @@ -87,7 +96,11 @@ def full_log_commits(opts = {}) arr_opts << "--author=#{opts[:author]}" if opts[:author].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 + + # + arr_opts << '--' + arr_opts << opts[:path_limiter] if opts[:path_limiter].is_a? String + # full_log = command_lines('log', arr_opts, true) process_commit_data(full_log) @@ -167,10 +180,17 @@ def object_contents(sha, &block) command('cat-file', ['-p', sha], &block) end - def ls_tree(sha) + def ls_tree(sha, options={}) + # -- implement recursive ls-tree + command_args = [] + command_args << '-r' if options[:recursive] + command_args << sha + # data = {'blob' => {}, 'tree' => {}} - command_lines('ls-tree', sha).each do |line| + # + command_lines('ls-tree', command_args).each do |line| + # (info, filenm) = line.split("\t") (mode, type, sha) = info.split data[type][filenm] = {:mode => mode, :sha => sha} @@ -287,6 +307,7 @@ def diff_index(treeish) command_lines('diff-index', treeish).each do |line| (info, file) = line.split("\t") (mode_src, mode_dest, sha_src, sha_dest, type) = info.split + type = 'A' if type == 'M' && sha_dest !~ /^0+$/ hsh[file] = {:path => file, :mode_repo => mode_src.to_s[1, 7], :mode_index => mode_dest, :sha_repo => sha_src, :sha_index => sha_dest, :type => type} end @@ -474,11 +495,15 @@ def stash_clear def stash_list command('stash list') end - - def branch_new(branch) - command('branch', branch) + + # -- implement --t switch on git branch command + def branch_new(branch, track=nil) + options = [branch] + options << '--t' << track if track + command('branch', options) end - + # + def branch_delete(branch) command('branch', ['-D', branch]) end @@ -486,8 +511,25 @@ 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 << branch + + # -- implementation of a working -b switch + # for git checkout command + arr_opts << '-b' if opts[:new_branch] + # -- this push is legacy + # i don't understand it and congratulate + # myself not to try to and just leave it here + arr_opts << opts[:new_branch] if opts[:new_branch] && !opts[:new_branch].is_a?(TrueClass) + # + + arr_opts << branch if branch + + # -- we can 'git checkout `sha`' now + arr_opts << opts[:commit] if opts[:commit] + # + + # -- checkout paths + arr_opts.push '--', *opts[:files] if opts[:files] + # command('checkout', arr_opts) end diff --git a/lib/git/log.rb b/lib/git/log.rb index e0dba497..37af4712 100644 --- a/lib/git/log.rb +++ b/lib/git/log.rb @@ -90,6 +90,15 @@ def first @commits.first rescue nil end + # -- how come we have a first and not + # a last ? + # well, there you go now + def last + check_log + @commits.last rescue nil + end + # + private def dirty_log diff --git a/lib/git/version.rb b/lib/git/version.rb new file mode 100644 index 00000000..368ab7ad --- /dev/null +++ b/lib/git/version.rb @@ -0,0 +1,4 @@ +module Git + VERSION = "1.2.6" +end + diff --git a/tests/all_tests.rb b/tests/all_tests.rb index d671b240..2ca7f088 100644 --- a/tests/all_tests.rb +++ b/tests/all_tests.rb @@ -1,4 +1,5 @@ -Dir.chdir(File.dirname(__FILE__)) do - Dir.glob('**/test_*.rb') { |test_case| require test_case } - #Dir.glob('**/test_index.rb') { |test_case| require test_case } +test_dir = File.dirname __FILE__ + +Dir.chdir(test_dir) do + Dir.glob('**/test_*.rb') { |test_case| puts File.join(test_dir, test_case); require File.join(test_dir, test_case) } end