fetchgit: allow disabling cone mode for sparse checkouts, fix test

This commit is contained in:
Winter 2022-08-04 15:26:03 -04:00 committed by Rick van Schijndel
parent 989b7550e6
commit dbd18a63a7
7 changed files with 36 additions and 5 deletions

View File

@ -91,7 +91,7 @@ Used with Git. Expects `url` to a Git repo, `rev`, and `sha256`. `rev` in this c
Additionally, the following optional arguments can be given: `fetchSubmodules = true` makes `fetchgit` also fetch the submodules of a repository. If `deepClone` is set to true, the entire repository is cloned as opposing to just creating a shallow clone. `deepClone = true` also implies `leaveDotGit = true` which means that the `.git` directory of the clone won't be removed after checkout.
If only parts of the repository are needed, `sparseCheckout` can be used. This will prevent git from fetching unnecessary blobs from server, see [git sparse-checkout](https://git-scm.com/docs/git-sparse-checkout) and [git clone --filter](https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---filterltfilter-specgt) for more information:
If only parts of the repository are needed, `sparseCheckout` can be used. This will prevent git from fetching unnecessary blobs from server, see [git sparse-checkout](https://git-scm.com/docs/git-sparse-checkout) for more information:
```nix
{ stdenv, fetchgit }:
@ -101,8 +101,8 @@ stdenv.mkDerivation {
src = fetchgit {
url = "https://...";
sparseCheckout = ''
path/to/be/included
another/path
directory/to/be/included
another/directory
'';
sha256 = "0000000000000000000000000000000000000000000000000000";
};

View File

@ -251,6 +251,18 @@
<literal>(with foo; isPower &amp;&amp; is32bit &amp;&amp; isBigEndian)</literal>.
</para>
</listitem>
<listitem>
<para>
The <literal>fetchgit</literal> fetcher now uses
<link xlink:href="https://www.git-scm.com/docs/git-sparse-checkout/2.37.0#_internalscone_mode_handling">cone
mode</link> by default for sparse checkouts.
<link xlink:href="https://www.git-scm.com/docs/git-sparse-checkout/2.37.0#_internalsnon_cone_problems">Non-cone
mode</link> can be enabled by passing
<literal>nonConeMode = true</literal>, but note that non-cone
mode is deprecated and this option may be removed alongside a
future Git update without notice.
</para>
</listitem>
<listitem>
<para>
<literal>bsp-layout</literal> no longer uses the command

View File

@ -97,6 +97,8 @@ In addition to numerous new and upgraded packages, this release has the followin
- The `isPowerPC` predicate, found on `platform` attrsets (`hostPlatform`, `buildPlatform`, `targetPlatform`, etc) has been removed in order to reduce confusion. The predicate was was defined such that it matches only the 32-bit big-endian members of the POWER/PowerPC family, despite having a name which would imply a broader set of systems. If you were using this predicate, you can replace `foo.isPowerPC` with `(with foo; isPower && is32bit && isBigEndian)`.
- The `fetchgit` fetcher now uses [cone mode](https://www.git-scm.com/docs/git-sparse-checkout/2.37.0#_internalscone_mode_handling) by default for sparse checkouts. [Non-cone mode](https://www.git-scm.com/docs/git-sparse-checkout/2.37.0#_internalsnon_cone_problems) can be enabled by passing `nonConeMode = true`, but note that non-cone mode is deprecated and this option may be removed alongside a future Git update without notice.
- `bsp-layout` no longer uses the command `cycle` to switch to other window layouts, as it got replaced by the commands `previous` and `next`.
- The Barco ClickShare driver/client package `pkgs.clickshare-csc1` and the option `programs.clickshare-csc1.enable` have been removed,

View File

@ -12,6 +12,7 @@ $SHELL $fetcher --builder --url "$url" --out "$out" --rev "$rev" \
${deepClone:+--deepClone} \
${fetchSubmodules:+--fetch-submodules} \
${sparseCheckout:+--sparse-checkout "$sparseCheckout"} \
${nonConeMode:+--non-cone-mode} \
${branchName:+--branch-name "$branchName"}
runHook postFetch

View File

@ -16,6 +16,7 @@ in
, fetchSubmodules ? true, deepClone ? false
, branchName ? null
, sparseCheckout ? ""
, nonConeMode ? false
, name ? urlToName url rev
, # Shell code executed after the file has been fetched
# successfully. This can do things like check or transform the file.
@ -54,6 +55,7 @@ in
*/
assert deepClone -> leaveDotGit;
assert nonConeMode -> (sparseCheckout != "");
if md5 != "" then
throw "fetchgit does not support md5 anymore, please use sha256"
@ -77,7 +79,7 @@ stdenvNoCC.mkDerivation {
else
lib.fakeSha256;
inherit url rev leaveDotGit fetchLFS fetchSubmodules deepClone branchName sparseCheckout postFetch;
inherit url rev leaveDotGit fetchLFS fetchSubmodules deepClone branchName sparseCheckout nonConeMode postFetch;
postHook = if netrcPhase == null then null else ''
${netrcPhase}

View File

@ -49,6 +49,7 @@ Options:
--hash h Expected hash.
--branch-name Branch name to check out into
--sparse-checkout Only fetch and checkout part of the repository.
--non-cone-mode Use non-cone mode for sparse checkouts.
--deepClone Clone the entire repository.
--no-deepClone Make a shallow clone of just the required ref.
--leave-dotGit Keep the .git directories.
@ -77,6 +78,7 @@ for arg; do
--branch-name) argfun=set_branchName;;
--deepClone) deepClone=true;;
--sparse-checkout) argfun=set_sparseCheckout;;
--non-cone-mode) nonConeMode=true;;
--quiet) QUIET=true;;
--no-deepClone) deepClone=;;
--leave-dotGit) leaveDotGit=true;;
@ -116,7 +118,7 @@ init_remote(){
clean_git remote add origin "$url"
if [ -n "$sparseCheckout" ]; then
git config remote.origin.partialclonefilter "blob:none"
echo "$sparseCheckout" | git sparse-checkout set --stdin
echo "$sparseCheckout" | git sparse-checkout set --stdin ${nonConeMode:+--no-cone}
fi
( [ -n "$http_proxy" ] && clean_git config http.proxy "$http_proxy" ) || true
}

View File

@ -16,6 +16,18 @@
src
tests
'';
sha256 = "sha256-g1PHGTWgAcd/+sXHo1o6AjVWCvC6HiocOfMbMh873LQ=";
};
sparseCheckoutNonConeMode = testers.invalidateFetcherByDrvHash fetchgit {
name = "nix-source";
url = "https://github.com/NixOS/nix";
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
sparseCheckout = ''
src
tests
'';
nonConeMode = true;
sha256 = "sha256-FknO6C/PSnMPfhUqObD4vsW4PhkwdmPa9blNzcNvJQ4=";
};
}