From b28cc1180883d9f43500af5fedd2446746c1a2f2 Mon Sep 17 00:00:00 2001 From: Adam Byrtek Date: Fri, 14 Aug 2009 23:53:18 +0200 Subject: [PATCH 6/8] Optional new_path argument to checkout supported by all SCMs. --- lib/source_control/bazaar.rb | 8 ++++---- lib/source_control/git.rb | 10 +++++----- lib/source_control/mercurial.rb | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/source_control/bazaar.rb b/lib/source_control/bazaar.rb index 8d7e6b5..edb9f8a 100644 --- a/lib/source_control/bazaar.rb +++ b/lib/source_control/bazaar.rb @@ -12,13 +12,13 @@ module SourceControl raise "don't know how to handle '#{options.keys.first}'" if options.length > 0 end - def checkout(revision = nil, stdout = $stdout) + def checkout(revision = nil, stdout = $stdout, new_path = path) raise 'Repository location is not specified' unless @repository - raise "#{path} is not empty, cannot branch a project into it" unless (Dir.entries(path) - ['.', '..']).empty? - FileUtils.rm_rf(path) + raise "#{new_path} is not empty, cannot branch a project into it" unless (Dir.entries(new_path) - ['.', '..']).empty? + FileUtils.rm_rf(new_path) - args = [@repository, path] + args = [@repository, new_path] args << ['-r', revision.number] if revision bzr('branch', args, :execute_in_project_directory => false) end diff --git a/lib/source_control/git.rb b/lib/source_control/git.rb index 460d483..5da1631 100644 --- a/lib/source_control/git.rb +++ b/lib/source_control/git.rb @@ -15,14 +15,14 @@ module SourceControl raise "don't know how to handle '#{options.keys.first}'" if options.length > 0 end - def checkout(revision = nil, stdout = $stdout) + def checkout(revision = nil, stdout = $stdout, new_path = path) raise 'Repository location is not specified' unless @repository - raise "#{path} is not empty, cannot clone a project into it" unless (Dir.entries(path) - ['.', '..']).empty? - FileUtils.rm_rf(path) + raise "#{new_path} is not empty, cannot clone a project into it" unless (Dir.entries(new_path) - ['.', '..']).empty? + FileUtils.rm_rf(new_path) # need to read from command output, because otherwise tests break - git('clone', [@repository, path], :execute_in_project_directory => false) + git('clone', [@repository, new_path], :execute_in_project_directory => false) if @branch git('branch', ['--track', @branch, "origin/#@branch"]) @@ -118,4 +118,4 @@ module SourceControl end -end \ No newline at end of file +end diff --git a/lib/source_control/mercurial.rb b/lib/source_control/mercurial.rb index 5647e6a..dd83a05 100644 --- a/lib/source_control/mercurial.rb +++ b/lib/source_control/mercurial.rb @@ -13,14 +13,14 @@ module SourceControl raise "don't know how to handle '#{options.keys.first}'" if options.length > 0 end - def checkout(revision = nil, stdout = $stdout) + def checkout(revision = nil, stdout = $stdout, new_path = path) raise 'Repository location is not specified' unless @repository - raise "#{path} is not empty, cannot clone a project into it" unless (Dir.entries(path) - ['.', '..']).empty? - FileUtils.rm_rf(path) + raise "#{new_path} is not empty, cannot clone a project into it" unless (Dir.entries(new_path) - ['.', '..']).empty? + FileUtils.rm_rf(new_path) # need to read from command output, because otherwise tests break - hg('clone', [@repository, path], :execute_in_project_directory => false) do |io| + hg('clone', [@repository, new_path], :execute_in_project_directory => false) do |io| begin while line = io.gets stdout.puts line -- 1.6.3.3