1
1
mirror of https://github.com/nmattia/niv.git synced 2024-09-18 19:07:19 +03:00

Actually update git specs

This commit is contained in:
Nicolas Mattia 2019-12-01 12:41:31 +01:00
parent 4fbbbf28d4
commit 3377472122
2 changed files with 32 additions and 4 deletions

View File

@ -295,9 +295,14 @@ cmdUpdate = \case
eFinalSpec <- case HMS.lookup packageName sources of
Just defaultSpec -> do
-- lookup the "type" to find a Cmd to run, defaulting to legacy
-- github
let cmd = case HMS.lookup "type" (unPackageSpec defaultSpec) of
Just "git" -> gitCmd
_ -> githubCmd
fmap attrsToSpec <$> tryEvalUpdate
(specToLockedAttrs cliSpec <> specToFreeAttrs defaultSpec)
(updateCmd githubCmd)
(updateCmd cmd)
Nothing -> abortCannotUpdateNoSuchPackage packageName
@ -314,9 +319,14 @@ cmdUpdate = \case
\packageName defaultSpec -> do
tsay $ "Package: " <> unPackageName packageName
let initialSpec = specToFreeAttrs defaultSpec
-- lookup the "type" to find a Cmd to run, defaulting to legacy
-- github
let cmd = case HMS.lookup "type" (unPackageSpec defaultSpec) of
Just "git" -> gitCmd
_ -> githubCmd
finalSpec <- fmap attrsToSpec <$> tryEvalUpdate
initialSpec
(updateCmd githubCmd)
(updateCmd cmd)
pure finalSpec
let (failed, sources') = partitionEithersHMS esources'

View File

@ -2,10 +2,11 @@
# TODO: this doesn' test anything meaningful yet because "niv git PACKAGE"
# doesn't parse yet
pkgs.runCommand "foo"
pkgs.runCommand "git-test"
{ nativeBuildInputs = [ pkgs.git niv pkgs.nix pkgs.jq ]; }
(
# First we create a dummy git repo with a single commit
# First we create a dummy git repo with one commit on master, and one commit
# on "branch".
''
gitdir=$(mktemp -d)
pushd $gitdir > /dev/null
@ -16,6 +17,15 @@ pkgs.runCommand "foo"
git add file
git commit -m "Initial commit"
gitrev=$(git rev-parse HEAD)
git checkout -b branch
echo world >> file
git add file
git commit -m "second commit"
gitrev2=$(git rev-parse HEAD)
# reset to master as "default branch"
git checkout master
popd > /dev/null
'' +
@ -47,6 +57,14 @@ pkgs.runCommand "foo"
echo "Mismatched revCount: 1 != $nivnixrevcount"
exit 42
fi
niv update my-git-repo -a ref=branch
nivrev2=$(nix eval --json '(import ./nix/sources.nix).my-git-repo.rev' | jq -r)
if [ ! "$gitrev2" = "$nivrev2" ]; then
echo "Mismatched revs: $gitrev2 != $nivrev2"
exit 42
fi
popd > /dev/null
touch $out