Sha256: 8796483ec7754495af28e449305f49bcfe0573421f69b427cef2179d0d1471fc

Contents?: true

Size: 770 Bytes

Versions: 6

Compression:

Stored size: 770 Bytes

Contents

require "pathname"

module GitCommands
  class Repository
    LOCKING_FILES = %w(rebase-merge rebase-apply)

    class InvalidError < StandardError; end

    def initialize(path)
      @path = Pathname::new(path.to_s)
      fail InvalidError, "'#{path}' is not a valid GIT repository!" unless valid?
    end

    def to_path
      @path.to_s
    end

    def locked?
      LOCKING_FILES.any? do |name| 
        File.exists?(@path.join(".git", name))
      end
    end

    private def valid?
      return false unless exists?
      work_tree?
    end

    private def exists?
      File.directory?(@path)
    end

    private def work_tree?
      Dir.chdir(@path) do
        `git rev-parse --is-inside-work-tree 2> /dev/null`.strip == "true"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
git_commands-3.2.5 lib/git_commands/repository.rb
git_commands-3.2.4 lib/git_commands/repository.rb
git_commands-3.2.3 lib/git_commands/repository.rb
git_commands-3.2.2 lib/git_commands/repository.rb
git_commands-3.2.1 lib/git_commands/repository.rb
git_commands-3.2.0 lib/git_commands/repository.rb