Sha256: c6c07e1b8e828b9bf7b42bafd1aed16b16e2073170822d441fa4284b33b99026

Contents?: true

Size: 894 Bytes

Versions: 6

Compression:

Stored size: 894 Bytes

Contents

module TrelloFlow
  class Cleanup
    def initialize(target)
      @target = target
    end

    def run
      Cli.title "Cleaning merged story branches for [#{target}]"
      update_remotes
      remove_fully_merged_local_branches
      remove_fully_merged_remote_branches
      Cli.success "Deleted branches merged with [#{target}]"
    end

    private

      attr_reader :target

      def update_remotes
        Cli.run "git fetch"
        Cli.run "git remote prune origin"
      end

      def remove_fully_merged_local_branches
        Cli.run "git branch --merged origin/#{target} | grep '#{filter}' | xargs git branch -D"
      end

      def remove_fully_merged_remote_branches
        Cli.run "git branch -r --merged origin/#{target} | sed 's/ *origin\\///' | grep '#{filter}' | xargs -I% git push origin :%"
      end

      def filter
        "\\.#{target}\\."
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
trello_flow-3.8.0 lib/trello_flow/cleanup.rb
trello_flow-3.7.1 lib/trello_flow/cleanup.rb
trello_flow-3.7.0 lib/trello_flow/cleanup.rb
trello_flow-3.6.0 lib/trello_flow/cleanup.rb
trello_flow-3.5.0 lib/trello_flow/cleanup.rb
trello_flow-3.4.0 lib/trello_flow/cleanup.rb