Avoid treating uv add -r as --raw-sources (#6287)

## Summary

I suspect this was added because there's no way for users to pass (e.g.)
`--tag`, so the references are ambiguous. I think it's better to write
them as `rev` than to fail, though. It's just less efficient when we
fetch.

Closes https://github.com/astral-sh/uv/issues/6276.

Closes https://github.com/astral-sh/uv/issues/6275.
This commit is contained in:
Charlie Marsh 2024-08-21 12:28:02 -04:00 committed by GitHub
parent d8095b1fb8
commit 70dba6f954
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 49 additions and 80 deletions

View file

@ -351,31 +351,32 @@ impl Source {
subdirectory,
..
} => {
// We can only resolve a full commit hash from a pep508 URL, everything else is ambiguous.
let rev = match reference {
GitReference::FullCommit(ref mut rev) => Some(mem::take(rev)),
_ => None,
}
// Give precedence to an explicit argument.
.or(rev);
// Error if the user tried to specify a reference but didn't disambiguate.
if reference != GitReference::DefaultBranch
&& rev.is_none()
&& tag.is_none()
&& branch.is_none()
{
return Err(SourceError::UnresolvedReference(
reference.as_str().unwrap().to_owned(),
));
}
Source::Git {
rev,
tag,
branch,
git: repository,
subdirectory: subdirectory.map(|path| path.to_string_lossy().into_owned()),
if rev.is_none() && tag.is_none() && branch.is_none() {
let rev = match reference {
GitReference::FullCommit(ref mut rev) => Some(mem::take(rev)),
GitReference::Branch(ref mut rev) => Some(mem::take(rev)),
GitReference::Tag(ref mut rev) => Some(mem::take(rev)),
GitReference::ShortCommit(ref mut rev) => Some(mem::take(rev)),
GitReference::BranchOrTag(ref mut rev) => Some(mem::take(rev)),
GitReference::BranchOrTagOrCommit(ref mut rev) => Some(mem::take(rev)),
GitReference::NamedRef(ref mut rev) => Some(mem::take(rev)),
GitReference::DefaultBranch => None,
};
Source::Git {
rev,
tag,
branch,
git: repository,
subdirectory: subdirectory.map(|path| path.to_string_lossy().into_owned()),
}
} else {
Source::Git {
rev,
tag,
branch,
git: repository,
subdirectory: subdirectory.map(|path| path.to_string_lossy().into_owned()),
}
}
}
};