Skip to content
Snippets Groups Projects
Unverified Commit 2bdf3deb authored by Mike McQuaid's avatar Mike McQuaid
Browse files

Reduce shallow clone usage

GitHub has requested we request our usage of shallow clones. As a
result:

- do default to shallow clones on CI
- do not do --shallow-since when setting up new repositories in
  `brew update`
- do not support shallow clones of homebrew-core at all

We may consider in future unshallowing all clones unconditionally.
parent 0c7a7188
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ module Homebrew ...@@ -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 ...@@ -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
......
...@@ -37,8 +37,7 @@ git_init_if_necessary() { ...@@ -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() { ...@@ -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 ...@@ -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 ...@@ -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"
......
...@@ -620,7 +620,10 @@ class CoreTap < Tap ...@@ -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."
......
...@@ -556,7 +556,7 @@ assumptions, so taps can be cloned from places other than GitHub and ...@@ -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`:
......
...@@ -786,7 +786,7 @@ With \fIURL\fR specified, tap a formula repository from anywhere, using any tran ...@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment