Sha256: 7838a7b9773d4e6d681804938941e9ef021b4c59d3ea192f15bc008a480b6313

Contents?: true

Size: 898 Bytes

Versions: 9

Compression:

Stored size: 898 Bytes

Contents

require "pathname"

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

    class PathError < ArgumentError; end
    class InvalidError < StandardError; end

    def initialize(path)
      @path = Pathname::new(path.to_s)
      fail PathError, "'#{path}' must be an absolute path!" unless @path.absolute?
      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| 
        @path.join(".git", name).exist?
      end
    end

    def unlock
      Dir.chdir(self) do
        `git rebase --abort`
      end
    end

    private def valid?
      @path.directory? && work_tree?
    end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
git_commands-3.5.3 lib/git_commands/repository.rb
git_commands-3.5.2 lib/git_commands/repository.rb
git_commands-3.5.1 lib/git_commands/repository.rb
git_commands-3.4.0 lib/git_commands/repository.rb
git_commands-3.3.7 lib/git_commands/repository.rb
git_commands-3.3.6 lib/git_commands/repository.rb
git_commands-3.3.5 lib/git_commands/repository.rb
git_commands-3.3.4 lib/git_commands/repository.rb
git_commands-3.3.3 lib/git_commands/repository.rb