Sha256: 8479cfb90ed0667c758a066aac841369fc7a46ee1730d36643c753438ca80464

Contents?: true

Size: 1.29 KB

Versions: 27

Compression:

Stored size: 1.29 KB

Contents

module Pushapp

  class Git

    def update_tracked_repos config
      refs         = required_refs(config)
      current_refs = current_refs(config)

      new_refs    = new_refs(refs, current_refs)
      old_refs    = old_refs(refs, current_refs)

      new_refs.each do |r|
        Pushapp::Pipe.run("git config --add remote.#{r[0]}.url #{r[1]}")
      end

      old_refs.each do |r|
        Pushapp::Pipe.run("git config --unset remote.#{r[0]}.url #{r[1]}")
      end
    end

    private

    def new_refs refs, cur_refs
      refs.select do |r|
        cur_refs.all? {|cr| r != cr }
      end
    end

    def old_refs refs, cur_refs
      cur_refs.select do |cr|
        refs.all? {|r| r != cr }
      end
    end

    def current_refs config
      output = Pipe.capture('git remote -v')

      refs     = required_refs(config)
      remotes  = refs.map {|r| r[0]}.uniq
      
      current_refs = output.lines.map do |l|
        l.gsub(/\s\(.*\)?\Z/, "").chomp
      end
      current_refs = current_refs.uniq.map { |line| line.split(/\t/) }
      current_refs.select {|r| remotes.include?(r[0])}
    end

    def required_refs config
      refs = []
      config.remotes.each do |r|
        refs << [r.group, r.location] if r.group
        refs << [r.full_name, r.location]
      end
      refs
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
pushapp-0.2.10 lib/pushapp/git.rb
pushapp-0.2.9 lib/pushapp/git.rb
pushapp-0.2.8 lib/pushapp/git.rb
pushapp-0.2.7 lib/pushapp/git.rb
pushapp-0.2.6 lib/pushapp/git.rb
pushapp-0.2.5 lib/pushapp/git.rb
pushapp-0.2.4 lib/pushapp/git.rb
pushapp-0.2.3 lib/pushapp/git.rb
pushapp-0.2.2 lib/pushapp/git.rb
pushapp-0.2.1 lib/pushapp/git.rb
pushapp-0.2.0 lib/pushapp/git.rb
pushapp-0.1.9 lib/pushapp/git.rb
pushapp-0.1.8 lib/pushapp/git.rb
pushapp-0.1.7 lib/pushapp/git.rb
pushapp-0.1.6 lib/pushapp/git.rb
pushapp-0.1.5 lib/pushapp/git.rb
pushapp-0.1.4 lib/pushapp/git.rb
pushapp-0.1.3 lib/pushapp/git.rb
pushapp-0.1.2 lib/pushapp/git.rb
pushapp-0.1.1 lib/pushapp/git.rb