Skip to content

Commit 78b884a

Browse files
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>
1 parent f9abb18 commit 78b884a

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/git/base.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ def self.bare(git_dir, opts = {})
2525
# :index_file
2626
#
2727
def self.clone(repository, name, opts = {})
28-
# run git-clone
29-
self.new(Git::Lib.new.clone(repository, name, opts))
28+
# run git-clone
29+
log = opts[:log]
30+
new(Git::Lib.new(nil, log).clone(repository, name, opts).merge(log: log))
3031
end
31-
32+
3233
# Returns (and initialize if needed) a Git::Config instance
3334
#
3435
# @return [Git::Config] the current config instance.

tests/units/test_base.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env ruby
22

3+
require 'stringio'
4+
35
require File.dirname(__FILE__) + '/../test_helper'
46

57
class TestBase < Test::Unit::TestCase
@@ -8,6 +10,18 @@ def setup
810
set_file_paths
911
end
1012

13+
def test_clone
14+
in_temp_dir do |_path|
15+
# Tests that the given logger object is used during the cloning phase as
16+
# well as passed to the Base class's initialize method.
17+
18+
buffer = StringIO.new
19+
Git.clone(@wdir, 'test_add', log: Logger.new(buffer))
20+
assert_match(/Cloning into 'test_add'/, buffer.string) # Comes from the Cloning Process
21+
assert_match(/Starting Git/, buffer.string) # Comes from the Base's initialize method
22+
end
23+
end
24+
1125
def test_add
1226
in_temp_dir do |path|
1327
git = Git.clone(@wdir, 'test_add')

0 commit comments

Comments
 (0)