Skip to content

Commit f3a5af4

Browse files
authored
nix/flake: fix Ref.String() for github flakes w/ rev and ref (#2467)
The string form of GitHub flakeref can only have a rev or a ref, not both. For example: - Good: `github:NixOS/nixpkgs/b321c8e818546d5491ee5611476500557b880856` - Good: `github:NixOS/nixpkgs/nixpkgs-unstable` - Bad: `github:NixOS/nixpkgs/nixpkgs-unstable/b321c8e818546d5491ee5611476500557b880856` If both the Rev and Ref fields are set, use Rev.
1 parent b02f1c6 commit f3a5af4

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Diff for: nix/flake/flakeref.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func (r Ref) String() string {
395395
}
396396
url := &url.URL{
397397
Scheme: "github",
398-
Opaque: buildEscapedPath(r.Owner, r.Repo, r.Rev, r.Ref),
398+
Opaque: buildEscapedPath(r.Owner, r.Repo, cmp.Or(r.Rev, r.Ref)),
399399
RawQuery: appendQueryString(nil,
400400
"host", r.Host,
401401
"dir", r.Dir,

Diff for: nix/flake/flakeref_test.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,14 @@ func TestFlakeRefString(t *testing.T) {
233233
{Type: TypeIndirect, ID: "indirect", Ref: "ref", Rev: "5233fd2ba76a3accb5aaa999c00509a11fd0793c"}: "flake:indirect/ref/5233fd2ba76a3accb5aaa999c00509a11fd0793c",
234234

235235
// GitHub references.
236-
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix"}: "github:NixOS/nix",
237-
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Ref: "v1.2.3"}: "github:NixOS/nix/v1.2.3",
238-
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Ref: "my/ref"}: "github:NixOS/nix/my%2Fref",
239-
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Ref: "5233fd2ba76a3accb5aaa999c00509a11fd0793c"}: "github:NixOS/nix/5233fd2ba76a3accb5aaa999c00509a11fd0793c",
240-
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Ref: "5233fd2bb76a3accb5aaa999c00509a11fd0793z"}: "github:NixOS/nix/5233fd2bb76a3accb5aaa999c00509a11fd0793z",
241-
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Dir: "sub/dir"}: "github:NixOS/nix?dir=sub%2Fdir",
242-
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Dir: "sub/dir", Host: "example.com"}: "github:NixOS/nix?dir=sub%2Fdir&host=example.com",
236+
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix"}: "github:NixOS/nix",
237+
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Ref: "v1.2.3"}: "github:NixOS/nix/v1.2.3",
238+
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Ref: "my/ref"}: "github:NixOS/nix/my%2Fref",
239+
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Ref: "5233fd2ba76a3accb5aaa999c00509a11fd0793c"}: "github:NixOS/nix/5233fd2ba76a3accb5aaa999c00509a11fd0793c",
240+
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Ref: "5233fd2bb76a3accb5aaa999c00509a11fd0793z"}: "github:NixOS/nix/5233fd2bb76a3accb5aaa999c00509a11fd0793z",
241+
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Rev: "5233fd2ba76a3accb5aaa999c00509a11fd0793c", Ref: "main"}: "github:NixOS/nix/5233fd2ba76a3accb5aaa999c00509a11fd0793c",
242+
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Dir: "sub/dir"}: "github:NixOS/nix?dir=sub%2Fdir",
243+
{Type: TypeGitHub, Owner: "NixOS", Repo: "nix", Dir: "sub/dir", Host: "example.com"}: "github:NixOS/nix?dir=sub%2Fdir&host=example.com",
243244

244245
// Git references.
245246
{Type: TypeGit, URL: "git://example.com/repo/flake"}: "git://example.com/repo/flake",

0 commit comments

Comments
 (0)