Skip to content

Commit

Permalink
Skip clone warming up when a file is missing (#67)
Browse files Browse the repository at this point in the history
* Skip clone warming up when a file is missing

* Align spacing in help
  • Loading branch information
polac24 authored Mar 18, 2024
1 parent 55adc9f commit e9e70b0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
git-fastclone (1.5.0)
git-fastclone (1.5.1)
colorize

GEM
Expand Down
19 changes: 13 additions & 6 deletions lib/git-fastclone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,15 @@ def parse_options
options[:config] = config
end

opts.on('--lock-timeout N', 'Timeout in seconds to acquire a lock on any reference repo.
Default is 0 which waits indefinitely.') do |timeout_secs|
opts.on('--lock-timeout N', 'Timeout in seconds to acquire a lock on any reference repo.',
'Default is 0 which waits indefinitely.') do |timeout_secs|
self.flock_timeout_secs = timeout_secs.to_i
end

opts.on('--pre-clone-hook command',
'An optional command that should be invoked before cloning mirror repo') do |command|
options[:pre_clone_hook] = command
opts.on('--pre-clone-hook script_file',
'An optional file that should be invoked before cloning mirror repo',
'No-op when a file is missing') do |script_file|
options[:pre_clone_hook] = script_file
end
end.parse!
end
Expand Down Expand Up @@ -452,7 +453,13 @@ def usage
private def trigger_pre_clone_hook_if_needed(url, mirror, attempt_number)
return if Dir.exist?(mirror) || !options.include?(:pre_clone_hook)

popen2e_wrapper(options[:pre_clone_hook], url.to_s, mirror.to_s, attempt_number.to_s, quiet: !verbose)
hook_command = options[:pre_clone_hook]
unless File.exist?(File.expand_path(hook_command))
puts 'pre_clone_hook script is missing' if verbose
return
end

popen2e_wrapper(hook_command, url.to_s, mirror.to_s, attempt_number.to_s, quiet: !verbose)
end
end
end
2 changes: 1 addition & 1 deletion lib/git-fastclone/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# Version string for git-fastclone
module GitFastCloneVersion
VERSION = '1.5.0'
VERSION = '1.5.1'
end
20 changes: 19 additions & 1 deletion spec/git_fastclone_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ def create_lockfile_double
end
end

context 'with pre-clone-hook errors' do
context 'with pre-clone-hook' do
let(:pre_clone_hook) { '/some/command' }
before(:each) do
subject.options[:pre_clone_hook] = pre_clone_hook
subject.reference_dir = placeholder_arg
allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with(pre_clone_hook).and_return(true)
allow(subject).to receive(:with_git_mirror).and_call_original
allow(subject).to receive(:with_reference_repo_lock) do |_url, &block|
block.call
Expand Down Expand Up @@ -192,6 +194,22 @@ def create_lockfile_double

subject.clone(placeholder_arg, nil, '.', 'config')
end

context 'non-existing script' do
before(:each) do
allow(File).to receive(:exist?).with(pre_clone_hook).and_return(false)
end

it 'does not invoke hook command' do
allow(subject).to receive(:fail_on_error)
expect(subject).not_to receive(:popen2e_wrapper).with(
pre_clone_hook, 'PH', 'PH/PH', '0',
{ quiet: true }
)

subject.clone(placeholder_arg, nil, '.', 'config')
end
end
end
end

Expand Down

0 comments on commit e9e70b0

Please sign in to comment.