Skip to content

Commit a0e8d3e

Browse files
committed
Avoid erroneous updates
1 parent bbccee8 commit a0e8d3e

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -411,21 +411,20 @@ pub(crate) async fn add(
411411
}
412412
};
413413

414-
// Keep track of the exact location of the edit.
415-
let index = edit.index();
416-
417414
// If the edit was inserted before the end of the list, update the existing edits.
418-
for edit in &mut edits {
419-
if *edit.dependency_type == dependency_type {
420-
match &mut edit.edit {
421-
ArrayEdit::Add(existing) => {
422-
if *existing >= index {
423-
*existing += 1;
415+
if let ArrayEdit::Add(index) = &edit {
416+
for edit in &mut edits {
417+
if *edit.dependency_type == dependency_type {
418+
match &mut edit.edit {
419+
ArrayEdit::Add(existing) => {
420+
if *existing >= *index {
421+
*existing += 1;
422+
}
424423
}
425-
}
426-
ArrayEdit::Update(existing) => {
427-
if *existing >= index {
428-
*existing += 1;
424+
ArrayEdit::Update(existing) => {
425+
if *existing >= *index {
426+
*existing += 1;
427+
}
429428
}
430429
}
431430
}

crates/uv/tests/edit.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4539,3 +4539,53 @@ fn custom_dependencies() -> Result<()> {
45394539
});
45404540
Ok(())
45414541
}
4542+
4543+
/// Regression test for: <https://github.com/astral-sh/uv/issues/7259>
4544+
#[test]
4545+
fn update_offset() -> Result<()> {
4546+
let context = TestContext::new("3.12");
4547+
4548+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
4549+
pyproject_toml.write_str(indoc! {r#"
4550+
[project]
4551+
name = "project"
4552+
version = "0.1.0"
4553+
requires-python = ">=3.12"
4554+
dependencies = [
4555+
"iniconfig",
4556+
]
4557+
"#})?;
4558+
4559+
uv_snapshot!(context.filters(), context.add().args(["typing-extensions", "iniconfig"]), @r###"
4560+
success: true
4561+
exit_code: 0
4562+
----- stdout -----
4563+
4564+
----- stderr -----
4565+
Resolved 3 packages in [TIME]
4566+
Prepared 2 packages in [TIME]
4567+
Installed 2 packages in [TIME]
4568+
+ iniconfig==2.0.0
4569+
+ typing-extensions==4.10.0
4570+
"###);
4571+
4572+
let pyproject_toml = fs_err::read_to_string(context.temp_dir.join("pyproject.toml"))?;
4573+
4574+
insta::with_settings!({
4575+
filters => context.filters(),
4576+
}, {
4577+
assert_snapshot!(
4578+
pyproject_toml, @r###"
4579+
[project]
4580+
name = "project"
4581+
version = "0.1.0"
4582+
requires-python = ">=3.12"
4583+
dependencies = [
4584+
"iniconfig",
4585+
"typing-extensions>=4.10.0",
4586+
]
4587+
"###
4588+
);
4589+
});
4590+
Ok(())
4591+
}

0 commit comments

Comments
 (0)