diff --git a/lix/libfetchers/mercurial.cc b/lix/libfetchers/mercurial.cc index eda49f93c..f99191566 100644 --- a/lix/libfetchers/mercurial.cc +++ b/lix/libfetchers/mercurial.cc @@ -204,6 +204,12 @@ struct MercurialInputScheme : InputScheme return {std::move(storePath), input}; } + + auto tokens = tokenizeString>( + runHg({ "identify", "-R", actualUrl, "-r", ".", "--template", "{branch} {node}" })); + assert(tokens.size() == 2); + input.attrs.insert_or_assign("ref", tokens[0]); + input.attrs.insert_or_assign("rev", tokens[1]); } if (!input.getRef()) input.attrs.insert_or_assign("ref", "default"); diff --git a/tests/functional/fetchMercurial.sh b/tests/functional/fetchMercurial.sh index 624705e9b..001e3ae00 100644 --- a/tests/functional/fetchMercurial.sh +++ b/tests/functional/fetchMercurial.sh @@ -33,11 +33,11 @@ path=$(nix eval --impure --raw --expr "(builtins.fetchMercurial \"file://$repo\" [[ $(cat $path/hello) = unclean ]] hg revert --cwd $repo --all -# Fetch the default branch. +# Fetch the currently checked out revision. path=$(nix eval --impure --raw --expr "(builtins.fetchMercurial \"file://$repo\").outPath") [[ $(cat $path/hello) = world ]] -# In pure eval mode, fetchGit without a revision should fail. +# In pure eval mode, fetchMercurial without a revision should fail. [[ $(nix eval --impure --raw --expr "(builtins.readFile (fetchMercurial \"file://$repo\" + \"/hello\"))") = world ]] (! nix eval --raw --expr "builtins.readFile (fetchMercurial \"file://$repo\" + \"/hello\")") @@ -45,7 +45,7 @@ path=$(nix eval --impure --raw --expr "(builtins.fetchMercurial \"file://$repo\" path2=$(nix eval --impure --raw --expr "(builtins.fetchMercurial { url = \"file://$repo\"; rev = \"$rev2\"; }).outPath") [[ $path = $path2 ]] -# In pure eval mode, fetchGit with a revision should succeed. +# In pure eval mode, fetchMercurial with a revision should succeed. [[ $(nix eval --raw --expr "builtins.readFile (fetchMercurial { url = \"file://$repo\"; rev = \"$rev2\"; } + \"/hello\")") = world ]] # Fetch again. This should be cached. @@ -104,3 +104,14 @@ echo paris > $repo/hello # Passing a `name` argument should be reflected in the output path path5=$(nix eval -vvvvv --impure --refresh --raw --expr "(builtins.fetchMercurial { url = \"file://$repo\"; name = \"foo\"; } ).outPath") [[ $path5 =~ -foo$ ]] + +# Fetch the currently checked out revision on a non-default branch. +hg branch --cwd $repo meow +hg commit --cwd $repo -m 'Bla4' +[[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial \"file://$repo\").branch") = meow ]] +[[ $(nix eval --impure --expr "(builtins.fetchMercurial \"file://$repo\").revCount") = 4 ]] + +# Fetch an older revision currently checked out. +hg update --cwd $repo 2 +[[ $(nix eval --impure --raw --expr "(builtins.fetchMercurial \"file://$repo\").branch") = default ]] +[[ $(nix eval --impure --expr "(builtins.fetchMercurial \"file://$repo\").revCount") = 3 ]]