mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Use system_command
for GitDownloadStrategy
.
This commit is contained in:
parent
28fd59672a
commit
e220406a6e
@ -690,14 +690,12 @@ class GitDownloadStrategy < VCSDownloadStrategy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
cached_location.cd do
|
|
||||||
config_repo
|
config_repo
|
||||||
update_repo
|
update_repo
|
||||||
checkout
|
checkout
|
||||||
reset
|
reset
|
||||||
update_submodules if submodules?
|
update_submodules if submodules?
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def shallow_clone?
|
def shallow_clone?
|
||||||
@shallow && support_depth?
|
@shallow && support_depth?
|
||||||
@ -716,15 +714,20 @@ class GitDownloadStrategy < VCSDownloadStrategy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def ref?
|
def ref?
|
||||||
quiet_system "git", "--git-dir", git_dir, "rev-parse", "-q", "--verify", "#{@ref}^{commit}"
|
system_command("git",
|
||||||
|
args: ["--git-dir", git_dir, "rev-parse", "-q", "--verify", "#{@ref}^{commit}"],
|
||||||
|
print_stderr: false)
|
||||||
|
.success?
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_revision
|
def current_revision
|
||||||
Utils.popen_read("git", "--git-dir", git_dir, "rev-parse", "-q", "--verify", "HEAD").strip
|
system_command("git", args: ["--git-dir", git_dir, "rev-parse", "-q", "--verify", "HEAD"])
|
||||||
|
.stdout.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
def repo_valid?
|
def repo_valid?
|
||||||
quiet_system "git", "--git-dir", git_dir, "status", "-s"
|
system_command("git", args: ["--git-dir", git_dir, "status", "-s"], print_stderr: false)
|
||||||
|
.success?
|
||||||
end
|
end
|
||||||
|
|
||||||
def submodules?
|
def submodules?
|
||||||
@ -752,35 +755,44 @@ class GitDownloadStrategy < VCSDownloadStrategy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def config_repo
|
def config_repo
|
||||||
safe_system "git", "config", "remote.origin.url", @url
|
system_command! "git",
|
||||||
safe_system "git", "config", "remote.origin.fetch", refspec
|
args: ["config", "remote.origin.url", @url],
|
||||||
|
chdir: cached_location
|
||||||
|
system_command! "git",
|
||||||
|
args: ["config", "remote.origin.fetch", refspec],
|
||||||
|
chdir: cached_location
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_repo
|
def update_repo
|
||||||
return unless @ref_type == :branch || !ref?
|
return unless @ref_type == :branch || !ref?
|
||||||
|
|
||||||
if !shallow_clone? && shallow_dir?
|
if !shallow_clone? && shallow_dir?
|
||||||
safe_system "git", "fetch", "origin", "--unshallow"
|
system_command! "git",
|
||||||
|
args: ["fetch", "origin", "--unshallow"],
|
||||||
|
chdir: cached_location
|
||||||
else
|
else
|
||||||
safe_system "git", "fetch", "origin"
|
system_command! "git",
|
||||||
|
args: ["fetch", "origin"],
|
||||||
|
chdir: cached_location
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def clone_repo
|
def clone_repo
|
||||||
safe_system "git", *clone_args
|
system_command! "git", args: clone_args
|
||||||
cached_location.cd do
|
|
||||||
safe_system "git", "config", "homebrew.cacheversion", cache_version
|
system_command! "git",
|
||||||
|
args: ["config", "homebrew.cacheversion", cache_version],
|
||||||
|
chdir: cached_location
|
||||||
checkout
|
checkout
|
||||||
update_submodules if submodules?
|
update_submodules if submodules?
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def checkout
|
def checkout
|
||||||
ohai "Checking out #{@ref_type} #{@ref}" if @ref_type && @ref
|
ohai "Checking out #{@ref_type} #{@ref}" if @ref_type && @ref
|
||||||
safe_system "git", "checkout", "-f", @ref, "--"
|
system_command! "git", args: ["checkout", "-f", @ref, "--"], chdir: cached_location
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_args
|
def reset
|
||||||
ref = case @ref_type
|
ref = case @ref_type
|
||||||
when :branch
|
when :branch
|
||||||
"origin/#{@ref}"
|
"origin/#{@ref}"
|
||||||
@ -788,20 +800,21 @@ class GitDownloadStrategy < VCSDownloadStrategy
|
|||||||
@ref
|
@ref
|
||||||
end
|
end
|
||||||
|
|
||||||
%W[reset --hard #{ref}]
|
system_command! "git",
|
||||||
end
|
args: ["reset", "--hard", *ref],
|
||||||
|
chdir: cached_location
|
||||||
def reset
|
|
||||||
safe_system "git", *reset_args
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_submodules
|
def update_submodules
|
||||||
safe_system "git", "submodule", "foreach", "--recursive", "git submodule sync"
|
system_command! "git",
|
||||||
safe_system "git", "submodule", "update", "--init", "--recursive"
|
args: ["submodule", "foreach", "--recursive", "git submodule sync"],
|
||||||
|
chdir: cached_location
|
||||||
|
system_command! "git",
|
||||||
|
args: ["submodule", "update", "--init", "--recursive"],
|
||||||
|
chdir: cached_location
|
||||||
fix_absolute_submodule_gitdir_references!
|
fix_absolute_submodule_gitdir_references!
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_absolute_submodule_gitdir_references!
|
|
||||||
# When checking out Git repositories with recursive submodules, some Git
|
# When checking out Git repositories with recursive submodules, some Git
|
||||||
# versions create `.git` files with absolute instead of relative `gitdir:`
|
# versions create `.git` files with absolute instead of relative `gitdir:`
|
||||||
# pointers. This works for the cached location, but breaks various Git
|
# pointers. This works for the cached location, but breaks various Git
|
||||||
@ -809,9 +822,12 @@ class GitDownloadStrategy < VCSDownloadStrategy
|
|||||||
# copied to a new location. (This bug was introduced in Git 2.7.0 and fixed
|
# copied to a new location. (This bug was introduced in Git 2.7.0 and fixed
|
||||||
# in 2.8.3. Clones created with affected version remain broken.)
|
# in 2.8.3. Clones created with affected version remain broken.)
|
||||||
# See https://github.com/Homebrew/homebrew-core/pull/1520 for an example.
|
# See https://github.com/Homebrew/homebrew-core/pull/1520 for an example.
|
||||||
submodule_dirs = Utils.popen_read(
|
def fix_absolute_submodule_gitdir_references!
|
||||||
"git", "submodule", "--quiet", "foreach", "--recursive", "pwd"
|
submodule_dirs = system_command!("git",
|
||||||
)
|
args: ["submodule", "--quiet", "foreach", "--recursive", "pwd"],
|
||||||
|
chdir: cached_location)
|
||||||
|
.stdout
|
||||||
|
|
||||||
submodule_dirs.lines.map(&:chomp).each do |submodule_dir|
|
submodule_dirs.lines.map(&:chomp).each do |submodule_dir|
|
||||||
work_dir = Pathname.new(submodule_dir)
|
work_dir = Pathname.new(submodule_dir)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user