Module: Git

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

Class Method Summary collapse

Class Method Details

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'brew/Library/Homebrew/utils/git.rb', line 8

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

  out, = Open3.capture3(
    HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo,
    "log", "--format=%h", "--abbrev=7", "--max-count=1",
    *args, "--", file
  )
  out.chomp
end

.last_revision_commit_of_files(repo, files, before_commit: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'brew/Library/Homebrew/utils/git.rb', line 23

def last_revision_commit_of_files(repo, files, before_commit: nil)
  args = if before_commit.nil?
    ["--skip=1"]
  else
    [before_commit.split("..").first]
  end

  # git log output format:
  #   <commit_hash>
  #   <file_path1>
  #   <file_path2>
  #   ...
  # return [<commit_hash>, [file_path1, file_path2, ...]]
  out, = Open3.capture3(
    HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo, "log",
    "--pretty=format:%h", "--abbrev=7", "--max-count=1",
    "--diff-filter=d", "--name-only", *args, "--", *files
  )
  rev, *paths = out.chomp.split(/\n/).reject(&:empty?)
  [rev, paths]
end

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



45
46
47
48
49
50
51
52
53
54
# File 'brew/Library/Homebrew/utils/git.rb', line 45

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