Skip to content

Commit ed9968c

Browse files
9999yearsalt-romes
authored andcommitted
Do not use shallow clones for short revisions
When the `tag` of a `source-repository-stanza` is not a full hash, we cannot do a shallow clone and fetch it separately. Therefore, in those cases, we fall back to doing a full clone. Fixes #10605 Includes a regression test by @9999years. Co-authored-by: Rebecca Turner <[email protected]>
1 parent ae3f4d9 commit ed9968c

File tree

6 files changed

+62
-2
lines changed

6 files changed

+62
-2
lines changed

cabal-install/src/Distribution/Client/VCS.hs

+30-2
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,10 @@ vcsGit =
549549
-- If we want a particular branch or tag, fetch it.
550550
ref <- case srpBranch `mplus` srpTag of
551551
Nothing -> pure "HEAD"
552-
Just ref -> do
552+
-- `doShallow` controls whether we use a shallow clone.
553+
-- If the clone is shallow, make sure to fetch specified revisions
554+
-- before using them.
555+
Just ref | doShallow -> do
553556
-- /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\
554557
-- /!\ MULTIPLE HOURS HAVE BEEN LOST HERE!! /!\
555558
-- /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\
@@ -582,6 +585,9 @@ vcsGit =
582585
-- for now. Option 1 is possible but seems to have little benefit.
583586
git localDir ("fetch" : verboseArg ++ ["origin", ref])
584587
pure "FETCH_HEAD"
588+
Just ref
589+
| otherwise ->
590+
pure ref
585591

586592
-- Then, reset to the appropriate ref.
587593
git localDir $
@@ -608,8 +614,30 @@ vcsGit =
608614
{ progInvokeCwd = Just cwd
609615
}
610616

617+
-- Beware: if the user supplied revision for the source repository
618+
-- package is /not/ a full hash, then we cannot fetch it, which means
619+
-- we cannot do a shallow clone (--depth=1).
620+
-- See #10605.
621+
doShallow
622+
| Nothing <- srpTag =
623+
-- No tag, OK for shallow
624+
True
625+
-- full hashes are exactly 40 characters
626+
| Just tg <- srpTag
627+
, length tg == 40
628+
, all (`elem` (['0' .. '9'] ++ ['a' .. 'f'] ++ ['A' .. 'F'])) tg =
629+
True
630+
| otherwise =
631+
False
632+
633+
depthIs1
634+
| doShallow = ["--depth=1"]
635+
| otherwise = []
636+
611637
cloneArgs =
612-
["clone", "--depth=1", "--no-checkout", loc, localDir]
638+
["clone"]
639+
++ depthIs1
640+
++ [ "--no-checkout", loc, localDir]
613641
++ case peer of
614642
Nothing -> []
615643
Just peerLocalDir -> ["--reference", peerLocalDir]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# cabal v2-build
2+
Configuration is affected by the following files:
3+
- cabal.project
4+
Resolving dependencies...
5+
Build profile: -w ghc-<GHCVER> -O1
6+
In order, the following will be built:
7+
- puppy-1.0 (lib) (first run)
8+
Configuring library for puppy-1.0...
9+
Preprocessing library for puppy-1.0...
10+
Building library for puppy-1.0...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
packages: .
2+
3+
-- Regression for https://github.com/haskell/cabal/issues/10605
4+
-- This is `my-lib` 0.9.
5+
source-repository-package
6+
type: git
7+
location: https://github.com/9999years/cabal-testsuite-my-lib.git
8+
tag: 9a0af0aa
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest $ do
4+
cabal "v2-build" []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cabal-version: 3.0
2+
name: puppy
3+
version: 1.0
4+
5+
library
6+
default-language: Haskell2010
7+
hs-source-dirs: src
8+
build-depends: base
9+
exposed-modules: Puppy
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module Puppy () where

0 commit comments

Comments
 (0)