Skip to content

Commit e9e70b0

Browse files
authored
Skip clone warming up when a file is missing (square#67)
* Skip clone warming up when a file is missing * Align spacing in help
1 parent 55adc9f commit e9e70b0

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
git-fastclone (1.5.0)
4+
git-fastclone (1.5.1)
55
colorize
66

77
GEM

lib/git-fastclone.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,15 @@ def parse_options
162162
options[:config] = config
163163
end
164164

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

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

455-
popen2e_wrapper(options[:pre_clone_hook], url.to_s, mirror.to_s, attempt_number.to_s, quiet: !verbose)
456+
hook_command = options[:pre_clone_hook]
457+
unless File.exist?(File.expand_path(hook_command))
458+
puts 'pre_clone_hook script is missing' if verbose
459+
return
460+
end
461+
462+
popen2e_wrapper(hook_command, url.to_s, mirror.to_s, attempt_number.to_s, quiet: !verbose)
456463
end
457464
end
458465
end

lib/git-fastclone/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
# Version string for git-fastclone
44
module GitFastCloneVersion
5-
VERSION = '1.5.0'
5+
VERSION = '1.5.1'
66
end

spec/git_fastclone_runner_spec.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,13 @@ def create_lockfile_double
146146
end
147147
end
148148

149-
context 'with pre-clone-hook errors' do
149+
context 'with pre-clone-hook' do
150150
let(:pre_clone_hook) { '/some/command' }
151151
before(:each) do
152152
subject.options[:pre_clone_hook] = pre_clone_hook
153153
subject.reference_dir = placeholder_arg
154+
allow(File).to receive(:exist?).and_call_original
155+
allow(File).to receive(:exist?).with(pre_clone_hook).and_return(true)
154156
allow(subject).to receive(:with_git_mirror).and_call_original
155157
allow(subject).to receive(:with_reference_repo_lock) do |_url, &block|
156158
block.call
@@ -192,6 +194,22 @@ def create_lockfile_double
192194

193195
subject.clone(placeholder_arg, nil, '.', 'config')
194196
end
197+
198+
context 'non-existing script' do
199+
before(:each) do
200+
allow(File).to receive(:exist?).with(pre_clone_hook).and_return(false)
201+
end
202+
203+
it 'does not invoke hook command' do
204+
allow(subject).to receive(:fail_on_error)
205+
expect(subject).not_to receive(:popen2e_wrapper).with(
206+
pre_clone_hook, 'PH', 'PH/PH', '0',
207+
{ quiet: true }
208+
)
209+
210+
subject.clone(placeholder_arg, nil, '.', 'config')
211+
end
212+
end
195213
end
196214
end
197215

0 commit comments

Comments
 (0)