Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
49d2e4cb
Commit
49d2e4cb
authored
4 years ago
by
Jonathan Chang
Browse files
Options
Downloads
Patches
Plain Diff
utils/git: modernize
parent
9dd5d424
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Library/Homebrew/utils/git.rb
+15
-20
15 additions, 20 deletions
Library/Homebrew/utils/git.rb
with
15 additions
and
20 deletions
Library/Homebrew/utils/git.rb
+
15
−
20
View file @
49d2e4cb
# frozen_string_literal: true
require
"open3"
module
Utils
# Helper functions for querying Git information.
#
...
...
@@ -16,7 +14,7 @@ module Utils
def
version
return
@version
if
defined?
(
@version
)
stdout
,
_
,
status
=
system_command
(
HOMEBREW_SHIMS_PATH
/
"scm/
git
"
,
args:
[
"--version"
],
print_stderr:
false
)
stdout
,
_
,
status
=
system_command
(
git
,
args:
[
"--version"
],
print_stderr:
false
)
@version
=
status
.
success?
?
stdout
.
chomp
[
/git version (\d+(?:\.\d+)*)/
,
1
]
:
nil
end
...
...
@@ -24,7 +22,13 @@ module Utils
return
unless
available?
return
@path
if
defined?
(
@path
)
@path
=
Utils
.
popen_read
(
HOMEBREW_SHIMS_PATH
/
"scm/git"
,
"--homebrew=print-path"
).
chomp
.
presence
@path
=
Utils
.
popen_read
(
git
,
"--homebrew=print-path"
).
chomp
.
presence
end
def
git
return
@git
if
defined?
(
@git
)
@git
=
HOMEBREW_SHIMS_PATH
/
"scm/git"
end
def
remote_exists?
(
url
)
...
...
@@ -36,6 +40,7 @@ module Utils
def
clear_available_cache
remove_instance_variable
(
:@version
)
if
defined?
(
@version
)
remove_instance_variable
(
:@path
)
if
defined?
(
@path
)
remove_instance_variable
(
:@git
)
if
defined?
(
@git
)
end
def
last_revision_commit_of_file
(
repo
,
file
,
before_commit:
nil
)
...
...
@@ -45,12 +50,7 @@ module Utils
[
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
Utils
.
popen_read
(
git
,
"-C"
,
repo
,
"log"
,
"--format=%h"
,
"--abbrev=7"
,
"--max-count=1"
,
*
args
,
"--"
,
file
).
chomp
end
def
last_revision_commit_of_files
(
repo
,
files
,
before_commit:
nil
)
...
...
@@ -66,12 +66,11 @@ module Utils
# <file_path2>
# ...
# return [<commit_hash>, [file_path1, file_path2, ...]]
out
,
=
Open3
.
capture3
(
HOMEBREW_SHIMS_PATH
/
"scm/
git
"
,
"-C"
,
repo
,
"log"
,
rev
,
*
paths
=
Utils
.
popen_read
(
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?
)
).
lines
.
map
(
&
:chomp
).
reject
(
&
:empty?
)
[
rev
,
paths
]
end
...
...
@@ -79,11 +78,7 @@ module Utils
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
Utils
.
popen_read
(
git
,
"-C"
,
repo
,
"show"
,
"
#{
commit_hash
}
:
#{
relative_file
}
"
)
end
def
ensure_installed!
...
...
@@ -121,7 +116,7 @@ module Utils
end
def
origin_branch
(
repo
)
Utils
.
popen_read
(
"
git
"
,
"-C"
,
repo
,
"symbolic-ref"
,
"-q"
,
"--short"
,
Utils
.
popen_read
(
git
,
"-C"
,
repo
,
"symbolic-ref"
,
"-q"
,
"--short"
,
"refs/remotes/origin/HEAD"
).
chomp
.
presence
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment