Sha256: 1e2b71b51e014ec80c43b21d81fe47787a3a6ed5c17d3c0f1487108896c51bb4

Contents?: true

Size: 896 Bytes

Versions: 16

Compression:

Stored size: 896 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

16 entries across 16 versions & 1 rubygems

Version Path
trello_flow-3.3.0 lib/trello_flow/cleanup.rb
trello_flow-3.1.0 lib/trello_flow/cleanup.rb
trello_flow-3.0.0 lib/trello_flow/cleanup.rb
trello_flow-2.3.1 lib/trello_flow/cleanup.rb
trello_flow-2.3.0 lib/trello_flow/cleanup.rb
trello_flow-2.2.1 lib/trello_flow/cleanup.rb
trello_flow-2.2.0 lib/trello_flow/cleanup.rb
trello_flow-2.1.0 lib/trello_flow/cleanup.rb
trello_flow-2.0.1 lib/trello_flow/cleanup.rb
trello_flow-2.0.0 lib/trello_flow/cleanup.rb
trello_flow-1.3.0 lib/trello_flow/cleanup.rb
trello_flow-1.2.2 lib/trello_flow/cleanup.rb
trello_flow-1.2.1 lib/trello_flow/cleanup.rb
trello_flow-1.2.0 lib/trello_flow/cleanup.rb
trello_flow-1.1.0 lib/trello_flow/cleanup.rb
trello_flow-1.0.1 lib/trello_flow/cleanup.rb