diff --git a/README.md b/README.md index ec97d4cd..7d3d61ef 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,9 @@ g.dir #=> /tmp/clone/ruby-git-clean g.config('user.name', 'Scott Chacon') g.config('user.email', 'email@email.com') +# Clone can take a filter to tell the serve to send a partial clone +g = Git.clone(git_url, name, :path => path, :filter => 'tree:0') + # Clone can take an optional logger logger = Logger.new g = Git.clone(git_url, NAME, :log => logger) diff --git a/lib/git.rb b/lib/git.rb index 1f81bbca..63e1f3b1 100644 --- a/lib/git.rb +++ b/lib/git.rb @@ -139,6 +139,9 @@ def self.bare(git_dir, options = {}) # @option options [Integer] :depth Create a shallow clone with a history # truncated to the specified number of commits. # + # @option options [String] :filter Request that the server send a partial + # clone according to the given filter + # # @option options [Logger] :log A logger to use for Git operations. Git # commands are logged at the `:info` level. Additional logging is done # at the `:debug` level. diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 78e4fafb..27934aa3 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -84,6 +84,7 @@ def init(opts={}) # :bare:: no working directory # :branch:: name of branch to track (rather than 'master') # :depth:: the number of commits back to pull + # :filter:: specify partial clone # :origin:: name of remote (same as remote) # :path:: directory where the repo will be cloned # :remote:: name of remote (rather than 'origin') @@ -101,6 +102,7 @@ def clone(repository_url, directory, opts = {}) arr_opts << '--bare' if opts[:bare] arr_opts << '--branch' << opts[:branch] if opts[:branch] arr_opts << '--depth' << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0 + arr_opts << '--filter' << opts[:filter] if opts[:filter] Array(opts[:config]).each { |c| arr_opts << '--config' << c } arr_opts << '--origin' << opts[:remote] || opts[:origin] if opts[:remote] || opts[:origin] arr_opts << '--recursive' if opts[:recursive] diff --git a/tests/units/test_git_clone.rb b/tests/units/test_git_clone.rb index 0ef25bf9..9f208b61 100644 --- a/tests/units/test_git_clone.rb +++ b/tests/units/test_git_clone.rb @@ -83,4 +83,29 @@ def test_git_clone_with_no_name assert_equal(expected_command_line, actual_command_line) end + test 'clone with a filter' do + repository_url = 'https://github.com/ruby-git/ruby-git.git' + destination = 'ruby-git' + + actual_command_line = nil + + in_temp_dir do |path| + git = Git.init('.') + + # Mock the Git::Lib#command method to capture the actual command line args + git.lib.define_singleton_method(:command) do |cmd, *opts, &block| + actual_command_line = [cmd, *opts.flatten] + end + + git.lib.clone(repository_url, destination, filter: 'tree:0') + end + + expected_command_line = [ + 'clone', + '--filter', 'tree:0', + '--', repository_url, destination + ] + + assert_equal(expected_command_line, actual_command_line) + end end pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy