libfetchers/mercurial: default to current revision on local repos
When using the Mercurial fetcher on a local repository without explicitly specifying a branch or revision, previously always the tip of the default branch would be fetched. This is likely unexpected by the user, and inconsistent with the Git fetcher as well as the dirty case. To reduce surprises and restore consistency, fetch the currently checked out revision instead. Change-Id: Id6d58f958b710f7a9661dc66ad4ddcb8d06a0cdd
This commit is contained in:
@@ -204,6 +204,12 @@ struct MercurialInputScheme : InputScheme
|
||||
|
||||
return {std::move(storePath), input};
|
||||
}
|
||||
|
||||
auto tokens = tokenizeString<std::vector<std::string>>(
|
||||
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");
|
||||
|
||||
@@ -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 ]]
|
||||
|
||||
Reference in New Issue
Block a user