Sha256: 033e05d818101481998050f334ff220e07c927fda4f59a7d77f783dd2372d117

Contents?: true

Size: 1.23 KB

Versions: 109

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Avm
  module Launcher
    module Git
      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

109 entries across 109 versions & 2 rubygems

Version Path
avm-tools-0.140.0 lib/avm/launcher/git/remote.rb
eac_tools-0.36.0 sub/avm-tools/lib/avm/launcher/git/remote.rb
avm-tools-0.139.0 lib/avm/launcher/git/remote.rb
eac_tools-0.35.0 sub/avm-tools/lib/avm/launcher/git/remote.rb
avm-tools-0.138.0 lib/avm/launcher/git/remote.rb
eac_tools-0.34.0 sub/avm-tools/lib/avm/launcher/git/remote.rb
avm-tools-0.137.0 lib/avm/launcher/git/remote.rb
eac_tools-0.33.0 sub/avm-tools/lib/avm/launcher/git/remote.rb
eac_tools-0.32.0 sub/avm-tools/lib/avm/launcher/git/remote.rb
avm-tools-0.136.2 lib/avm/launcher/git/remote.rb
eac_tools-0.31.1 sub/avm-tools/lib/avm/launcher/git/remote.rb
eac_tools-0.31.0 sub/avm-tools/lib/avm/launcher/git/remote.rb
avm-tools-0.136.1 lib/avm/launcher/git/remote.rb
eac_tools-0.30.0 sub/avm-tools/lib/avm/launcher/git/remote.rb
eac_tools-0.29.0 sub/avm-tools/lib/avm/launcher/git/remote.rb
avm-tools-0.136.0 lib/avm/launcher/git/remote.rb
eac_tools-0.28.0 sub/avm-tools/lib/avm/launcher/git/remote.rb
eac_tools-0.27.2 sub/avm-tools/lib/avm/launcher/git/remote.rb
eac_tools-0.27.1 sub/avm-tools/lib/avm/launcher/git/remote.rb
avm-tools-0.135.0 lib/avm/launcher/git/remote.rb