Class: FilesInMyDiff::Git::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/files_in_my_diff/git/adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(folder:, repo: ::Git.open(folder)) ⇒ Adapter

Returns a new instance of Adapter.



6
7
8
# File 'lib/files_in_my_diff/git/adapter.rb', line 6

def initialize(folder:, repo: ::Git.open(folder))
  @repo = repo
end

Instance Method Details

#checkout_worktree(path, revision) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/files_in_my_diff/git/adapter.rb', line 14

def checkout_worktree(path, revision)
  @repo.add_worktree(path, revision)
rescue ::Git::FailedError => e
  unless e.result.stderr.include? 'already exists'
    raise CheckoutError,
          "Could not checkout #{revision} to #{path}: #{e.message}"
  end
end

#diff(revision) ⇒ Object



10
11
12
# File 'lib/files_in_my_diff/git/adapter.rb', line 10

def diff(revision)
  Diff.new(object: object(revision), revision:)
end