Sha256: 4edb5b3ab5fb451241b161b5f0775c0fb3d1c0254f0e9dfda77bcf153e8636e1

Contents?: true

Size: 1.65 KB

Versions: 10

Compression:

Stored size: 1.65 KB

Contents

#!/usr/bin/ruby -w


module GitTopic; end

module GitTopic::Completion
  class << self

    def user
      ENV['USER']
    end

    def branches
      `git branch -a --no-color`.split( "\n" ).map do |l|
        l.gsub( /->.*$/, '' )[ 2..-1 ]
      end
    end

    def others_review_branches
      branches.map do |b|
        b =~ %r{^remotes/origin/review/(.*)} && $1
      end.reject do |b|
        b =~ %r{^#{user}/}
      end.compact
    end

    def my_reject_review_and_all_wip_branches
      branches.map do |b|
        b =~ %r{^remotes/origin/(rejected)/#{user}/(.*)}  ||
        b =~ %r{^remotes/origin/(review)/#{user}/(.*)}    ||
        b =~ %r{^remotes/origin/(wip)/(\S*?)/(.*)}
        suggestion = [$1,($2 unless $2 == user), $3].compact.join("/")
        suggestion unless suggestion.strip.empty?
      end.compact
    end

    def all_reject_and_review_branches
      branches.map do |b|
        b =~ %r{^remotes/origin/(rejected|review)/(\S*)/(.*)}
        suggestion = [$1,($2 unless $2 == user), $3].compact.join("/")
        suggestion unless suggestion.strip.empty?
      end.compact
    end

    def complete
      suggestions = 
        case ARGV.shift
        # TODO 2: if we let accept/reject take args, simply return
        # others_review_branches here
        when "accept"
        when "reject"
        when "comment"
        when "done"
          # nothing
        when "comments"
          all_reject_and_review_branches
        when "work-on"
          my_reject_review_and_all_wip_branches
        when "review"
          others_review_branches
        end || []

      suggestions.each{ |s| puts s }
    end

  end
end

GitTopic::Completion.complete

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
git-topic-0.2.7.3 bin/git-topic-completion
git-topic-0.2.7.2 bin/git-topic-completion
git-topic-0.2.7.1 bin/git-topic-completion
git-topic-0.2.7 bin/git-topic-completion
git-topic-0.2.6.1 bin/git-topic-completion
git-topic-0.2.6 bin/git-topic-completion
git-topic-0.2.5 bin/git-topic-completion
git-topic-0.2.4.1 bin/git-topic-completion
git-topic-0.2.4 bin/git-topic-completion
git-topic-0.2.3.3 bin/git-topic-completion