Sha256: 6781175c08da0a43b4b5b97254cbbfbe5245f707da77dee939bf7681613914f3

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module GitTopic
  class << self; attr_accessor :global_opts end
  self.global_opts = {}
end

module GitTopic::Git
  module ClassMethods

    protected

    def working_tree_clean?
      git [ "diff --quiet", "diff --quiet --cached" ]
      $?.success?
    end

    def working_tree_dirty?
      not working_tree_clean?
    end


    def display_git_output?
      @@display_git_output ||= false
    end

    def display_git_output!
      @@display_git_output = true
    end


    def switch_to_branch( branch, tracking=nil )
      if branches.include?( branch )
        "checkout #{branch}"
      else
        "checkout -b #{branch} #{tracking}"
      end
    end

    def cmd_redirect_suffix( opts )
      if !opts[:show] && !display_git_output?
        "> /dev/null 2> /dev/null"
      end
    end

    def git( cmds=[], opts={} )
      cmds  = [cmds] if cmds.is_a? String
      redir = cmd_redirect_suffix( opts )
      cmd = cmds.map{|c| "git #{c} #{redir}"}.join( " && " )

      puts cmd if GitTopic::global_opts[:verbose]
      system cmd
    end

    def capture_git( cmds=[] )
      cmds = [cmds] if cmds.is_a? String
      redir = "2> /dev/null" unless display_git_output?
      cmd = "#{cmds.map{|c| "git #{c} #{redir}"}.join( " && " )}"

      puts cmd if GitTopic::global_opts[:verbose]
      `#{cmd}`
    end

  end

  def self.included( base )
    base.extend ClassMethods
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git-topic-0.1.6.4 lib/git_topic/git.rb