Sha256: ea9529690545aafc519246621e56e8bbe6bfee6d75a8b2225352e129f55b9692
Contents?: true
Size: 983 Bytes
Versions: 2
Compression:
Stored size: 983 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| File.exists?(@path.join(".git", name)) end end def unlock Dir.chdir(@path) do `git rebase --abort` 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
git_commands-3.3.2 | lib/git_commands/repository.rb |
git_commands-3.3.1 | lib/git_commands/repository.rb |