git-fastclone 1.4.1 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/git-fastclone/version.rb +1 -1
- data/lib/git-fastclone.rb +24 -19
- data/lib/runner_execution.rb +8 -5
- data/spec/git_fastclone_runner_spec.rb +22 -9
- data/spec/runner_execution_spec.rb +58 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b755aef58d17ded702b989b16fb92cf93908413403bb99f92b542319c59fdbc
|
4
|
+
data.tar.gz: c7ad9ab44516bea864027aa562af274bd49999aea62eccbfc3df9421cc6674d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f6cff1907474ac42d8a4936dba9e5e684440b72f9995ce80bdb0bc79bc169d79969386b32eb3c8e8cc64358fc1872b0cbb07011d2bebfd753b04423fc1198be
|
7
|
+
data.tar.gz: 889d56227ae2aff1aba3d9dfc33fdd7ab554b9f6ae77f21c036c66af5c2eb47756d49e62a2244ca922855442856caaeb772baace5bc1c9f093d1eae0a3043b02
|
data/lib/git-fastclone.rb
CHANGED
@@ -74,7 +74,7 @@ module GitFastClone
|
|
74
74
|
DEFAULT_GIT_ALLOW_PROTOCOL = 'file:git:http:https:ssh'
|
75
75
|
|
76
76
|
attr_accessor :reference_dir, :prefetch_submodules, :reference_updated, :reference_mutex,
|
77
|
-
:options, :abs_clone_path, :using_local_repo, :verbose, :color,
|
77
|
+
:options, :abs_clone_path, :using_local_repo, :verbose, :print_git_errors, :color,
|
78
78
|
:flock_timeout_secs
|
79
79
|
|
80
80
|
def initialize
|
@@ -100,6 +100,8 @@ module GitFastClone
|
|
100
100
|
|
101
101
|
self.verbose = false
|
102
102
|
|
103
|
+
self.print_git_errors = false
|
104
|
+
|
103
105
|
self.color = false
|
104
106
|
|
105
107
|
self.flock_timeout_secs = 0
|
@@ -133,9 +135,15 @@ module GitFastClone
|
|
133
135
|
end
|
134
136
|
|
135
137
|
opts.on('-v', '--verbose', 'Verbose mode') do
|
138
|
+
puts '--print_git_errors is redundant when using --verbose' if print_git_errors
|
136
139
|
self.verbose = true
|
137
140
|
end
|
138
141
|
|
142
|
+
opts.on('--print_git_errors', 'Print git output if a command fails') do
|
143
|
+
puts '--print_git_errors is redundant when using --verbose' if verbose
|
144
|
+
self.print_git_errors = true
|
145
|
+
end
|
146
|
+
|
139
147
|
opts.on('-c', '--color', 'Display colored output') do
|
140
148
|
self.color = true
|
141
149
|
end
|
@@ -212,14 +220,14 @@ module GitFastClone
|
|
212
220
|
clone_commands = ['git', 'clone', verbose ? '--verbose' : '--quiet']
|
213
221
|
clone_commands << '--reference' << mirror.to_s << url.to_s << clone_dest
|
214
222
|
clone_commands << '--config' << config.to_s unless config.nil?
|
215
|
-
fail_on_error(*clone_commands, quiet: !verbose)
|
223
|
+
fail_on_error(*clone_commands, quiet: !verbose, print_on_failure: print_git_errors)
|
216
224
|
end
|
217
225
|
|
218
226
|
# Only checkout if we're changing branches to a non-default branch
|
219
227
|
if rev
|
220
|
-
|
221
|
-
|
222
|
-
|
228
|
+
fail_on_error('git', 'checkout', '--quiet', rev.to_s, quiet: !verbose,
|
229
|
+
print_on_failure: print_git_errors,
|
230
|
+
chdir: File.join(abs_clone_path, src_dir))
|
223
231
|
end
|
224
232
|
|
225
233
|
update_submodules(src_dir, url)
|
@@ -241,10 +249,9 @@ module GitFastClone
|
|
241
249
|
|
242
250
|
threads = []
|
243
251
|
submodule_url_list = []
|
244
|
-
output = ''
|
245
|
-
|
246
|
-
|
247
|
-
end
|
252
|
+
output = fail_on_error('git', 'submodule', 'init', quiet: !verbose,
|
253
|
+
print_on_failure: print_git_errors,
|
254
|
+
chdir: File.join(abs_clone_path, pwd))
|
248
255
|
|
249
256
|
output.split("\n").each do |line|
|
250
257
|
submodule_path, submodule_url = parse_update_info(line)
|
@@ -260,11 +267,10 @@ module GitFastClone
|
|
260
267
|
def thread_update_submodule(submodule_url, submodule_path, threads, pwd)
|
261
268
|
threads << Thread.new do
|
262
269
|
with_git_mirror(submodule_url) do |mirror, _|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
end
|
270
|
+
cmd = ['git', 'submodule',
|
271
|
+
verbose ? nil : '--quiet', 'update', '--reference', mirror.to_s, submodule_path.to_s].compact
|
272
|
+
fail_on_error(*cmd, quiet: !verbose, print_on_failure: print_git_errors,
|
273
|
+
chdir: File.join(abs_clone_path, pwd))
|
268
274
|
end
|
269
275
|
|
270
276
|
update_submodules(File.join(pwd, submodule_path), submodule_url)
|
@@ -337,13 +343,12 @@ module GitFastClone
|
|
337
343
|
def store_updated_repo(url, mirror, repo_name, fail_hard)
|
338
344
|
unless Dir.exist?(mirror)
|
339
345
|
fail_on_error('git', 'clone', verbose ? '--verbose' : '--quiet', '--mirror', url.to_s, mirror.to_s,
|
340
|
-
quiet: !verbose)
|
346
|
+
quiet: !verbose, print_on_failure: print_git_errors)
|
341
347
|
end
|
342
348
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
end
|
349
|
+
cmd = ['git', 'remote', verbose ? '--verbose' : nil, 'update', '--prune'].compact
|
350
|
+
fail_on_error(*cmd, quiet: !verbose, print_on_failure: print_git_errors, chdir: mirror)
|
351
|
+
|
347
352
|
reference_updated[repo_name] = true
|
348
353
|
rescue RunnerExecutionRuntimeError => e
|
349
354
|
# To avoid corruption of the cache, if we failed to update or check out we remove
|
data/lib/runner_execution.rb
CHANGED
@@ -22,7 +22,7 @@ module RunnerExecution
|
|
22
22
|
|
23
23
|
# Runs a command that fails on error.
|
24
24
|
# Uses popen2e wrapper. Handles bad statuses with potential for retries.
|
25
|
-
def fail_on_error(*cmd, stdin_data: nil, binmode: false, quiet: false, **opts)
|
25
|
+
def fail_on_error(*cmd, stdin_data: nil, binmode: false, quiet: false, print_on_failure: false, **opts)
|
26
26
|
print_command('Running Shell Safe Command:', [cmd]) unless quiet
|
27
27
|
shell_safe_cmd = shell_safe(cmd)
|
28
28
|
retry_times = opts[:retry] || 0
|
@@ -39,7 +39,9 @@ module RunnerExecution
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# Get out with the status, good or bad.
|
42
|
-
|
42
|
+
# When quiet, we don't need to print the output, as it is already streamed from popen2e_wrapper
|
43
|
+
needs_print_on_failure = quiet && print_on_failure
|
44
|
+
exit_on_status(output, [shell_safe_cmd], [status], quiet: quiet, print_on_failure: needs_print_on_failure)
|
43
45
|
end
|
44
46
|
module_function :fail_on_error
|
45
47
|
|
@@ -155,20 +157,21 @@ module RunnerExecution
|
|
155
157
|
# return code of the first one.
|
156
158
|
#
|
157
159
|
# Otherwise returns first argument (output)
|
158
|
-
def exit_on_status(output, cmd_list, status_list, quiet: false)
|
160
|
+
def exit_on_status(output, cmd_list, status_list, quiet: false, print_on_failure: false)
|
159
161
|
status_list.each_index do |index|
|
160
162
|
status = status_list[index]
|
161
163
|
cmd = cmd_list[index]
|
162
|
-
check_status(cmd, status, output: output, quiet: quiet)
|
164
|
+
check_status(cmd, status, output: output, quiet: quiet, print_on_failure: print_on_failure)
|
163
165
|
end
|
164
166
|
|
165
167
|
output
|
166
168
|
end
|
167
169
|
module_function :exit_on_status
|
168
170
|
|
169
|
-
def check_status(cmd, status, output: nil, quiet: false)
|
171
|
+
def check_status(cmd, status, output: nil, quiet: false, print_on_failure: false)
|
170
172
|
return if status.exited? && status.exitstatus == 0
|
171
173
|
|
174
|
+
logger.info(output) if print_on_failure
|
172
175
|
# If we exited nonzero or abnormally, print debugging info and explode.
|
173
176
|
if status.exited?
|
174
177
|
logger.debug("Process Exited normally. Exit status:#{status.exitstatus}") unless quiet
|
@@ -91,7 +91,6 @@ describe GitFastClone::Runner do
|
|
91
91
|
before(:each) do
|
92
92
|
allow(runner_execution_double).to receive(:fail_on_error) {}
|
93
93
|
allow(Dir).to receive(:pwd) { '/pwd' }
|
94
|
-
allow(Dir).to receive(:chdir).and_yield
|
95
94
|
allow(subject).to receive(:with_git_mirror).and_yield('/cache', 0)
|
96
95
|
expect(subject).to receive(:clear_clone_dest_if_needed).once {}
|
97
96
|
end
|
@@ -99,11 +98,11 @@ describe GitFastClone::Runner do
|
|
99
98
|
it 'should clone correctly' do
|
100
99
|
expect(subject).to receive(:fail_on_error).with(
|
101
100
|
'git', 'checkout', '--quiet', 'PH',
|
102
|
-
{ quiet: true }
|
101
|
+
{ chdir: '/pwd/.', print_on_failure: false, quiet: true }
|
103
102
|
) { runner_execution_double }
|
104
103
|
expect(subject).to receive(:fail_on_error).with(
|
105
104
|
'git', 'clone', '--quiet', '--reference', '/cache', 'PH', '/pwd/.',
|
106
|
-
{ quiet: true }
|
105
|
+
{ quiet: true, print_on_failure: false }
|
107
106
|
) { runner_execution_double }
|
108
107
|
|
109
108
|
subject.clone(placeholder_arg, placeholder_arg, '.', nil)
|
@@ -113,11 +112,11 @@ describe GitFastClone::Runner do
|
|
113
112
|
subject.verbose = true
|
114
113
|
expect(subject).to receive(:fail_on_error).with(
|
115
114
|
'git', 'checkout', '--quiet', 'PH',
|
116
|
-
{ quiet: false }
|
115
|
+
{ chdir: '/pwd/.', print_on_failure: false, quiet: false }
|
117
116
|
) { runner_execution_double }
|
118
117
|
expect(subject).to receive(:fail_on_error).with(
|
119
118
|
'git', 'clone', '--verbose', '--reference', '/cache', 'PH', '/pwd/.',
|
120
|
-
{ quiet: false }
|
119
|
+
{ quiet: false, print_on_failure: false }
|
121
120
|
) { runner_execution_double }
|
122
121
|
|
123
122
|
subject.clone(placeholder_arg, placeholder_arg, '.', nil)
|
@@ -126,11 +125,26 @@ describe GitFastClone::Runner do
|
|
126
125
|
it 'should clone correctly with custom configs' do
|
127
126
|
expect(subject).to receive(:fail_on_error).with(
|
128
127
|
'git', 'clone', '--quiet', '--reference', '/cache', 'PH', '/pwd/.', '--config', 'config',
|
129
|
-
{ quiet: true }
|
128
|
+
{ quiet: true, print_on_failure: false }
|
130
129
|
) { runner_execution_double }
|
131
130
|
|
132
131
|
subject.clone(placeholder_arg, nil, '.', 'config')
|
133
132
|
end
|
133
|
+
|
134
|
+
context 'with printing errors' do
|
135
|
+
before(:each) do
|
136
|
+
subject.print_git_errors = true
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'prints failures' do
|
140
|
+
expect(subject).to receive(:fail_on_error).with(
|
141
|
+
'git', 'clone', '--quiet', '--reference', '/cache', 'PH', '/pwd/.', '--config', 'config',
|
142
|
+
{ quiet: true, print_on_failure: true }
|
143
|
+
) { runner_execution_double }
|
144
|
+
|
145
|
+
subject.clone(placeholder_arg, nil, '.', 'config')
|
146
|
+
end
|
147
|
+
end
|
134
148
|
end
|
135
149
|
|
136
150
|
describe '.clear_clone_dest_if_needed' do
|
@@ -323,7 +337,6 @@ describe GitFastClone::Runner do
|
|
323
337
|
|
324
338
|
it 'should correctly update the hash' do
|
325
339
|
allow(subject).to receive(:fail_on_error)
|
326
|
-
allow(Dir).to receive(:chdir) {}
|
327
340
|
|
328
341
|
subject.reference_updated = placeholder_hash
|
329
342
|
subject.store_updated_repo(placeholder_arg, placeholder_arg, placeholder_arg, false)
|
@@ -374,7 +387,6 @@ describe GitFastClone::Runner do
|
|
374
387
|
expected_command = expected_commands.shift
|
375
388
|
expect(command).to eq(expected_command)
|
376
389
|
}
|
377
|
-
allow(Dir).to receive(:chdir).and_yield
|
378
390
|
|
379
391
|
allow(subject).to receive(:print_formatted_error) {}
|
380
392
|
allow(subject).to receive(:reference_repo_dir).and_return(test_reference_repo_dir)
|
@@ -389,7 +401,8 @@ describe GitFastClone::Runner do
|
|
389
401
|
[
|
390
402
|
['git', 'clone', verbose ? '--verbose' : '--quiet', '--mirror', test_url_valid,
|
391
403
|
test_reference_repo_dir],
|
392
|
-
['git', 'remote', verbose ? '--verbose' : nil, 'update',
|
404
|
+
['git', 'remote', verbose ? '--verbose' : nil, 'update',
|
405
|
+
'--prune'].compact
|
393
406
|
]
|
394
407
|
end
|
395
408
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2023 Square Inc.
|
4
|
+
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
require 'git-fastclone'
|
19
|
+
|
20
|
+
# Integration tests use real demo_tool.sh to inspect the E2E behavior
|
21
|
+
describe RunnerExecution do
|
22
|
+
subject { described_class }
|
23
|
+
let(:external_tool) { "#{__dir__}/../script/spec_demo_tool.sh" }
|
24
|
+
let(:logger) { double('logger') }
|
25
|
+
|
26
|
+
before do
|
27
|
+
allow($stdout).to receive(:puts)
|
28
|
+
allow(logger).to receive(:info)
|
29
|
+
allow(logger).to receive(:debug)
|
30
|
+
allow(logger).to receive(:warn)
|
31
|
+
allow(RunnerExecution).to receive(:logger).and_return(logger)
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '.fail_on_error' do
|
35
|
+
it 'should log failure info on command error' do
|
36
|
+
expect(logger).to receive(:info).with("My error output\n")
|
37
|
+
|
38
|
+
expect do
|
39
|
+
described_class.fail_on_error(external_tool, '1', 'My error output', quiet: true,
|
40
|
+
print_on_failure: true)
|
41
|
+
end.to raise_error(RunnerExecution::RunnerExecutionRuntimeError)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should not log failure output on command success' do
|
45
|
+
expect($stdout).not_to receive(:info)
|
46
|
+
|
47
|
+
described_class.fail_on_error(external_tool, '0', 'My success output', quiet: true,
|
48
|
+
print_on_failure: true)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should not log failure output when not in the quiet mode' do
|
52
|
+
expect($stdout).not_to receive(:info)
|
53
|
+
|
54
|
+
described_class.fail_on_error(external_tool, '0', 'My success output', quiet: false,
|
55
|
+
print_on_failure: true)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-fastclone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Tauraso
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/runner_execution.rb
|
45
45
|
- spec/git_fastclone_runner_spec.rb
|
46
46
|
- spec/git_fastclone_url_helper_spec.rb
|
47
|
+
- spec/runner_execution_spec.rb
|
47
48
|
- spec/spec_helper.rb
|
48
49
|
homepage: http://square.github.io/git-fastclone/
|
49
50
|
licenses:
|