Skip to content

Commit c7b408f

Browse files
authored
fetch{gitlab,gitiles}: add tag argument (#367322)
2 parents ce1a731 + e64344c commit c7b408f

File tree

2 files changed

+115
-36
lines changed

2 files changed

+115
-36
lines changed

pkgs/build-support/fetchgitiles/default.nix

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,36 @@
33
lib.makeOverridable (
44
{
55
url,
6-
rev,
6+
rev ? null,
7+
tag ? null,
78
name ? "source",
89
...
910
}@args:
1011

12+
assert (
13+
lib.assertMsg (lib.xor (tag == null) (
14+
rev == null
15+
)) "fetchFromGitiles requires one of either `rev` or `tag` to be provided (not both)."
16+
);
17+
18+
let
19+
realrev = (if tag != null then "refs/tags/" + tag else rev);
20+
in
21+
1122
fetchzip (
1223
{
1324
inherit name;
14-
url = "${url}/+archive/${rev}.tar.gz";
25+
url = "${url}/+archive/${realrev}.tar.gz";
1526
stripRoot = false;
1627
meta.homepage = url;
1728
}
1829
// removeAttrs args [
1930
"url"
31+
"tag"
2032
"rev"
2133
]
2234
)
2335
// {
24-
inherit rev;
36+
inherit rev tag;
2537
}
2638
)
Lines changed: 100 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,103 @@
1-
{ lib, fetchgit, fetchzip }:
1+
{
2+
lib,
3+
fetchgit,
4+
fetchzip,
5+
}:
26

37
lib.makeOverridable (
4-
# gitlab example
5-
{ owner, repo, rev, protocol ? "https", domain ? "gitlab.com", name ? "source", group ? null
6-
, fetchSubmodules ? false, leaveDotGit ? false
7-
, deepClone ? false, forceFetchGit ? false
8-
, sparseCheckout ? []
9-
, ... # For hash agility
10-
} @ args:
11-
12-
let
13-
slug = lib.concatStringsSep "/" ((lib.optional (group != null) group) ++ [ owner repo ]);
14-
escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug;
15-
escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] rev;
16-
passthruAttrs = removeAttrs args [ "protocol" "domain" "owner" "group" "repo" "rev" "fetchSubmodules" "forceFetchGit" "leaveDotGit" "deepClone" ];
17-
18-
useFetchGit = fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || (sparseCheckout != []);
19-
fetcher = if useFetchGit then fetchgit else fetchzip;
20-
21-
gitRepoUrl = "${protocol}://${domain}/${slug}.git";
22-
23-
fetcherArgs = (if useFetchGit then {
24-
inherit rev deepClone fetchSubmodules sparseCheckout leaveDotGit;
25-
url = gitRepoUrl;
26-
} else {
27-
url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}";
28-
29-
passthru = {
30-
inherit gitRepoUrl;
31-
};
32-
}) // passthruAttrs // { inherit name; };
33-
in
34-
35-
fetcher fetcherArgs // { meta.homepage = "${protocol}://${domain}/${slug}/"; inherit rev owner repo; }
8+
# gitlab example
9+
{
10+
owner,
11+
repo,
12+
rev ? null,
13+
tag ? null,
14+
protocol ? "https",
15+
domain ? "gitlab.com",
16+
name ? "source",
17+
group ? null,
18+
fetchSubmodules ? false,
19+
leaveDotGit ? false,
20+
deepClone ? false,
21+
forceFetchGit ? false,
22+
sparseCheckout ? [ ],
23+
... # For hash agility
24+
}@args:
25+
26+
assert (
27+
lib.assertMsg (lib.xor (tag == null) (
28+
rev == null
29+
)) "fetchFromGitLab requires one of either `rev` or `tag` to be provided (not both)."
30+
);
31+
32+
let
33+
slug = lib.concatStringsSep "/" (
34+
(lib.optional (group != null) group)
35+
++ [
36+
owner
37+
repo
38+
]
39+
);
40+
escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug;
41+
escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] (
42+
if tag != null then "refs/tags/" + tag else rev
43+
);
44+
passthruAttrs = removeAttrs args [
45+
"protocol"
46+
"domain"
47+
"owner"
48+
"group"
49+
"repo"
50+
"rev"
51+
"tag"
52+
"fetchSubmodules"
53+
"forceFetchGit"
54+
"leaveDotGit"
55+
"deepClone"
56+
];
57+
58+
useFetchGit =
59+
fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || (sparseCheckout != [ ]);
60+
fetcher = if useFetchGit then fetchgit else fetchzip;
61+
62+
gitRepoUrl = "${protocol}://${domain}/${slug}.git";
63+
64+
fetcherArgs =
65+
(
66+
if useFetchGit then
67+
{
68+
inherit
69+
rev
70+
deepClone
71+
tag
72+
fetchSubmodules
73+
sparseCheckout
74+
leaveDotGit
75+
;
76+
url = gitRepoUrl;
77+
}
78+
else
79+
{
80+
url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}";
81+
82+
passthru = {
83+
inherit gitRepoUrl;
84+
};
85+
}
86+
)
87+
// passthruAttrs
88+
// {
89+
inherit name;
90+
};
91+
in
92+
93+
fetcher fetcherArgs
94+
// {
95+
meta.homepage = "${protocol}://${domain}/${slug}/";
96+
inherit
97+
tag
98+
rev
99+
owner
100+
repo
101+
;
102+
}
36103
)

0 commit comments

Comments
 (0)