Sha256: 4e3a0e950de1f484419b5098c2856de234e33e2b7c8b1920e1527d9efb6b88b7

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 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{^(wip)/#{user}/(.*)}                      ||
        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 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 "done"
          # nothing
        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

2 entries across 2 versions & 1 rubygems

Version Path
git-topic-0.2.3.1 bin/git-topic-completion
git-topic-0.2.3 bin/git-topic-completion