Sha256: ac3042413605a431fa7a92eb82ab58f3ab993fa8a8b2e8a7266e26a09e6df792

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true
#
# Copyright (c) 2021-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# ronin-core is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ronin-core is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ronin-core.  If not, see <https://www.gnu.org/licenses/>.
#

module Ronin
  module Core
    #
    # @api semipublic
    #
    module Git
      #
      # Queries the git `user.name` variable from `~/.gitconfig`.
      #
      # @return [String, nil]
      #   The value of `user.name` or `nil` if it was not set.
      #
      def self.user_name
        config_value('user.name')
      end

      #
      # Queries the git `user.email` variable from `~/.gitconfig`.
      #
      # @return [String, nil]
      #   The value of `user.email` or `nil` if it was not set.
      #
      def self.user_email
        config_value('user.email')
      end

      #
      # Queries the git `github.user` variable from `~/.gitconfig`.
      #
      # @return [String, nil]
      #   The value of `github.user` or `nil` if it was not set.
      #
      def self.github_user
        config_value('github.user')
      end

      #
      # Queries a git configuration value.
      #
      # @param [String] name
      #   The configuration name.
      #
      # @return [string, nil]
      #   The configuration value or `nil` if nothing was returned.
      #
      def self.config_value(name)
        output = `git config #{name}`.chomp

        if output.empty? then nil
        else                  output
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ronin-core-0.2.0 lib/ronin/core/git.rb
ronin-core-0.2.0.rc1 lib/ronin/core/git.rb