Unverified Commit 947724b4 authored by Philip Taron's avatar Philip Taron Committed by GitHub
Browse files

fetchFromBitbucket: expand and add `fetchgit` backend (#448621)

parents 3aedc709 5654a122
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -882,7 +882,17 @@ This is used with Gitiles repositories. The arguments expected are similar to `f

## `fetchFromBitbucket` {#fetchfrombitbucket}

This is used with BitBucket repositories. The arguments expected are very similar to `fetchFromGitHub` above.
Used for repositories hosted on Bitbucket (`"bitbucket.org"`) owned by the Australian-based Atlassian Corporation. It requires an `owner` and `repo` argument which are both strings that reference the workspace ID and repository name hosted on Bitbucket cloud as well as either a `tag` or `rev` argument.

By default, `fetchFromBitbucket` will attempt to download a commit snapshot tarball at the specified `tag` or `rev` at `https://bitbucket.org/<owner>/<repo>/get/<tag-or-rev>.tar.gz`

However, `fetchFromBitbucket` will automatically switch to using `fetchgit` and fetch from `https://bitbucket.org/<owner>/<repo>.git` in any of these cases:

- `forceFetchGit`, `leaveDotGit`, `deepClone`, `fetchLFS`, or `fetchSubmodules` are set to `true`
- `sparseCheckout` contains any entries (is a non-empty list)
- `rootDir` is set to a non-empty string

When `fetchgit` is used, refer to the `fetchgit` section for documentation of its available options.

## `fetchFromSavannah` {#fetchfromsavannah}

+3 −1
Original line number Diff line number Diff line
@@ -144,7 +144,9 @@

- `tooling-language-server` has been renamed to `deputy` (both the package and binary), following the rename of the upstream project.

- `fetchtorrent`, when using the "rqbit" backend, erroneously started fetching files into a subdirectory in Nixpkgs 24.11. The original behaviour -- which matches the behaviour using the "transmission" backend -- has now been restored. Users reliant on the erroneous behaviour can temporarily maintain it by adding `flatten = false` to the `fetchtorrent` arguments; Nix will produce an evaluation warning for anyone using `backend = "rqbit"` without `flatten = true`.
- `fetchFromBitBucket` has gained a `fetchgit` backend when passing in git-related arguments similar to `fetchFromGitHub`.

- `fetchtorrent`, when using the "rqbit" backend, erroneously started fetching files into a subdirectory in Nixpkgs 24.11.  The original behaviour &ndash; which matches the behaviour using the "transmission" backend &ndash; has now been restored.  Users reliant on the erroneous behaviour can temporarily maintain it by adding `flatten = false` to the `fetchtorrent` arguments; Nix will produce an evaluation warning for anyone using `backend = "rqbit"` without `flatten = true`.

- `steamcontroller` has been removed due to lack of upstream maintenance. Consider using `sc-controller` instead.

+93 −12
Original line number Diff line number Diff line
{
  lib,
  repoRevToNameMaybe,
  fetchgit,
  fetchzip,
}:

@@ -8,23 +9,103 @@ lib.makeOverridable (
  {
    owner,
    repo,
    rev,
    name ? repoRevToNameMaybe repo rev "bitbucket",
    tag ? null,
    rev ? null,
    name ? repoRevToNameMaybe repo (lib.revOrTag rev tag) "bitbucket",
    fetchSubmodules ? false,
    leaveDotGit ? false,
    deepClone ? false,
    forceFetchGit ? false,
    fetchLFS ? false,
    rootDir ? "",
    sparseCheckout ? lib.optional (rootDir != "") rootDir,
    meta ? { },
    ... # For hash agility
  }@args:
  fetchzip (
    {
      inherit name;
      url = "https://bitbucket.org/${owner}/${repo}/get/${lib.strings.escapeURL rev}.tar.gz";
      meta.homepage = "https://bitbucket.org/${owner}/${repo}/";

  assert (
    lib.assertMsg (lib.xor (tag == null) (
      rev == null
    )) "fetchFromBitbucket requires one of either `rev` or `tag` to be provided (not both)."
  );

  let
    position = (
      if args.meta.description or null != null then
        builtins.unsafeGetAttrPos "description" args.meta
      else if tag != null then
        builtins.unsafeGetAttrPos "tag" args
      else
        builtins.unsafeGetAttrPos "rev" args
    );
    baseUrl = "https://bitbucket.org/${owner}/${repo}";
    newMeta =
      meta
      // {
        homepage = meta.homepage or baseUrl;
      }
    // removeAttrs args [
      // lib.optionalAttrs (position != null) {
        # to indicate where derivation originates, similar to make-derivation.nix's mkDerivation
        position = "${position.file}:${toString position.line}";
      };
    gitRepoUrl = "${baseUrl}.git";

    # the tag is escaped to support mercurial-based tags as bitbucket supports them
    revWithTag = if tag != null then "refs/tags/${lib.strings.escapeURL tag}" else rev;

    passthruAttrs = removeAttrs args [
      "owner"
      "repo"
      "rev"
    ]
      "tag"
      "fetchSubmodules"
      "forceFetchGit"
    ];

    useFetchGit =
      fetchSubmodules
      || (leaveDotGit == true)
      || deepClone
      || forceFetchGit
      || fetchLFS
      || (rootDir != "")
      || (sparseCheckout != [ ]);

    fetcher = if useFetchGit then fetchgit else fetchzip;

    fetcherArgs =
      (
        if useFetchGit then
          {
            inherit
              rev
              tag
              deepClone
              fetchSubmodules
              sparseCheckout
              fetchLFS
              ;
            url = gitRepoUrl;
          }
          // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; }
        else
          {
            url = "https://bitbucket.org/${owner}/${repo}/get/${revWithTag}.tar.gz";
            extension = "tar.gz";
            passthru = {
              inherit gitRepoUrl;
            };
          }
      )
      // passthruAttrs
      // {
        inherit name;
      };
  in
  fetcher fetcherArgs
  // {
    inherit rev;
    meta = newMeta;
    inherit owner repo tag;
    rev = revWithTag;
  }
)
+11 −2
Original line number Diff line number Diff line
@@ -4,15 +4,24 @@
    name = "withWhitespace";
    owner = "tetov";
    repo = "fetchbitbucket_tester";
    rev = "tag%20with%20encoded%20spaces";
    tag = "tag%20with%20encoded%20spaces";
    sha256 = "sha256-Nf1Cvbx7Sbab8EeSSBU5baLBiuFYiQtITED+f4tfjC0=";
  };

  withEncodedWhitespaceGit = testers.invalidateFetcherByDrvHash fetchFromBitbucket {
    name = "withWhitespaceGit";
    owner = "tetov";
    repo = "fetchbitbucket_tester";
    tag = "tag%20with%20encoded%20spaces";
    sha256 = "sha256-Nf1Cvbx7Sbab8EeSSBU5baLBiuFYiQtITED+f4tfjC0=";
    forceFetchGit = true;
  };

  withoutWhitespace = testers.invalidateFetcherByDrvHash fetchFromBitbucket {
    name = "withoutWhitespace";
    owner = "tetov";
    repo = "fetchbitbucket_tester";
    rev = "main";
    rev = "6b611eb75c7b3bf04b510dfc1268284039d55542";
    sha256 = "sha256-eTd773gE1z4+Fl2YPBbbsrADD4Dr7sFGoOWgphXUhtE=";
  };
}