Skip to content

Commit ed7d891

Browse files
committed
Assume git+ prefix when URLs end in .git
1 parent e4ec6e4 commit ed7d891

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

crates/pypi-types/src/parsed_url.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ impl TryFrom<Url> for ParsedUrl {
347347
message: "Unknown scheme",
348348
}),
349349
}
350+
} else if url.path().ends_with(".git") {
351+
Ok(Self::Git(ParsedGitUrl::try_from(url)?))
350352
} else if url.scheme().eq_ignore_ascii_case("file") {
351353
let path = url
352354
.to_file_path()

crates/uv/src/commands/project/add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub(crate) async fn add(
106106

107107
// Read the requirements.
108108
let RequirementsSpecification { requirements, .. } =
109-
RequirementsSpecification::from_sources(&requirements, &[], &[], &client_builder).await?;
109+
RequirementsSpecification::from_simple_sources(&requirements, &client_builder).await?;
110110

111111
// TODO(charlie): These are all default values. We should consider whether we want to make them
112112
// optional on the downstream APIs.

crates/uv/tests/edit.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,64 @@ fn add_git_raw() -> Result<()> {
491491
Ok(())
492492
}
493493

494+
/// Add a Git requirement without the `git+` prefix.
495+
#[test]
496+
fn add_git_implicit() -> Result<()> {
497+
let context = TestContext::new("3.12");
498+
499+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
500+
pyproject_toml.write_str(indoc! {r#"
501+
[project]
502+
name = "project"
503+
version = "0.1.0"
504+
requires-python = ">=3.12"
505+
dependencies = ["anyio==3.7.0"]
506+
"#})?;
507+
508+
uv_snapshot!(context.filters(), context.lock(), @r###"
509+
success: true
510+
exit_code: 0
511+
----- stdout -----
512+
513+
----- stderr -----
514+
warning: `uv lock` is experimental and may change without warning
515+
Resolved 4 packages in [TIME]
516+
"###);
517+
518+
uv_snapshot!(context.filters(), context.sync().arg("--frozen"), @r###"
519+
success: true
520+
exit_code: 0
521+
----- stdout -----
522+
523+
----- stderr -----
524+
warning: `uv sync` is experimental and may change without warning
525+
Prepared 4 packages in [TIME]
526+
Installed 4 packages in [TIME]
527+
+ anyio==3.7.0
528+
+ idna==3.6
529+
+ project==0.1.0 (from file://[TEMP_DIR]/)
530+
+ sniffio==1.3.1
531+
"###);
532+
533+
// Omit the `git+` prefix.
534+
uv_snapshot!(context.filters(), context.add(&["uv-public-pypackage @ https://github.com/astral-test/uv-public-pypackage.git"]).arg("--preview"), @r###"
535+
success: true
536+
exit_code: 0
537+
----- stdout -----
538+
539+
----- stderr -----
540+
Resolved 5 packages in [TIME]
541+
Prepared 2 packages in [TIME]
542+
Uninstalled 1 package in [TIME]
543+
Installed 2 packages in [TIME]
544+
- project==0.1.0 (from file://[TEMP_DIR]/)
545+
+ project==0.1.0 (from file://[TEMP_DIR]/)
546+
+ uv-public-pypackage==0.1.0 (from git+https://github.com/astral-test/uv-public-pypackage.git@b270df1a2fb5d012294e9aaf05e7e0bab1e6a389)
547+
"###);
548+
549+
Ok(())
550+
}
551+
494552
/// `--raw-sources` should be considered conflicting with sources-specific arguments, like `--tag`.
495553
#[test]
496554
fn add_raw_error() -> Result<()> {

crates/uv/tests/pip_install.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,31 @@ fn install_git_public_https() {
13571357
context.assert_installed("uv_public_pypackage", "0.1.0");
13581358
}
13591359

1360+
/// Install a package from a public GitHub repository, omitting the `git+` prefix
1361+
#[test]
1362+
#[cfg(feature = "git")]
1363+
fn install_implicit_git_public_https() {
1364+
let context = TestContext::new("3.8");
1365+
1366+
uv_snapshot!(
1367+
context
1368+
.pip_install()
1369+
.arg("uv-public-pypackage @ https://github.com/astral-test/uv-public-pypackage.git"),
1370+
@r###"
1371+
success: true
1372+
exit_code: 0
1373+
----- stdout -----
1374+
1375+
----- stderr -----
1376+
Resolved 1 package in [TIME]
1377+
Prepared 1 package in [TIME]
1378+
Installed 1 package in [TIME]
1379+
+ uv-public-pypackage==0.1.0 (from git+https://github.com/astral-test/uv-public-pypackage.git@b270df1a2fb5d012294e9aaf05e7e0bab1e6a389)
1380+
"###);
1381+
1382+
context.assert_installed("uv_public_pypackage", "0.1.0");
1383+
}
1384+
13601385
/// Install and update a package from a public GitHub repository
13611386
#[test]
13621387
#[cfg(feature = "git")]

0 commit comments

Comments
 (0)