Method: EmergeCLI::Git.previous_sha

Defined in:
lib/utils/git.rb

.previous_shaObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/utils/git.rb', line 64

def self.previous_sha
  Logger.debug 'Getting previous SHA'
  command = 'git rev-list --count HEAD'
  Logger.debug command
  count_stdout, _, count_status = Open3.capture3(command)

  if !count_status.success? || count_stdout.strip.to_i <= 1
    Logger.error 'Detected shallow clone while trying to get the previous commit. ' \
                 'Please clone with full history using: git clone --no-single-branch ' \
                 'or configure CI with fetch-depth: 0'
    return nil
  end

  command = 'git rev-parse HEAD^'
  Logger.debug command
  stdout, stderr, status = Open3.capture3(command)
  Logger.error "Failed to get previous SHA: #{stdout}, #{stderr}" if !status.success?
  stdout.strip if status.success?
end