Skip to content
Permalink
Browse files

Actually update git specs

  • Loading branch information
nmattia committed Dec 1, 2019
1 parent 4fbbbf2 commit 3377472122546eec6dcaefb519e86eec94ce7ade
Showing with 32 additions and 4 deletions.
  1. +12 −2 src/Niv/Cli.hs
  2. +20 −2 tests/git/default.nix
@@ -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'
@@ -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

0 comments on commit 3377472

Please sign in to comment.
You can’t perform that action at this time.