Module: GitRepositoryExtension Private

Extended by:
T::Sig
Defined in:
extend/git_repository.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Extensions to Pathname for querying Git repository information.

See Also:

Instance Method Summary collapse

Instance Method Details

#git?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


14
15
16
# File 'extend/git_repository.rb', line 14

def git?
  join(".git").exist?
end

#git_branch(safe: false) ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Gets the name of the currently checked-out branch, or HEAD if the repository is in a detached HEAD state.

Parameters:

  • safe (Boolean) (defaults to: false)

Returns:



53
54
55
# File 'extend/git_repository.rb', line 53

def git_branch(safe: false)
  popen_git("rev-parse", "--abbrev-ref", "HEAD", safe: safe)
end

#git_branch_set_upstream(local:, origin:) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Set an upstream branch for a local branch to track

Parameters:



65
66
67
# File 'extend/git_repository.rb', line 65

def git_branch_set_upstream(local:, origin:)
  popen_git("branch", "-u", "origin/#{origin}", local)
end

#git_commit_message(commit = "HEAD", safe: false) ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Gets the full commit message of the specified commit, or of the HEAD commit if unspecified.

Parameters:

  • commit (String) (defaults to: "HEAD")
  • safe (Boolean) (defaults to: false)

Returns:



100
101
102
# File 'extend/git_repository.rb', line 100

def git_commit_message(commit = "HEAD", safe: false)
  popen_git("log", "-1", "--pretty=%B", commit, "--", safe: safe, err: :out)&.strip
end

#git_default_origin_branch?Boolean?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns true if the repository’s current branch matches the default origin branch.

Returns:

  • (Boolean, nil)


77
78
79
# File 'extend/git_repository.rb', line 77

def git_default_origin_branch?
  git_origin_branch == git_branch
end

#git_head(safe: false) ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Gets the full commit hash of the HEAD commit.

Parameters:

  • safe (Boolean) (defaults to: false)

Returns:



34
35
36
# File 'extend/git_repository.rb', line 34

def git_head(safe: false)
  popen_git("rev-parse", "--verify", "--quiet", "HEAD", safe: safe)
end

#git_last_commitString?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Gets the relative date of the last commit, e.g. “1 hour ago”

Returns:



47
48
49
# File 'extend/git_repository.rb', line 47

def git_last_commit
  popen_git("show", "-s", "--format=%cr", "HEAD")
end

#git_last_commit_dateString?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns the date of the last commit, in YYYY-MM-DD format.

Returns:



83
84
85
# File 'extend/git_repository.rb', line 83

def git_last_commit_date
  popen_git("show", "-s", "--format=%cd", "--date=short", "HEAD")
end

#git_originString?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Gets the URL of the Git origin remote.

Returns:



20
21
22
# File 'extend/git_repository.rb', line 20

def git_origin
  popen_git("config", "--get", "remote.origin.url")
end

#git_origin=(origin) ⇒ Boolean?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Sets the URL of the Git origin remote.

Parameters:

Returns:

  • (Boolean, nil)


26
27
28
29
30
# File 'extend/git_repository.rb', line 26

def git_origin=(origin)
  return if !git? || !Utils::Git.available?

  safe_system Utils::Git.git, "remote", "set-url", "origin", origin, chdir: self
end

#git_origin_branchString?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Gets the name of the default origin HEAD branch.

Returns:



71
72
73
# File 'extend/git_repository.rb', line 71

def git_origin_branch
  popen_git("symbolic-ref", "-q", "--short", "refs/remotes/origin/HEAD")&.split("/")&.last
end

#git_origin_has_branch?(branch) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns true if the given branch exists on origin

Parameters:

Returns:

  • (Boolean)


89
90
91
# File 'extend/git_repository.rb', line 89

def git_origin_has_branch?(branch)
  popen_git("ls-remote", "--heads", "origin", branch).present?
end

#git_origin_set_head_autovoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



94
95
96
# File 'extend/git_repository.rb', line 94

def git_origin_set_head_auto
  popen_git("remote", "set-head", "origin", "--auto")
end

#git_rename_branch(old:, new:) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Change the name of a local branch

Parameters:



59
60
61
# File 'extend/git_repository.rb', line 59

def git_rename_branch(old:, new:)
  popen_git("branch", "-m", old, new)
end

#git_short_head(length: nil, safe: false) ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Gets a short commit hash of the HEAD commit.

Parameters:

  • length (Integer, nil) (defaults to: nil)
  • safe (Boolean) (defaults to: false)

Returns:



40
41
42
43
# File 'extend/git_repository.rb', line 40

def git_short_head(length: nil, safe: false)
  short_arg = length.present? ? "--short=#{length}" : "--short"
  popen_git("rev-parse", short_arg, "--verify", "--quiet", "HEAD", safe: safe)
end