Module: SimpleCov::CLI::Git
Overview
The git plumbing the change-aware subcommands share: safe capture, the repository toplevel, ref hygiene, and the default base ref.
Instance Method Summary collapse
-
#capture(*argv) ⇒ Object
[stdout, first stderr line, success].
-
#default_base ⇒ Object
The branch origin's HEAD points at, so master and trunk repositories work bare, falling back to main where no origin HEAD is recorded.
-
#option_like_ref?(ref) ⇒ Boolean
A git ref can never begin with "-", so one that does would be read by git as an option instead of a revision.
- #toplevel ⇒ Object
Instance Method Details
#capture(*argv) ⇒ Object
[stdout, first stderr line, success]. A spawn failure reads as an unsuccessful run whose stdout is nil, so callers can tell "git ran and refused" from "git never ran".
15 16 17 18 19 20 |
# File 'lib/simplecov/cli/git.rb', line 15 def capture(*argv) stdout, stderr, status = Open3.capture3("git", *argv) [stdout, stderr.lines.first.to_s.strip, status.success?] rescue => e [nil, e., false] end |
#default_base ⇒ Object
The branch origin's HEAD points at, so master and trunk repositories work bare, falling back to main where no origin HEAD is recorded.
35 36 37 38 |
# File 'lib/simplecov/cli/git.rb', line 35 def default_base stdout, _detail, success = capture("symbolic-ref", "--short", "refs/remotes/origin/HEAD") success ? (_ = stdout).chomp.delete_prefix("origin/") : "main" end |
#option_like_ref?(ref) ⇒ Boolean
A git ref can never begin with "-", so one that does would be read by git as an option instead of a revision.
29 30 31 |
# File 'lib/simplecov/cli/git.rb', line 29 def option_like_ref?(ref) ref.start_with?("-") end |
#toplevel ⇒ Object
22 23 24 25 |
# File 'lib/simplecov/cli/git.rb', line 22 def toplevel stdout, _detail, success = capture("rev-parse", "--show-toplevel") (_ = stdout).chomp if success end |