Skip to content

Allows a logger to be given during cloning #473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allows a logger to be given during cloning
Modifies the clone method in the Base class to allow it to receive and
use a logger during the clonning phase as well as pass it down to the
class constructor so that the created instance has access to it as well.

Signed-off-by: Sergio Bobillier <sergio.bobillier@esrlabs.com>
  • Loading branch information
sergio-bobillier committed Dec 1, 2020
commit 78b884a19d0d49a09e6bef234b1a51f1be9399df
7 changes: 4 additions & 3 deletions lib/git/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ def self.bare(git_dir, opts = {})
# :index_file
#
def self.clone(repository, name, opts = {})
# run git-clone
self.new(Git::Lib.new.clone(repository, name, opts))
# run git-clone
log = opts[:log]
new(Git::Lib.new(nil, log).clone(repository, name, opts).merge(log: log))
end

# Returns (and initialize if needed) a Git::Config instance
#
# @return [Git::Config] the current config instance.
Expand Down
14 changes: 14 additions & 0 deletions tests/units/test_base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env ruby

require 'stringio'

require File.dirname(__FILE__) + '/../test_helper'

class TestBase < Test::Unit::TestCase
Expand All @@ -8,6 +10,18 @@ def setup
set_file_paths
end

def test_clone
in_temp_dir do |_path|
# Tests that the given logger object is used during the cloning phase as
# well as passed to the Base class's initialize method.

buffer = StringIO.new
Git.clone(@wdir, 'test_add', log: Logger.new(buffer))
assert_match(/Cloning into 'test_add'/, buffer.string) # Comes from the Cloning Process
assert_match(/Starting Git/, buffer.string) # Comes from the Base's initialize method
end
end

def test_add
in_temp_dir do |path|
git = Git.clone(@wdir, 'test_add')
Expand Down