Respect Git tags and branches that look like short commits (#2795)

## Summary

If we're given a Git reference like `20240222`, we currently treat it as
a short commit hash. However... it _could_ be a branch or a tag. This PR
improves the Git reference logic to ensure that ambiguous references
like `20240222` are handled appropriately, by attempting to extract it
as a branch, then a tag, then a short commit hash.

Closes https://github.com/astral-sh/uv/issues/2772.
This commit is contained in:
Charlie Marsh 2024-04-03 22:05:54 -04:00 committed by GitHub
parent dc2c289dff
commit dd3009ad84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 205 additions and 261 deletions

View file

@ -25,20 +25,14 @@ const CHECKOUT_READY_LOCK: &str = ".ok";
/// A reference to commit or commit-ish. /// A reference to commit or commit-ish.
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GitReference { pub enum GitReference {
/// From a branch.
#[allow(unused)]
Branch(String),
/// From a tag.
#[allow(unused)]
Tag(String),
/// From a reference that's ambiguously a branch or tag. /// From a reference that's ambiguously a branch or tag.
BranchOrTag(String), BranchOrTag(String),
/// From a reference that's ambiguously a short commit, a branch, or a tag.
BranchOrTagOrCommit(String),
/// From a named reference, like `refs/pull/493/head`.
NamedRef(String),
/// From a specific revision, using a full 40-character commit hash. /// From a specific revision, using a full 40-character commit hash.
FullCommit(String), FullCommit(String),
/// From a truncated revision.
ShortCommit(String),
/// From a named reference, like `refs/pull/493/head`.
Ref(String),
/// The default branch of the repository, the reference named `HEAD`. /// The default branch of the repository, the reference named `HEAD`.
DefaultBranch, DefaultBranch,
} }
@ -52,37 +46,28 @@ enum RefspecStrategy {
} }
impl GitReference { impl GitReference {
/// Creates a [`GitReference`] from a revision string.
pub(crate) fn from_rev(rev: &str) -> Self { pub(crate) fn from_rev(rev: &str) -> Self {
if rev.starts_with("refs/") { if rev.starts_with("refs/") {
Self::Ref(rev.to_owned()) Self::NamedRef(rev.to_owned())
} else if looks_like_commit_hash(rev) { } else if looks_like_commit_hash(rev) {
if rev.len() == 40 { if rev.len() == 40 {
Self::FullCommit(rev.to_owned()) Self::FullCommit(rev.to_owned())
} else { } else {
Self::ShortCommit(rev.to_owned()) Self::BranchOrTagOrCommit(rev.to_owned())
} }
} else { } else {
Self::BranchOrTag(rev.to_owned()) Self::BranchOrTag(rev.to_owned())
} }
} }
pub fn precise(&self) -> Option<&str> {
match self {
Self::FullCommit(rev) => Some(rev),
Self::ShortCommit(rev) => Some(rev),
_ => None,
}
}
/// Converts the [`GitReference`] to a `str`. /// Converts the [`GitReference`] to a `str`.
pub fn as_str(&self) -> Option<&str> { pub fn as_str(&self) -> Option<&str> {
match self { match self {
Self::Branch(rev) => Some(rev),
Self::Tag(rev) => Some(rev),
Self::BranchOrTag(rev) => Some(rev), Self::BranchOrTag(rev) => Some(rev),
Self::FullCommit(rev) => Some(rev), Self::FullCommit(rev) => Some(rev),
Self::ShortCommit(rev) => Some(rev), Self::BranchOrTagOrCommit(rev) => Some(rev),
Self::Ref(rev) => Some(rev), Self::NamedRef(rev) => Some(rev),
Self::DefaultBranch => None, Self::DefaultBranch => None,
} }
} }
@ -90,12 +75,10 @@ impl GitReference {
/// Converts the [`GitReference`] to a `str` that can be used as a revision. /// Converts the [`GitReference`] to a `str` that can be used as a revision.
pub(crate) fn as_rev(&self) -> &str { pub(crate) fn as_rev(&self) -> &str {
match self { match self {
Self::Branch(rev) Self::BranchOrTag(rev)
| Self::Tag(rev)
| Self::BranchOrTag(rev)
| Self::FullCommit(rev) | Self::FullCommit(rev)
| Self::ShortCommit(rev) | Self::BranchOrTagOrCommit(rev)
| Self::Ref(rev) => rev, | Self::NamedRef(rev) => rev,
Self::DefaultBranch => "HEAD", Self::DefaultBranch => "HEAD",
} }
} }
@ -103,12 +86,10 @@ impl GitReference {
/// Returns the kind of this reference. /// Returns the kind of this reference.
pub(crate) fn kind_str(&self) -> &str { pub(crate) fn kind_str(&self) -> &str {
match self { match self {
Self::Branch(_) => "branch",
Self::Tag(_) => "tag",
Self::BranchOrTag(_) => "branch or tag", Self::BranchOrTag(_) => "branch or tag",
Self::FullCommit(_) => "commit", Self::FullCommit(_) => "commit",
Self::ShortCommit(_) => "short commit", Self::BranchOrTagOrCommit(_) => "branch, tag, or commit",
Self::Ref(_) => "ref", Self::NamedRef(_) => "ref",
Self::DefaultBranch => "default branch", Self::DefaultBranch => "default branch",
} }
} }
@ -281,37 +262,18 @@ impl GitReference {
pub(crate) fn resolve(&self, repo: &git2::Repository) -> Result<git2::Oid> { pub(crate) fn resolve(&self, repo: &git2::Repository) -> Result<git2::Oid> {
let refkind = self.kind_str(); let refkind = self.kind_str();
let id = match self { let id = match self {
// Note that we resolve the named tag here in sync with where it's
// fetched into via `fetch` below.
Self::Tag(s) => (|| -> Result<git2::Oid> {
let refname = format!("refs/remotes/origin/tags/{s}");
let id = repo.refname_to_id(&refname)?;
let obj = repo.find_object(id, None)?;
let obj = obj.peel(ObjectType::Commit)?;
Ok(obj.id())
})()
.with_context(|| format!("failed to find {refkind} `{s}`"))?,
// Resolve the remote name since that's all we're configuring in
// `fetch` below.
Self::Branch(s) => {
let name = format!("origin/{s}");
let b = repo
.find_branch(&name, git2::BranchType::Remote)
.with_context(|| format!("failed to find {refkind} `{s}`"))?;
b.get()
.target()
.ok_or_else(|| anyhow::format_err!("{refkind} `{s}` did not have a target"))?
}
// Attempt to resolve the branch, then the tag. // Attempt to resolve the branch, then the tag.
Self::BranchOrTag(s) => { Self::BranchOrTag(s) => {
let name = format!("origin/{s}"); let name = format!("origin/{s}");
// Resolve the remote name since that's all we're configuring in
// `fetch` below.
repo.find_branch(&name, git2::BranchType::Remote) repo.find_branch(&name, git2::BranchType::Remote)
.ok() .ok()
.and_then(|b| b.get().target()) .and_then(|b| b.get().target())
.or_else(|| { .or_else(|| {
// Note that we resolve the named tag here in sync with where it's
// fetched into via `fetch` below.
let refname = format!("refs/remotes/origin/tags/{s}"); let refname = format!("refs/remotes/origin/tags/{s}");
let id = repo.refname_to_id(&refname).ok()?; let id = repo.refname_to_id(&refname).ok()?;
let obj = repo.find_object(id, None).ok()?; let obj = repo.find_object(id, None).ok()?;
@ -321,6 +283,35 @@ impl GitReference {
.ok_or_else(|| anyhow::format_err!("failed to find {refkind} `{s}`"))? .ok_or_else(|| anyhow::format_err!("failed to find {refkind} `{s}`"))?
} }
// Attempt to resolve the branch, then the tag, then the commit.
Self::BranchOrTagOrCommit(s) => {
let name = format!("origin/{s}");
// Resolve the remote name since that's all we're configuring in
// `fetch` below.
repo.find_branch(&name, git2::BranchType::Remote)
.ok()
.and_then(|b| b.get().target())
.or_else(|| {
// Note that we resolve the named tag here in sync with where it's
// fetched into via `fetch` below.
let refname = format!("refs/remotes/origin/tags/{s}");
let id = repo.refname_to_id(&refname).ok()?;
let obj = repo.find_object(id, None).ok()?;
let obj = obj.peel(ObjectType::Commit).ok()?;
Some(obj.id())
})
.or_else(|| {
// Resolve the commit.
let obj = repo.revparse_single(s).ok()?;
match obj.as_tag() {
Some(tag) => Some(tag.target_id()),
None => Some(obj.id()),
}
})
.ok_or_else(|| anyhow::format_err!("failed to find {refkind} `{s}`"))?
}
// We'll be using the HEAD commit // We'll be using the HEAD commit
Self::DefaultBranch => { Self::DefaultBranch => {
let head_id = repo.refname_to_id("refs/remotes/origin/HEAD")?; let head_id = repo.refname_to_id("refs/remotes/origin/HEAD")?;
@ -328,7 +319,7 @@ impl GitReference {
head.peel(ObjectType::Commit)?.id() head.peel(ObjectType::Commit)?.id()
} }
Self::FullCommit(s) | Self::ShortCommit(s) | Self::Ref(s) => { Self::FullCommit(s) | Self::NamedRef(s) => {
let obj = repo.revparse_single(s)?; let obj = repo.revparse_single(s)?;
match obj.as_tag() { match obj.as_tag() {
Some(tag) => tag.target_id(), Some(tag) => tag.target_id(),
@ -958,14 +949,6 @@ pub(crate) fn fetch(
match reference { match reference {
// For branches and tags we can fetch simply one reference and copy it // For branches and tags we can fetch simply one reference and copy it
// locally, no need to fetch other branches/tags. // locally, no need to fetch other branches/tags.
GitReference::Branch(branch) => {
refspecs.push(format!("+refs/heads/{branch}:refs/remotes/origin/{branch}"));
}
GitReference::Tag(tag) => {
refspecs.push(format!("+refs/tags/{tag}:refs/remotes/origin/tags/{tag}"));
}
GitReference::BranchOrTag(branch_or_tag) => { GitReference::BranchOrTag(branch_or_tag) => {
refspecs.push(format!( refspecs.push(format!(
"+refs/heads/{branch_or_tag}:refs/remotes/origin/{branch_or_tag}" "+refs/heads/{branch_or_tag}:refs/remotes/origin/{branch_or_tag}"
@ -976,11 +959,31 @@ pub(crate) fn fetch(
refspec_strategy = RefspecStrategy::First; refspec_strategy = RefspecStrategy::First;
} }
// For ambiguous references, we can fetch the exact commit (if known); otherwise,
// we fetch all branches and tags.
GitReference::BranchOrTagOrCommit(branch_or_tag_or_commit) => {
// The `oid_to_fetch` is the exact commit we want to fetch. But it could be the exact
// commit of a branch or tag. We should only fetch it directly if it's the exact commit
// of a short commit hash.
if let Some(oid_to_fetch) =
oid_to_fetch.filter(|oid| is_short_hash_of(branch_or_tag_or_commit, *oid))
{
refspecs.push(format!("+{oid_to_fetch}:refs/commit/{oid_to_fetch}"));
} else {
// We don't know what the rev will point to. To handle this
// situation we fetch all branches and tags, and then we pray
// it's somewhere in there.
refspecs.push(String::from("+refs/heads/*:refs/remotes/origin/*"));
refspecs.push(String::from("+HEAD:refs/remotes/origin/HEAD"));
tags = true;
}
}
GitReference::DefaultBranch => { GitReference::DefaultBranch => {
refspecs.push(String::from("+HEAD:refs/remotes/origin/HEAD")); refspecs.push(String::from("+HEAD:refs/remotes/origin/HEAD"));
} }
GitReference::Ref(rev) => { GitReference::NamedRef(rev) => {
refspecs.push(format!("+{rev}:{rev}")); refspecs.push(format!("+{rev}:{rev}"));
} }
@ -997,19 +1000,6 @@ pub(crate) fn fetch(
refspecs.push(format!("+{rev}:refs/remotes/origin/HEAD")); refspecs.push(format!("+{rev}:refs/remotes/origin/HEAD"));
} }
} }
GitReference::ShortCommit(_) => {
if let Some(oid_to_fetch) = oid_to_fetch {
refspecs.push(format!("+{oid_to_fetch}:refs/commit/{oid_to_fetch}"));
} else {
// We don't know what the rev will point to. To handle this
// situation we fetch all branches and tags, and then we pray
// it's somewhere in there.
refspecs.push(String::from("+refs/heads/*:refs/remotes/origin/*"));
refspecs.push(String::from("+HEAD:refs/remotes/origin/HEAD"));
tags = true;
}
}
} }
debug!("Performing a Git fetch for: {remote_url}"); debug!("Performing a Git fetch for: {remote_url}");
@ -1022,8 +1012,12 @@ pub(crate) fn fetch(
let mut errors = refspecs let mut errors = refspecs
.iter() .iter()
.map_while(|refspec| { .map_while(|refspec| {
let fetch_result = let fetch_result = fetch_with_cli(
fetch_with_cli(repo, remote_url, &[refspec.clone()], tags); repo,
remote_url,
std::slice::from_ref(refspec),
tags,
);
// Stop after the first success and log failures // Stop after the first success and log failures
match fetch_result { match fetch_result {
@ -1335,40 +1329,33 @@ fn github_fast_path(
let local_object = reference.resolve(repo).ok(); let local_object = reference.resolve(repo).ok();
let github_branch_name = match reference { let github_branch_name = match reference {
GitReference::Branch(branch) => branch,
GitReference::Tag(tag) => tag,
GitReference::BranchOrTag(branch_or_tag) => branch_or_tag, GitReference::BranchOrTag(branch_or_tag) => branch_or_tag,
GitReference::DefaultBranch => "HEAD", GitReference::DefaultBranch => "HEAD",
GitReference::Ref(rev) => rev, GitReference::NamedRef(rev) => rev,
GitReference::FullCommit(rev) | GitReference::ShortCommit(rev) => { GitReference::FullCommit(rev) | GitReference::BranchOrTagOrCommit(rev) => {
if looks_like_commit_hash(rev) { // `revparse_single` (used by `resolve`) is the only way to turn
// `revparse_single` (used by `resolve`) is the only way to turn // short hash -> long hash, but it also parses other things,
// short hash -> long hash, but it also parses other things, // like branch and tag names, which might coincidentally be
// like branch and tag names, which might coincidentally be // valid hex.
// valid hex. //
// // We only return early if `rev` is a prefix of the object found
// We only return early if `rev` is a prefix of the object found // by `revparse_single`. Don't bother talking to GitHub in that
// by `revparse_single`. Don't bother talking to GitHub in that // case, since commit hashes are permanent. If a commit with the
// case, since commit hashes are permanent. If a commit with the // requested hash is already present in the local clone, its
// requested hash is already present in the local clone, its // contents must be the same as what is on the server for that
// contents must be the same as what is on the server for that // hash.
// hash. //
// // If `rev` is not found locally by `revparse_single`, we'll
// If `rev` is not found locally by `revparse_single`, we'll // need GitHub to resolve it and get a hash. If `rev` is found
// need GitHub to resolve it and get a hash. If `rev` is found // but is not a short hash of the found object, it's probably a
// but is not a short hash of the found object, it's probably a // branch and we also need to get a hash from GitHub, in case
// branch and we also need to get a hash from GitHub, in case // the branch has moved.
// the branch has moved. if let Some(local_object) = local_object {
if let Some(local_object) = local_object { if is_short_hash_of(rev, local_object) {
if is_short_hash_of(rev, local_object) { return Ok(FastPathRev::UpToDate);
return Ok(FastPathRev::UpToDate);
}
} }
rev
} else {
debug!("can't use github fast path with `rev = \"{}\"`", rev);
return Ok(FastPathRev::Indeterminate);
} }
rev
} }
}; };

View file

@ -95,12 +95,10 @@ impl From<GitUrl> for Url {
} else { } else {
// Otherwise, add the branch or tag name. // Otherwise, add the branch or tag name.
match git.reference { match git.reference {
GitReference::Branch(rev) GitReference::BranchOrTag(rev)
| GitReference::Tag(rev) | GitReference::NamedRef(rev)
| GitReference::BranchOrTag(rev)
| GitReference::Ref(rev)
| GitReference::FullCommit(rev) | GitReference::FullCommit(rev)
| GitReference::ShortCommit(rev) => { | GitReference::BranchOrTagOrCommit(rev) => {
url.set_path(&format!("{}@{}", url.path(), rev)); url.set_path(&format!("{}@{}", url.path(), rev));
} }
GitReference::DefaultBranch => {} GitReference::DefaultBranch => {}

View file

@ -1079,13 +1079,15 @@ fn compile_sdist_url_dependency() -> Result<()> {
Ok(()) Ok(())
} }
/// Resolve a specific Flask source distribution via a Git HTTPS dependency. /// Resolve a specific source distribution via a Git HTTPS dependency.
#[test] #[test]
#[cfg(feature = "git")] #[cfg(feature = "git")]
fn compile_git_https_dependency() -> Result<()> { fn compile_git_https_dependency() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in"); let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("flask @ git+https://github.com/pallets/flask.git")?; requirements_in.write_str(
"uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage",
)?;
// In addition to the standard filters, remove the `main` commit, which will change frequently. // In addition to the standard filters, remove the `main` commit, which will change frequently.
let filters: Vec<_> = [(r"@(\d|\w){40}", "@[COMMIT]")] let filters: Vec<_> = [(r"@(\d|\w){40}", "@[COMMIT]")]
@ -1100,113 +1102,23 @@ fn compile_git_https_dependency() -> Result<()> {
----- stdout ----- ----- stdout -----
# This file was autogenerated by uv via the following command: # This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in
blinker==1.7.0 uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@[COMMIT]
# via flask
click==8.1.7
# via flask
flask @ git+https://github.com/pallets/flask.git@[COMMIT]
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
# via flask
markupsafe==2.1.5
# via
# jinja2
# werkzeug
werkzeug==3.0.1
# via flask
----- stderr ----- ----- stderr -----
Resolved 7 packages in [TIME] Resolved 1 package in [TIME]
"###); "###);
Ok(()) Ok(())
} }
/// Resolve a specific Flask branch via a Git HTTPS dependency. /// Resolve a specific branch via a Git HTTPS dependency.
#[test] #[test]
#[cfg(feature = "git")] #[cfg(feature = "git")]
fn compile_git_branch_https_dependency() -> Result<()> { fn compile_git_branch_https_dependency() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("flask @ git+https://github.com/pallets/flask.git@1.0.x")?;
uv_snapshot!(context.compile()
.arg("requirements.in"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in
click==8.1.7
# via flask
flask @ git+https://github.com/pallets/flask.git@d92b64aa275841b0c9aea3903aba72fbc4275d91
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
# via flask
markupsafe==2.1.5
# via
# jinja2
# werkzeug
werkzeug==3.0.1
# via flask
----- stderr -----
Resolved 6 packages in [TIME]
"###
);
Ok(())
}
/// Resolve a specific Flask tag via a Git HTTPS dependency.
#[test]
#[cfg(feature = "git")]
fn compile_git_tag_https_dependency() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("flask @ git+https://github.com/pallets/flask.git@3.0.0")?;
uv_snapshot!(context.compile()
.arg("requirements.in"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in
blinker==1.7.0
# via flask
click==8.1.7
# via flask
flask @ git+https://github.com/pallets/flask.git@735a4701d6d5e848241e7d7535db898efb62d400
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
# via flask
markupsafe==2.1.5
# via
# jinja2
# werkzeug
werkzeug==3.0.1
# via flask
----- stderr -----
Resolved 7 packages in [TIME]
"###
);
Ok(())
}
/// Resolve a specific Flask commit via a Git HTTPS dependency.
#[test]
#[cfg(feature = "git")]
fn compile_git_long_commit_https_dependency() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in"); let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str( requirements_in.write_str(
"flask @ git+https://github.com/pallets/flask.git@d92b64aa275841b0c9aea3903aba72fbc4275d91", "uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@test-branch",
)?; )?;
uv_snapshot!(context.compile() uv_snapshot!(context.compile()
@ -1216,35 +1128,25 @@ fn compile_git_long_commit_https_dependency() -> Result<()> {
----- stdout ----- ----- stdout -----
# This file was autogenerated by uv via the following command: # This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in
click==8.1.7 uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@0dacfd662c64cb4ceb16e6cf65a157a8b715b979
# via flask
flask @ git+https://github.com/pallets/flask.git@d92b64aa275841b0c9aea3903aba72fbc4275d91
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
# via flask
markupsafe==2.1.5
# via
# jinja2
# werkzeug
werkzeug==3.0.1
# via flask
----- stderr ----- ----- stderr -----
Resolved 6 packages in [TIME] Resolved 1 package in [TIME]
"### "###
); );
Ok(()) Ok(())
} }
/// Resolve a specific Flask commit via a Git HTTPS dependency. /// Resolve a specific tag via a Git HTTPS dependency.
#[test] #[test]
#[cfg(feature = "git")] #[cfg(feature = "git")]
fn compile_git_short_commit_https_dependency() -> Result<()> { fn compile_git_tag_https_dependency() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in"); let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("flask @ git+https://github.com/pallets/flask.git@d92b64a")?; requirements_in.write_str(
"uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@test-tag",
)?;
uv_snapshot!(context.compile() uv_snapshot!(context.compile()
.arg("requirements.in"), @r###" .arg("requirements.in"), @r###"
@ -1253,36 +1155,107 @@ fn compile_git_short_commit_https_dependency() -> Result<()> {
----- stdout ----- ----- stdout -----
# This file was autogenerated by uv via the following command: # This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in
click==8.1.7 uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@0dacfd662c64cb4ceb16e6cf65a157a8b715b979
# via flask
flask @ git+https://github.com/pallets/flask.git@d92b64aa275841b0c9aea3903aba72fbc4275d91
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
# via flask
markupsafe==2.1.5
# via
# jinja2
# werkzeug
werkzeug==3.0.1
# via flask
----- stderr ----- ----- stderr -----
Resolved 6 packages in [TIME] Resolved 1 package in [TIME]
"### "###
); );
Ok(()) Ok(())
} }
/// Resolve a specific Flask ref via a Git HTTPS dependency. /// Resolve a specific tag via a Git HTTPS dependency.
///
/// In this case, the tag is a date, and thus could feasibly refer to a short commit hash.
#[test]
#[cfg(feature = "git")]
fn compile_git_date_tag_https_dependency() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str(
"uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@20240402",
)?;
uv_snapshot!(context.compile()
.arg("requirements.in"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in
uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@0dacfd662c64cb4ceb16e6cf65a157a8b715b979
----- stderr -----
Resolved 1 package in [TIME]
"###
);
Ok(())
}
/// Resolve a specific commit via a Git HTTPS dependency.
#[test]
#[cfg(feature = "git")]
fn compile_git_long_commit_https_dependency() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str(
"uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@0dacfd662c64cb4ceb16e6cf65a157a8b715b979",
)?;
uv_snapshot!(context.compile()
.arg("requirements.in"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in
uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@0dacfd662c64cb4ceb16e6cf65a157a8b715b979
----- stderr -----
Resolved 1 package in [TIME]
"###
);
Ok(())
}
/// Resolve a specific commit via a Git HTTPS dependency.
#[test]
#[cfg(feature = "git")]
fn compile_git_short_commit_https_dependency() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str(
"uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@0dacfd6",
)?;
uv_snapshot!(context.compile()
.arg("requirements.in"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in
uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@0dacfd662c64cb4ceb16e6cf65a157a8b715b979
----- stderr -----
Resolved 1 package in [TIME]
"###
);
Ok(())
}
/// Resolve a specific ref via a Git HTTPS dependency.
#[test] #[test]
#[cfg(feature = "git")] #[cfg(feature = "git")]
fn compile_git_refs_https_dependency() -> Result<()> { fn compile_git_refs_https_dependency() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in"); let requirements_in = context.temp_dir.child("requirements.in");
requirements_in requirements_in
.write_str("flask @ git+https://github.com/pallets/flask.git@refs/pull/5313/head")?; .write_str("uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@refs/pull/4/head")?;
uv_snapshot!(context.compile() uv_snapshot!(context.compile()
.arg("requirements.in"), @r###" .arg("requirements.in"), @r###"
@ -1291,24 +1264,10 @@ fn compile_git_refs_https_dependency() -> Result<()> {
----- stdout ----- ----- stdout -----
# This file was autogenerated by uv via the following command: # This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in
blinker==1.7.0 uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@9d01a806f17ddacb9c7b66b1b68574adf790b63f
# via flask
click==8.1.7
# via flask
flask @ git+https://github.com/pallets/flask.git@7af0271f4703a71beef8e26d1f5f6f8da04100e6
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
# via flask
markupsafe==2.1.5
# via
# jinja2
# werkzeug
werkzeug==3.0.1
# via flask
----- stderr ----- ----- stderr -----
Resolved 7 packages in [TIME] Resolved 1 package in [TIME]
"### "###
); );