Sha256: 0beb08e217ef95b876068a43258cd6159afc4a74237cae18060af95bf09467c6

Contents?: true

Size: 1.83 KB

Versions: 10

Compression:

Stored size: 1.83 KB

Contents

# takelage git check module
module GitCheckModule

  # Backend method for git check clean.
  # @return [Boolean] is git workspace clean?
  def git_check_clean
    log.debug "Checking if git workspace is clean"

    return false unless git_check_workspace

    cmd_git_unstaged =
        config.active['cmd_git_check_clean_git_unstaged']

    cmd_git_uncommitted =
        config.active['cmd_git_check_clean_git_uncommitted']

    cmd_git_status =
        config.active['cmd_git_check_clean_git_status']

    status_unstaged = try cmd_git_unstaged
    status_uncommitted = try cmd_git_uncommitted
    stdout_str_status = run cmd_git_status

    # only return true if neither unstaged nor uncommitted nor empty files
    sum = status_unstaged.exitstatus +
        status_uncommitted.exitstatus +
        stdout_str_status.length

    sum.zero?
  end

  # Backend method for git check master.
  # @return [Boolean] are we on the git master branch?
  def git_check_master
    log.debug 'Check if we are on the git master branch'

    return false unless git_check_workspace

    cmd_get_branch =
        config.active['cmd_git_check_master_git_branch']

    stdout_str = run cmd_get_branch

    branch = stdout_str.strip.split('/')[-1]

    log.debug "We are on git branch \"#{branch}\""

    branch == 'master'
  end

  # Backend method for git check workspace.
  # @return [Boolean] is this a git workspace?
  def git_check_workspace
    log.debug 'Check if this is a git workspace'

    cmd_git_repo =
        config.active['cmd_git_check_workspace_git_repo']

    status_repo = try cmd_git_repo

    cmd_pwd =
        config.active['cmd_git_check_workspace_pwd']

    stdout_str_dir = run cmd_pwd

    dir = stdout_str_dir.strip

    unless status_repo.exitstatus.zero?
      log.debug "No git workspace found in \"#{dir}\""
      return false
    end

    true
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
takelage-0.13.2 lib/takelage/git/check/module.rb
takelage-0.13.1 lib/takelage/git/check/module.rb
takelage-0.13.0 lib/takelage/git/check/module.rb
takelage-0.12.2 lib/takelage/git/check/module.rb
takelage-0.12.1 lib/takelage/git/check/module.rb
takelage-0.12.0 lib/takelage/git/check/module.rb
takelage-0.11.1 lib/takelage/git/check/module.rb
takelage-0.11.0 lib/takelage/git/check/module.rb
takelage-0.10.0 lib/takelage/git/check/module.rb
takelage-0.9.2 lib/takelage/git/check/module.rb