Merge pull request #8883 from MikeMcQuaid/no-shallow

Reduce shallow clone usage
This commit is contained in:
Mike McQuaid 2020-10-09 10:35:19 +01:00 committed by GitHub
commit cfd4870247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 15 deletions

View File

@ -26,7 +26,7 @@ module Homebrew
EOS EOS
switch "--full", switch "--full",
description: "Convert a shallow clone to a full clone without untapping. Taps are only cloned as "\ description: "Convert a shallow clone to a full clone without untapping. Taps are only cloned as "\
"shallow clones on continuous integration, or if `--shallow` was originally passed." "shallow clones if `--shallow` was originally passed."
switch "--shallow", switch "--shallow",
description: "Fetch tap as a shallow clone rather than a full clone. Useful for continuous integration." description: "Fetch tap as a shallow clone rather than a full clone. Useful for continuous integration."
switch "--force-auto-update", switch "--force-auto-update",
@ -53,8 +53,6 @@ module Homebrew
else else
full_clone = if args.full? full_clone = if args.full?
true true
elsif !args.shallow?
ENV["CI"].blank?
else else
!args.shallow? !args.shallow?
end end

View File

@ -37,8 +37,7 @@ git_init_if_necessary() {
fi fi
git config remote.origin.url "$HOMEBREW_BREW_GIT_REMOTE" git config remote.origin.url "$HOMEBREW_BREW_GIT_REMOTE"
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
latest_tag="$(git ls-remote --tags --refs -q origin | tail -n1 | cut -f2)" git fetch --force --tags origin
git fetch --force origin --shallow-since="$latest_tag"
git remote set-head origin --auto >/dev/null git remote set-head origin --auto >/dev/null
git reset --hard origin/master git reset --hard origin/master
SKIP_FETCH_BREW_REPOSITORY=1 SKIP_FETCH_BREW_REPOSITORY=1
@ -60,7 +59,7 @@ git_init_if_necessary() {
fi fi
git config remote.origin.url "$HOMEBREW_CORE_GIT_REMOTE" git config remote.origin.url "$HOMEBREW_CORE_GIT_REMOTE"
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch --force --depth=1 origin refs/heads/master:refs/remotes/origin/master git fetch --force origin refs/heads/master:refs/remotes/origin/master
git remote set-head origin --auto >/dev/null git remote set-head origin --auto >/dev/null
git reset --hard origin/master git reset --hard origin/master
SKIP_FETCH_CORE_REPOSITORY=1 SKIP_FETCH_CORE_REPOSITORY=1
@ -428,12 +427,7 @@ EOS
echo "HOMEBREW_BREW_GIT_REMOTE set: using $HOMEBREW_BREW_GIT_REMOTE for Homebrew/brew Git remote." echo "HOMEBREW_BREW_GIT_REMOTE set: using $HOMEBREW_BREW_GIT_REMOTE for Homebrew/brew Git remote."
git remote set-url origin "$HOMEBREW_BREW_GIT_REMOTE" git remote set-url origin "$HOMEBREW_BREW_GIT_REMOTE"
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
latest_tag="$(git ls-remote --tags --refs -q origin | git fetch --force --tags origin
cut -d/ -f3 |
sort --numeric-sort --field-separator=. --key=1,1 --key=2,2 --key=3,3 |
tail -n1)"
latest_ref="refs/tags/$latest_tag"
git fetch --force origin --shallow-since="$latest_ref"
fi fi
if [[ "$HOMEBREW_CORE_DEFAULT_GIT_REMOTE" != "$HOMEBREW_CORE_GIT_REMOTE" ]] && if [[ "$HOMEBREW_CORE_DEFAULT_GIT_REMOTE" != "$HOMEBREW_CORE_GIT_REMOTE" ]] &&
@ -443,7 +437,7 @@ EOS
echo "HOMEBREW_CORE_GIT_REMOTE set: using $HOMEBREW_CORE_GIT_REMOTE for Homebrew/brew Git remote." echo "HOMEBREW_CORE_GIT_REMOTE set: using $HOMEBREW_CORE_GIT_REMOTE for Homebrew/brew Git remote."
git remote set-url origin "$HOMEBREW_CORE_GIT_REMOTE" git remote set-url origin "$HOMEBREW_CORE_GIT_REMOTE"
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch --force --depth=1 origin refs/heads/master:refs/remotes/origin/master git fetch --force origin refs/heads/master:refs/remotes/origin/master
fi fi
safe_cd "$HOMEBREW_REPOSITORY" safe_cd "$HOMEBREW_REPOSITORY"

View File

@ -620,7 +620,10 @@ class CoreTap < Tap
safe_system HOMEBREW_BREW_FILE, "tap", instance.name safe_system HOMEBREW_BREW_FILE, "tap", instance.name
end end
# CoreTap never allows shallow clones (on request from GitHub).
def install(full_clone: true, quiet: false, clone_target: nil, force_auto_update: nil) def install(full_clone: true, quiet: false, clone_target: nil, force_auto_update: nil)
raise "Shallow clones are not supported for homebrew-core!" unless full_clone
remote = Homebrew::EnvConfig.core_git_remote remote = Homebrew::EnvConfig.core_git_remote
if remote != default_remote if remote != default_remote
$stderr.puts "HOMEBREW_CORE_GIT_REMOTE set: using #{remote} for Homebrew/core Git remote URL." $stderr.puts "HOMEBREW_CORE_GIT_REMOTE set: using #{remote} for Homebrew/core Git remote URL."

View File

@ -556,7 +556,7 @@ assumptions, so taps can be cloned from places other than GitHub and
using protocols other than HTTPS, e.g. SSH, git, HTTP, FTP(S), rsync. using protocols other than HTTPS, e.g. SSH, git, HTTP, FTP(S), rsync.
* `--full`: * `--full`:
Convert a shallow clone to a full clone without untapping. Taps are only cloned as shallow clones on continuous integration, or if `--shallow` was originally passed. Convert a shallow clone to a full clone without untapping. Taps are only cloned as shallow clones if `--shallow` was originally passed.
* `--shallow`: * `--shallow`:
Fetch tap as a shallow clone rather than a full clone. Useful for continuous integration. Fetch tap as a shallow clone rather than a full clone. Useful for continuous integration.
* `--force-auto-update`: * `--force-auto-update`:

View File

@ -786,7 +786,7 @@ With \fIURL\fR specified, tap a formula repository from anywhere, using any tran
. .
.TP .TP
\fB\-\-full\fR \fB\-\-full\fR
Convert a shallow clone to a full clone without untapping\. Taps are only cloned as shallow clones on continuous integration, or if \fB\-\-shallow\fR was originally passed\. Convert a shallow clone to a full clone without untapping\. Taps are only cloned as shallow clones if \fB\-\-shallow\fR was originally passed\.
. .
.TP .TP
\fB\-\-shallow\fR \fB\-\-shallow\fR