Sha256: 86ba652feab8dd5bbab0d7fbd292d309012dcd39fda36dd05ce569ea0b69c823

Contents?: true

Size: 1.65 KB

Versions: 10

Compression:

Stored size: 1.65 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['git_unstaged']
    cmd_git_uncommitted = config.active['git_uncommitted']
    cmd_git_status = config.active['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['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['git_repo']
    status_repo = try cmd_git_repo

    cmd_pwd = config.active['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.9.1 lib/takelage/git/check/module.rb
takelage-0.9.0 lib/takelage/git/check/module.rb
takelage-0.8.1 lib/takelage/git/check/module.rb
takelage-0.8.0 lib/takelage/git/check/module.rb
takelage-0.7.2 lib/takelage/git/check/module.rb
takelage-0.7.1 lib/takelage/git/check/module.rb
takelage-0.7.0 lib/takelage/git/check/module.rb
takelage-0.6.0 lib/takelage/git/check/module.rb
takelage-0.5.1 lib/takelage/git/check/module.rb
takelage-0.5.0 lib/takelage/git/check/module.rb