Sha256: 5fd736ba2d6d2ddb59aae545c7036d796c09c2148c349005290391020c8d4243

Contents?: true

Size: 1.64 KB

Versions: 118

Compression:

Stored size: 1.64 KB

Contents

module Daddy
  
  class Git

    def branches(remote = false)
      branches = []
      `git branch -a`.split("\n").each do |b|
        next unless b.index('remotes/origin/master') or b.index(/remotes\/origin\/p[0-9]+(\.[0-9]+)?/)
        
        if remote
          branches << b.strip
        else
          branches << b.strip.sub('remotes/origin/', '')
        end
      end
      
      branches.sort! do |a, b|
        if a == 'master' or a == 'remotes/origin/master'
          -1
        elsif b == 'master' or b == 'remotes/origin/master'
          1
        else
          if remote
            b.sub('remotes/origin/p', '').to_f <=> a.sub('remotes/origin/p', '').to_f
          else
            b.sub('p', '').to_f <=> a.sub('p', '').to_f
          end
        end
      end
      
      branches
    end
    
    def current_branch
      `git branch`.split("\n").each do |b|
        return b.split.last if b.start_with?('*')
      end
    end
    
    def previous_branch(remote = false)
      current_branch = self.current_branch
      branches = self.branches(remote)

      branches.each_with_index do |b, i|
        return nil if i == branches.size - 1

        if b == current_branch or b == "remotes/origin/#{current_branch}"
          return branches[i+1]
        end
      end
    end
    
    def show_previous(file, options = {})
      remote = options[:remote]
      commit = options[:commit]

      if commit
        `git show #{commit}:#{file}`
      else
        `git show #{previous_branch(remote)}:#{file}`
      end
    end

    def git_diff_name(*includes)
      `git diff origin/#{previous_branch} --name-only #{includes.join(' ')}`
    end
  end

end

Version data entries

118 entries across 118 versions & 1 rubygems

Version Path
daddy-0.9.19 lib/daddy/git.rb
daddy-0.9.18 lib/daddy/git.rb
daddy-0.9.17 lib/daddy/git.rb
daddy-0.9.16 lib/daddy/git.rb
daddy-0.9.15 lib/daddy/git.rb
daddy-0.9.14 lib/daddy/git.rb
daddy-0.9.13 lib/daddy/git.rb
daddy-0.9.12 lib/daddy/git.rb
daddy-0.9.11 lib/daddy/git.rb
daddy-0.9.10 lib/daddy/git.rb
daddy-0.9.9 lib/daddy/git.rb
daddy-0.9.8 lib/daddy/git.rb
daddy-0.9.7 lib/daddy/git.rb
daddy-0.9.6 lib/daddy/git.rb
daddy-0.9.5 lib/daddy/git.rb
daddy-0.9.4 lib/daddy/git.rb
daddy-0.9.3 lib/daddy/git.rb
daddy-0.9.2 lib/daddy/git.rb
daddy-0.9.1 lib/daddy/git.rb
daddy-0.9.0 lib/daddy/git.rb