Module: Git

Defined in:
Library/Homebrew/utils/git.rb

Class Method Summary collapse

Class Method Details

.last_revision_commit_of_file(repo, file, before_commit: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'Library/Homebrew/utils/git.rb', line 6

def last_revision_commit_of_file(repo, file, before_commit: nil)
  args = [before_commit.nil? ? "--skip=1" : before_commit.split("..").first]

  out, = Open3.capture3(
    HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo,
    "log", "--oneline", "--max-count=1", *args, "--", file
  )
  out.split(" ").first
end

.last_revision_of_file(repo, file, before_commit: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'Library/Homebrew/utils/git.rb', line 16

def last_revision_of_file(repo, file, before_commit: nil)
  relative_file = Pathname(file).relative_path_from(repo)

  commit_hash = last_revision_commit_of_file(repo, relative_file, before_commit: before_commit)
  out, = Open3.capture3(
    HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo,
    "show", "#{commit_hash}:#{relative_file}"
  )
  out
end