Method: Datadog::CI::Git::LocalRepository.git_unshallow

Defined in:
lib/datadog/ci/git/local_repository.rb

.git_unshallowObject



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/datadog/ci/git/local_repository.rb', line 265

def self.git_unshallow
  Telemetry.git_command(Ext::Telemetry::Command::UNSHALLOW)
  res = nil

  unshallow_command =
    "git fetch " \
    "--shallow-since=\"1 month ago\" " \
    "--update-shallow " \
    "--filter=\"blob:none\" " \
    "--recurse-submodules=no " \
    "$(git config --default origin --get clone.defaultRemoteName)"

  unshallow_remotes = [
    "$(git rev-parse HEAD)",
    "$(git rev-parse --abbrev-ref --symbolic-full-name @{upstream})",
    nil
  ]

  duration_ms = Core::Utils::Time.measure(:float_millisecond) do
    unshallow_remotes.each do |remote|
      unshallowing_errored = false

      res =
        begin
          exec_git_command(
            "#{unshallow_command} #{remote}"
          )
        rescue => e
          log_failure(e, "git unshallow")
          telemetry_track_error(e, Ext::Telemetry::Command::UNSHALLOW)
          unshallowing_errored = true
          nil
        end

      break unless unshallowing_errored
    end
  end

  Telemetry.git_command_ms(Ext::Telemetry::Command::UNSHALLOW, duration_ms)
  res
end