fetchFromGitHub: fix fetchSubmodules=true when revision is not hexadecimal
This commit is contained in:
parent
c73f0caea5
commit
535a6c3520
@ -1,21 +1,9 @@
|
||||
{stdenv, git, cacert}: let
|
||||
urlToName = url: rev: let
|
||||
inherit (stdenv.lib) removeSuffix splitString last;
|
||||
base = last (splitString ":" (baseNameOf (removeSuffix "/" url)));
|
||||
{stdenv, git, cacert, gitRepoToName}:
|
||||
|
||||
matched = builtins.match "(.*).git" base;
|
||||
|
||||
short = builtins.substring 0 7 rev;
|
||||
|
||||
appendShort = if (builtins.match "[a-f0-9]*" rev) != null
|
||||
then "-${short}"
|
||||
else "";
|
||||
in "${if matched == null then base else builtins.head matched}${appendShort}";
|
||||
in
|
||||
{ url, rev ? "HEAD", md5 ? "", sha256 ? "", leaveDotGit ? deepClone
|
||||
, fetchSubmodules ? true, deepClone ? false
|
||||
, branchName ? null
|
||||
, name ? urlToName url rev
|
||||
, name ? gitRepoToName url rev
|
||||
, # Shell code executed after the file has been fetched
|
||||
# successfully. This can do things like check or transform the file.
|
||||
postFetch ? ""
|
||||
|
14
pkgs/build-support/fetchgit/gitrepotoname.nix
Normal file
14
pkgs/build-support/fetchgit/gitrepotoname.nix
Normal file
@ -0,0 +1,14 @@
|
||||
{ lib }:
|
||||
|
||||
urlOrRepo: rev: let
|
||||
inherit (lib) removeSuffix splitString last;
|
||||
base = last (splitString ":" (baseNameOf (removeSuffix "/" urlOrRepo)));
|
||||
|
||||
matched = builtins.match "(.*).git" base;
|
||||
|
||||
short = builtins.substring 0 7 rev;
|
||||
|
||||
appendShort = if (builtins.match "[a-f0-9]*" rev) != null
|
||||
then "-${short}"
|
||||
else "";
|
||||
in "${if matched == null then base else builtins.head matched}${appendShort}"
|
@ -282,8 +282,8 @@ _clone_user_rev() {
|
||||
if test -z "$(echo "$rev" | tr -d 0123456789abcdef)"; then
|
||||
clone "$dir" "$url" "$rev" "" 1>&2
|
||||
else
|
||||
echo 1>&2 "Bad commit hash or bad reference."
|
||||
exit 1
|
||||
# if revision is not hexadecimal it might be a tag
|
||||
clone "$dir" "$url" "" "refs/tags/$rev" 1>&2
|
||||
fi;;
|
||||
esac
|
||||
|
||||
|
@ -185,8 +185,10 @@ with pkgs;
|
||||
|
||||
fetchzip = callPackage ../build-support/fetchzip { };
|
||||
|
||||
gitRepoToName = callPackage ../build-support/fetchgit/gitrepotoname.nix { };
|
||||
|
||||
fetchFromGitHub = {
|
||||
owner, repo, rev, name ? "${repo}-${rev}-src",
|
||||
owner, repo, rev, name ? gitRepoToName repo rev,
|
||||
fetchSubmodules ? false, private ? false,
|
||||
githubBase ? "github.com", varPrefix ? null,
|
||||
... # For hash agility
|
||||
@ -223,7 +225,7 @@ with pkgs;
|
||||
} // passthruAttrs) // { inherit rev; };
|
||||
|
||||
fetchFromBitbucket = {
|
||||
owner, repo, rev, name ? "${repo}-${rev}-src",
|
||||
owner, repo, rev, name ? gitRepoToName repo rev,
|
||||
... # For hash agility
|
||||
}@args: fetchzip ({
|
||||
inherit name;
|
||||
@ -234,7 +236,7 @@ with pkgs;
|
||||
|
||||
# cgit example, snapshot support is optional in cgit
|
||||
fetchFromSavannah = {
|
||||
repo, rev, name ? "${repo}-${rev}-src",
|
||||
repo, rev, name ? gitRepoToName repo rev,
|
||||
... # For hash agility
|
||||
}@args: fetchzip ({
|
||||
inherit name;
|
||||
@ -244,7 +246,7 @@ with pkgs;
|
||||
|
||||
# gitlab example
|
||||
fetchFromGitLab = {
|
||||
owner, repo, rev, name ? "${repo}-${rev}-src",
|
||||
owner, repo, rev, name ? gitRepoToName repo rev,
|
||||
... # For hash agility
|
||||
}@args: fetchzip ({
|
||||
inherit name;
|
||||
@ -254,7 +256,7 @@ with pkgs;
|
||||
|
||||
# gitweb example, snapshot support is optional in gitweb
|
||||
fetchFromRepoOrCz = {
|
||||
repo, rev, name ? "${repo}-${rev}-src",
|
||||
repo, rev, name ? gitRepoToName repo rev,
|
||||
... # For hash agility
|
||||
}@args: fetchzip ({
|
||||
inherit name;
|
||||
|
Loading…
Reference in New Issue
Block a user