git-fastclone 1.4.1 → 1.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e915bc1276ac42ac35559122dc1c12f4a04778032ec4510fe96a64b37fc4a7a
4
- data.tar.gz: 9fcb6e4a441106da6b09f2d4b39cf0e740942ae99de051712fba27656d962f04
3
+ metadata.gz: da2eb17be407c42dbabdb002d8cee1fb56820f6543df47758b0376e84ed2344e
4
+ data.tar.gz: 0c1ca35bca06f608f8087670eba49cb5cc7d6c1af7c308e38159477455bd33c3
5
5
  SHA512:
6
- metadata.gz: fc52b41c18799ec2154000bc7762c8301ed50f28d2eb252e4adcdc82ff36cdc6e3fa772d85db4d52ea95782ea16e02ea0460f1488b5ce95a745ee8a451511a3d
7
- data.tar.gz: f86877adef196e5416e69aac06c7129bfaf22a21a566a5afe05e4780da60cdc3f0e2379e81d1bc0b4e8bd129d18a893f925dbd7096a4057ef428f085a964b2f2
6
+ metadata.gz: 4a3d27522c916ac8883ad8abceb5d19529bb406409b3f7904652a54640b2edc91184420baad3118d8379b7c26ce2331018367c994375843c9130ae9511f1108f
7
+ data.tar.gz: 413c42026762c4bf1a80d693d2920c0a519969a7d5c4f215fb810b88f6dabb5e449a15d331214c0751e0daa92c4cbc706915e7ca4d9691ec2aaefb292b8cbef6
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Version string for git-fastclone
4
4
  module GitFastCloneVersion
5
- VERSION = '1.4.1'
5
+ VERSION = '1.4.2'
6
6
  end
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,13 +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
228
  Dir.chdir(File.join(abs_clone_path, src_dir)) do
221
- fail_on_error('git', 'checkout', '--quiet', rev.to_s, quiet: !verbose)
229
+ fail_on_error('git', 'checkout', '--quiet', rev.to_s, quiet: !verbose,
230
+ print_on_failure: print_git_errors)
222
231
  end
223
232
  end
224
233
 
@@ -243,7 +252,8 @@ module GitFastClone
243
252
  submodule_url_list = []
244
253
  output = ''
245
254
  Dir.chdir(File.join(abs_clone_path, pwd).to_s) do
246
- output = fail_on_error('git', 'submodule', 'init', quiet: !verbose)
255
+ output = fail_on_error('git', 'submodule', 'init', quiet: !verbose,
256
+ print_on_failure: print_git_errors)
247
257
  end
248
258
 
249
259
  output.split("\n").each do |line|
@@ -263,7 +273,7 @@ module GitFastClone
263
273
  Dir.chdir(File.join(abs_clone_path, pwd).to_s) do
264
274
  cmd = ['git', 'submodule', verbose ? nil : '--quiet', 'update', '--reference', mirror.to_s,
265
275
  submodule_path.to_s].compact
266
- fail_on_error(*cmd, quiet: !verbose)
276
+ fail_on_error(*cmd, quiet: !verbose, print_on_failure: print_git_errors)
267
277
  end
268
278
  end
269
279
 
@@ -337,12 +347,12 @@ module GitFastClone
337
347
  def store_updated_repo(url, mirror, repo_name, fail_hard)
338
348
  unless Dir.exist?(mirror)
339
349
  fail_on_error('git', 'clone', verbose ? '--verbose' : '--quiet', '--mirror', url.to_s, mirror.to_s,
340
- quiet: !verbose)
350
+ quiet: !verbose, print_on_failure: print_git_errors)
341
351
  end
342
352
 
343
353
  Dir.chdir(mirror) do
344
354
  cmd = ['git', 'remote', verbose ? '--verbose' : nil, 'update', '--prune'].compact
345
- fail_on_error(*cmd, quiet: !verbose)
355
+ fail_on_error(*cmd, quiet: !verbose, print_on_failure: print_git_errors)
346
356
  end
347
357
  reference_updated[repo_name] = true
348
358
  rescue RunnerExecutionRuntimeError => e
@@ -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
- exit_on_status(output, [shell_safe_cmd], [status], quiet: quiet)
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
@@ -99,11 +99,11 @@ describe GitFastClone::Runner do
99
99
  it 'should clone correctly' do
100
100
  expect(subject).to receive(:fail_on_error).with(
101
101
  'git', 'checkout', '--quiet', 'PH',
102
- { quiet: true }
102
+ { quiet: true, print_on_failure: false }
103
103
  ) { runner_execution_double }
104
104
  expect(subject).to receive(:fail_on_error).with(
105
105
  'git', 'clone', '--quiet', '--reference', '/cache', 'PH', '/pwd/.',
106
- { quiet: true }
106
+ { quiet: true, print_on_failure: false }
107
107
  ) { runner_execution_double }
108
108
 
109
109
  subject.clone(placeholder_arg, placeholder_arg, '.', nil)
@@ -113,11 +113,11 @@ describe GitFastClone::Runner do
113
113
  subject.verbose = true
114
114
  expect(subject).to receive(:fail_on_error).with(
115
115
  'git', 'checkout', '--quiet', 'PH',
116
- { quiet: false }
116
+ { quiet: false, print_on_failure: false }
117
117
  ) { runner_execution_double }
118
118
  expect(subject).to receive(:fail_on_error).with(
119
119
  'git', 'clone', '--verbose', '--reference', '/cache', 'PH', '/pwd/.',
120
- { quiet: false }
120
+ { quiet: false, print_on_failure: false }
121
121
  ) { runner_execution_double }
122
122
 
123
123
  subject.clone(placeholder_arg, placeholder_arg, '.', nil)
@@ -126,11 +126,26 @@ describe GitFastClone::Runner do
126
126
  it 'should clone correctly with custom configs' do
127
127
  expect(subject).to receive(:fail_on_error).with(
128
128
  'git', 'clone', '--quiet', '--reference', '/cache', 'PH', '/pwd/.', '--config', 'config',
129
- { quiet: true }
129
+ { quiet: true, print_on_failure: false }
130
130
  ) { runner_execution_double }
131
131
 
132
132
  subject.clone(placeholder_arg, nil, '.', 'config')
133
133
  end
134
+
135
+ context 'with printing errors' do
136
+ before(:each) do
137
+ subject.print_git_errors = true
138
+ end
139
+
140
+ it 'prints failures' do
141
+ expect(subject).to receive(:fail_on_error).with(
142
+ 'git', 'clone', '--quiet', '--reference', '/cache', 'PH', '/pwd/.', '--config', 'config',
143
+ { quiet: true, print_on_failure: true }
144
+ ) { runner_execution_double }
145
+
146
+ subject.clone(placeholder_arg, nil, '.', 'config')
147
+ end
148
+ end
134
149
  end
135
150
 
136
151
  describe '.clear_clone_dest_if_needed' do
@@ -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.1
4
+ version: 1.4.2
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-05-19 00:00:00.000000000 Z
12
+ date: 2023-06-27 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:
@@ -65,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
66
  - !ruby/object:Gem::Version
66
67
  version: '0'
67
68
  requirements: []
68
- rubygems_version: 3.1.6
69
+ rubygems_version: 3.4.13
69
70
  signing_key:
70
71
  specification_version: 4
71
72
  summary: git-clone --recursive on steroids!