Sha256: 2c7fc27fe31253cab2d66e260382df3db429b65140f778e08d30c19e3c9dc654

Contents?: true

Size: 1.23 KB

Versions: 86

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Avm
  module Git
    module Launcher
      class Remote
        common_constructor :git, :name

        def exist?
          git.execute!('remote').each_line.any? { |line| line.strip == name }
        end

        def ls
          git.execute!(['ls-remote', name]).each_line.map do |line|
            x = line.strip.split(/\s+/)
            [x[1], x[0]]
          end.to_h
        end

        # +git remote add ...+
        def add(url)
          git.execute!('remote', 'add', name, url)
        end

        # +git remote rm ...+
        def remove
          git.execute!('remote', 'rm', name)
        end

        # +git remote get-url ...+
        def url
          git.execute!('remote', 'get-url', name).strip.if_present(nil)
        end

        # git remote set-url ...
        def url_set(url)
          git.execute!('remote', 'set-url', name, url)
        end

        # Add or set URL if +url+ is present, remove remote if is blank.
        def url=(url)
          if exist? && url.blank?
            remove
          elsif exist? && self.url != url
            url_set(url)
          elsif !exist?
            add(url)
          end
        end
      end
    end
  end
end

Version data entries

86 entries across 86 versions & 2 rubygems

Version Path
eac_tools-0.80.0 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.79.0 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.78.0 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.77.1 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.77.0 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.76.1 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.76.0 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.75.2 sub/avm-git/lib/avm/git/launcher/remote.rb
avm-git-0.13.4 lib/avm/git/launcher/remote.rb
eac_tools-0.75.1 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.75.0 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.74.1 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.74.0 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.73.0 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.72.0 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.70.1 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.70.0 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.69.1 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.69.0 sub/avm-git/lib/avm/git/launcher/remote.rb
eac_tools-0.68.0 sub/avm-git/lib/avm/git/launcher/remote.rb