Skip to content

Commit

Permalink
Merge pull request #74 from stuebinm/nix-prefetch-git-names
Browse files Browse the repository at this point in the history
builtins.fetchGit: use same name as nix-prefetch-git
  • Loading branch information
andir authored May 11, 2024
2 parents 7b72204 + 24ec372 commit d640c29
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions npins/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let
revision,
url ? null,
hash,
branch ? null,
...
}:
assert repository ? type;
Expand All @@ -39,9 +40,23 @@ let
})
else
assert repository.type == "Git";
let
urlToName =
url: rev:
let
matched = builtins.match "^.*/([^/]*)(\\.git)?$" repository.url;

short = builtins.substring 0 7 rev;

appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
in
"${if matched == null then "source" else builtins.head matched}${appendShort}";
name = urlToName repository.url revision;
in
builtins.fetchGit {
url = repository.url;
rev = revision;
inherit name;
# hash = hash;
};

Expand Down
27 changes: 27 additions & 0 deletions test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ let
nix
gitMinimal
jq
nix-prefetch-git
];
}
''
Expand Down Expand Up @@ -210,4 +211,30 @@ in
[[ "$V" = "v0.2" ]]
'';
};

nixPrefetch =
let
mkPrefetchGitTest =
name: npinsArgs:
mkGitTest {
name = "nix-prefetch-git-${name}";
inherit gitRepo;
commands = ''
npins init --bare
npins add git http://localhost:8000/foo ${npinsArgs}
before=$(ls /build)
nix-instantiate --eval npins -A foo.outPath.outPath
after=$(ls /build)
cat npins/sources.json
[[ "$before" = "$after" ]]
'';
};
in
{
branch = mkPrefetchGitTest "branch" "--branch test-branch";
tag = mkPrefetchGitTest "tag" "--at v0.2";
hash = mkPrefetchGitTest "hash" "--branch test-branch --at 9ba40d123c3e6adb35c99ad04fd9de6bcdc1c9d5";
};
}

0 comments on commit d640c29

Please sign in to comment.