def amendment?
      return @amendment unless @amendment.nil?

      cmd = Overcommit::Utils.parent_command
      amend_pattern = 'commit(\s.*)?\s--amend(\s|$)'

      # Since the ps command can return invalid byte sequences for commands
      # containing unicode characters, we replace the offending characters,
      # since the pattern we're looking for will consist of ASCII characters
      unless cmd.valid_encoding?
        cmd = Overcommit::Utils.parent_command.encode('UTF-16be', invalid: :replace, replace: '?').
                                               encode('UTF-8')
      end

      return @amendment if
        # True if the command is a commit with the --amend flag
        @amendment = !(/\s#{amend_pattern}/ =~ cmd).nil?

      # Check for git aliases that call `commit --amend`
      `git config --get-regexp "^alias\\." "#{amend_pattern}"`.
        scan(/alias\.([-\w]+)/). # Extract the alias
        each do |match|
          return @amendment if
            # True if the command uses a git alias for `commit --amend`
            @amendment = !(/git(\.exe)?\s+#{match[0]}/ =~ cmd).nil?
        end

      @amendment
    end
def amendment?
      return @amendment unless @amendment.nil?

      cmd = Overcommit::Utils.parent_command
      amend_pattern = 'commit(\s.*)?\s--amend(\s|$)'

      # Since the ps command can return invalid byte sequences for commands
      # containing unicode characters, we replace the offending characters,
      # since the pattern we're looking for will consist of ASCII characters
      unless cmd.valid_encoding?
        cmd = Overcommit::Utils.parent_command.encode('UTF-16be', invalid: :replace, replace: '?').
                                               encode('UTF-8')
      end

      return @amendment if
        # True if the command is a commit with the --amend flag
        @amendment = !(/\s#{amend_pattern}/ =~ cmd).nil?

      # Check for git aliases that call `commit --amend`
      `git config --get-regexp "^alias\\." "#{amend_pattern}"`.
        scan(/alias\.([-\w]+)/). # Extract the alias
        each do |match|
          return @amendment if
            # True if the command uses a git alias for `commit --amend`
            @amendment = !(/git(\.exe)?\s+#{match[0]}/ =~ cmd).nil?
        end

      @amendment
    end
rubocop:disable ClassLength
 Returns whether this hook run was triggered by `git commit --amend`