Skip to content

Commit 645e227

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 4bef5ab commit 645e227

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ def setup
88
set_file_paths
99
end
1010

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

0 commit comments

Comments
 (0)