Sha256: a69e93931ac0b504a1398ff59ccad492b093f63e8d3cfb5a38a44f18145b2b85

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

module Vim
  module Jar
    module Installer
      module Git
        extend self

        def install_to(source, output_path)
          Dir.chdir(config.vim_home) do
            system("git submodule add #{source} #{Pathname.new(output_path).relative_path_from(config.vim_home)}")
            system("git submodule init")
          end
        end

        def uninstall_for(name)
          remove_ref_from_gitmodules(name)
          remove_ref_from_git_config(name)
          remove_from_cache(name)
        end

        def remove_from_cache(name)
          Dir.chdir(config.vim_home) do
            system("git rm -rf --cached bundle/#{name}")
          end
          Dir.chdir(config.vim_home) do
            system("rm -rf bundle/#{name}")
          end
        end

        def remove_ref_from_gitmodules(name)
          #TODO bundle name is different to submodule name
          f     = File.new(config.gitmodules_file_path)
          lines = f.lines.to_a
          lines.delete_if do |x|
            x =~ /bundle\/#{name}/ || x =~ /#{name}\.git$/
          end
          f.close

          File.open(config.gitmodules_file_path, "w") do |ff|
            lines.each do |l|
              ff.puts l
            end
          end
        end

        def remove_ref_from_git_config(name)
          #TODO bundle name is different to submodule name
          f     = File.new(config.gitconfig_file_path)
          lines = f.lines.to_a
          lines.delete_if do |x|
            x =~ /bundle\/#{name}/ || x =~ /#{name}\.git$/
          end
          f.close

          File.open(config.gitconfig_file_path, "w") do |ff|
            lines.each do |l|
              ff.puts l
            end
          end
        end

        def config
          ::Vim::Jar::Config.instance
        end
      end
    end
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vimjar-0.3.1 lib/vim-jar/installer/git.rb