Class: GitCommands::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/git_commands/repository.rb

Defined Under Namespace

Classes: InvalidError, PathError

Constant Summary collapse

LOCKING_FILES =
%w(rebase-merge rebase-apply)

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Repository

Returns a new instance of Repository.



10
11
12
13
14
# File 'lib/git_commands/repository.rb', line 10

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

Instance Method Details

#locked?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/git_commands/repository.rb', line 20

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

#to_pathObject



16
17
18
# File 'lib/git_commands/repository.rb', line 16

def to_path
  @path.to_s
end

#unlockObject



26
27
28
29
30
# File 'lib/git_commands/repository.rb', line 26

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