From 9d4b755e4523392efd763d997896afc4c08f9f37 Mon Sep 17 00:00:00 2001 From: Adrian Cheater Date: Tue, 12 Mar 2013 12:23:46 -0500 Subject: [PATCH 1/4] Added show_files and list directory suport --- README | 4 ++++ lib/git/base.rb | 8 ++++++-- lib/git/lib.rb | 12 ++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README b/README index f202fa5e..2cb258df 100644 --- a/README +++ b/README @@ -173,7 +173,11 @@ And here are the operations that will need to write to your git repository. g.branch(name).in_branch(message) { # add files } # auto-commits g.merge('new_branch') g.merge('origin/remote_branch') +<<<<<<< HEAD g.merge(g.branch('master')) +======= + g.merge(b.branch('master')) +>>>>>>> Added show_files and list directory suport g.merge([branch1, branch2]) r = g.add_remote(name, uri) # Git::Remote diff --git a/lib/git/base.rb b/lib/git/base.rb index 5ad8906a..15ae2def 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -244,8 +244,8 @@ def diff(objectish = 'HEAD', obj2 = nil) end # adds files from the working directory to the git repository - def add(path = '.') - self.lib.add(path) + def add(path = '.',opts = {}) + self.lib.add(path,opts) end # removes file(s) from the git repository @@ -292,6 +292,10 @@ def checkout_file(version, file) self.lib.checkout_file(version,file) end + def show_file(version,file) + self.lib.show_file(version,file) + end + # fetches changes from a remote branch - this does not modify the working directory, # it just gets the changes from the remote if there are any def fetch(remote = 'origin') diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 52fb2e6c..01397e95 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -392,8 +392,10 @@ def global_config_set(name, value) command('config', ['--global', name, value], false) end - def add(path = '.') - arr_opts = ['--'] + def add(path = '.', opts={}) + arr_opts = [] + arr_opts << ['-A'] if opts[:add_remove] + arr_opts << ['--'] if path.is_a?(Array) arr_opts += path else @@ -498,6 +500,12 @@ def checkout_file(version, file) arr_opts << file command('checkout', arr_opts) end + + def show_file(version, file) + arr_opts = [] + arr_opts << "#{version}:#{file}" + command('show', arr_opts) + end def merge(branch, message = nil) arr_opts = [] From 62ecb3f46ba5267b6d0b1bb82eddceb2750e9551 Mon Sep 17 00:00:00 2001 From: Adrian Cheater Date: Tue, 12 Mar 2013 14:52:41 -0500 Subject: [PATCH 2/4] Added support for -B branch switching on checkout via :force_branch option --- lib/git/lib.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 01397e95..4752f67d 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -488,7 +488,11 @@ 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] + if( opts[:force_branch] ) + arr_opts << '-B' << opts[:force_branch] + else + arr_opts << '-b' << opts[:new_branch] if opts[:new_branch] + end arr_opts << branch command('checkout', arr_opts) From 953b8b57f492c40f672d8190a65bb3d1cc656ded Mon Sep 17 00:00:00 2001 From: Adrian Cheater Date: Tue, 12 Mar 2013 15:07:33 -0500 Subject: [PATCH 3/4] Don't provided final param if branch is nil --- lib/git/lib.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 4752f67d..05a6fbcf 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -493,7 +493,7 @@ def checkout(branch, opts = {}) else arr_opts << '-b' << opts[:new_branch] if opts[:new_branch] end - arr_opts << branch + arr_opts << branch if branch command('checkout', arr_opts) end From 8f70cc487c49744f4831ceb8c61ae1f94e671040 Mon Sep 17 00:00:00 2001 From: Adrian Cheater Date: Wed, 29 Mar 2017 15:30:06 -0500 Subject: [PATCH 4/4] Added clean command --- lib/git/base.rb | 5 ++++- lib/git/lib.rb | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/git/base.rb b/lib/git/base.rb index 15ae2def..257eda93 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -477,7 +477,10 @@ def current_branch self.lib.branch_current end - + def clean + puts "cleaning" + self.lib.clean + end end end diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 05a6fbcf..8d4cd657 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -28,6 +28,10 @@ def initialize(base = nil, logger = nil) def init command('init') end + + def clean + command('clean -f') + end # tries to clone the given repo # @@ -103,7 +107,7 @@ def revparse(string) return File.read(rev).chomp if rev command('rev-parse', string) end - + def namerev(string) command('name-rev', string).split[1] end