Use system_command for GitDownloadStrategy.

This commit is contained in:
Markus Reiter 2018-08-03 11:13:12 +02:00
parent 28fd59672a
commit e220406a6e

View File

@ -690,13 +690,11 @@ 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?
@ -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",
checkout args: ["config", "homebrew.cacheversion", cache_version],
update_submodules if submodules? chdir: cached_location
end checkout
update_submodules if submodules?
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,30 +800,34 @@ 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
# When checking out Git repositories with recursive submodules, some Git
# versions create `.git` files with absolute instead of relative `gitdir:`
# pointers. This works for the cached location, but breaks various Git
# operations once the affected Git resource is staged, i.e. recursively
# 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.)
# See https://github.com/Homebrew/homebrew-core/pull/1520 for an example.
def fix_absolute_submodule_gitdir_references! def fix_absolute_submodule_gitdir_references!
# When checking out Git repositories with recursive submodules, some Git submodule_dirs = system_command!("git",
# versions create `.git` files with absolute instead of relative `gitdir:` args: ["submodule", "--quiet", "foreach", "--recursive", "pwd"],
# pointers. This works for the cached location, but breaks various Git chdir: cached_location)
# operations once the affected Git resource is staged, i.e. recursively .stdout
# 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.)
# See https://github.com/Homebrew/homebrew-core/pull/1520 for an example.
submodule_dirs = Utils.popen_read(
"git", "submodule", "--quiet", "foreach", "--recursive", "pwd"
)
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)