From 6987d584abec6e05ea7d912ddd2bfafed831b56b Mon Sep 17 00:00:00 2001 From: lacravate Date: Tue, 16 Oct 2012 03:35:44 +0200 Subject: [PATCH 01/11] tests are deprecated, broken, old... I give up, not funny...; i'll spec this through its use by other libs --- tests/all_tests.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 From ae8a0677995ada2b0ff889d2a3b22b9b732cc9ba Mon Sep 17 00:00:00 2001 From: lacravate Date: Tue, 16 Oct 2012 03:37:59 +0200 Subject: [PATCH 02/11] add switches support for as passed through the command line --- lib/git/lib.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 52fb2e6c..cf8a9b5e 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -50,6 +50,9 @@ 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 + # + arr_opts << opts[:switches].join(' ') unless opts[:switches].nil? + arr_opts << '--' arr_opts << repository arr_opts << clone_dir From e8042063a7ed19831fc8579621ae0177346df7fa Mon Sep 17 00:00:00 2001 From: lacravate Date: Tue, 16 Oct 2012 03:39:07 +0200 Subject: [PATCH 03/11] fixes tracked files type casting --- lib/git/lib.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index cf8a9b5e..9bc9d477 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -290,6 +290,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 From 438798ea534063350f3a21ec9cd76840c3a7f8b0 Mon Sep 17 00:00:00 2001 From: lacravate Date: Thu, 1 Nov 2012 01:19:54 +0100 Subject: [PATCH 04/11] implementation of --t switch on git branch command --- lib/git/base.rb | 7 +++++-- lib/git/branch.rb | 23 +++++++++++++++-------- lib/git/lib.rb | 12 ++++++++---- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/git/base.rb b/lib/git/base.rb index 5ad8906a..c432e3a7 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 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 9bc9d477..e1cf3506 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -478,11 +478,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 From c1910e58a4e762f1be2c17601496a5be85f007e5 Mon Sep 17 00:00:00 2001 From: lacravate Date: Thu, 1 Nov 2012 01:21:15 +0100 Subject: [PATCH 05/11] implementation of recursive ls-tree --- lib/git/base.rb | 7 +++++-- lib/git/lib.rb | 11 +++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/git/base.rb b/lib/git/base.rb index c432e3a7..9129514e 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -463,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/lib.rb b/lib/git/lib.rb index e1cf3506..11bcc49b 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -170,10 +170,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} From c9456859ec2be351e63e07170774bde918f69415 Mon Sep 17 00:00:00 2001 From: lacravate Date: Thu, 1 Nov 2012 01:23:17 +0100 Subject: [PATCH 06/11] better management of switches on git clone --- lib/git/lib.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 11bcc49b..6ebfee8f 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -50,8 +50,9 @@ 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 << opts[:switches].join(' ') unless opts[:switches].nil? arr_opts << '--' arr_opts << repository From 8b5796d0a9269d97e456eb224a70157fc8b3f0ee Mon Sep 17 00:00:00 2001 From: lacravate Date: Thu, 1 Nov 2012 01:25:12 +0100 Subject: [PATCH 07/11] we can git log branch now --- lib/git/lib.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 6ebfee8f..e0f05605 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -76,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 @@ -91,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) From 82273642b4c3e92eee319fa3acc73981717d9fbc Mon Sep 17 00:00:00 2001 From: lacravate Date: Thu, 1 Nov 2012 01:26:40 +0100 Subject: [PATCH 08/11] checkout to sha and checkout -b --- lib/git/lib.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index e0f05605..1bed98f3 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -511,8 +511,21 @@ 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] + + # -- 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 + + # -- we can 'git checkout `sha`' now + arr_opts << opts[:commit] if opts[:commit] + # command('checkout', arr_opts) end From 81217034eb5adbcfdb196e568256a1f234b03e74 Mon Sep 17 00:00:00 2001 From: lacravate Date: Thu, 1 Nov 2012 01:27:21 +0100 Subject: [PATCH 09/11] last commit --- lib/git/log.rb | 9 +++++++++ 1 file changed, 9 insertions(+) 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 From 4d40338f36ad2fc4cebe41596450b7710d95409b Mon Sep 17 00:00:00 2001 From: lacravate Date: Wed, 7 Nov 2012 15:00:17 +0100 Subject: [PATCH 10/11] a little addition to deal "checkout file" with this checkout method --- lib/git/lib.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 1bed98f3..b1dda932 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -57,7 +57,7 @@ def clone(repository, name, opts = {}) arr_opts << '--' arr_opts << repository arr_opts << clone_dir - + command('clone', arr_opts) opts[:bare] ? {:repository => clone_dir} : {:working_directory => clone_dir} @@ -521,12 +521,16 @@ def checkout(branch, opts = {}) arr_opts << opts[:new_branch] if opts[:new_branch] && !opts[:new_branch].is_a?(TrueClass) # - arr_opts << branch + 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 From a9020652f67096e357d1df65555894f52a9a20d2 Mon Sep 17 00:00:00 2001 From: lacravate Date: Wed, 14 Nov 2012 02:00:47 +0100 Subject: [PATCH 11/11] Bump to 1.2.6 --- VERSION | 1 - lib/git/version.rb | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) delete mode 100644 VERSION create mode 100644 lib/git/version.rb 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/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 +