150 Commits

Author SHA1 Message Date
Ross Sullivan
92d9a94d02
chore: Migrated testsuite to testsuite::prelude 2025-06-25 22:37:24 +09:00
Weihang Lo
d7940042bd
Fix cargo add overwriting symlinked Cargo.toml files (#15281)
### What does this PR try to resolve?

This PR fixes a bug where `cargo add` breaks symlinks to Cargo.toml
files. Currently, when Cargo.toml is a symlink and `cargo add` is used
to add a dependency, the symlink is replaced with a regular file,
breaking the link to the original target file.

This issue was reported in #15241 where a user who relies on symlinked
Cargo.toml files found that `cargo add` breaks their workflow.

Fixes #15241

### How should we test and review this PR?

I've modified `LocalManifest::write()` to check if the path is a
symlink, and if so, follow it to get the actual target path. This
ensures we write to the actual file rather than replacing the symlink.

I've also added a test in `tests/testsuite/cargo_add/symlink.rs` that:
1. Creates a symlinked Cargo.toml file
2. Runs `cargo add` to add a dependency
3. Verifies the symlink is preserved and the dependency is added to the
target file

I've manually tested this fix and confirmed it works correctly.
2025-06-02 10:23:52 +00:00
Raghavender Singh
ecfe3a961d fix: handle symlinks properly in write_atomic
- Preserve symlinks when writing files atomically in write_atomic()
- Update test to verify correct symlink preservation behavior
- Apply rustfmt formatting

This fixes the issue where cargo add would replace symlinked Cargo.toml
files with regular files, breaking the symlink to the original target.

Fixes #15241
2025-06-02 10:26:42 +05:30
Raghavender Singh
35d2a30a5c test: Add test demonstrating cargo add replaces symlinks
This test shows the current behavior where cargo add replaces
symlinked Cargo.toml files with regular files. The test passes,
documenting this problematic behavior.
2025-05-30 00:25:18 +05:30
Pyrode
9ae361a8fe add: Added error message for when v is prefixed with version 2025-05-03 22:25:12 +05:30
Pyrode
ac86dea366 test(add): Added test case for prefixed v in version 2025-05-03 22:24:52 +05:30
Ed Page
64e3cd1ac5
feat(add): suggest similarly named features (#15438)
### What does this PR try to resolve?
Fixes #15436

### How should we test and review this PR?
There are 3 tests for each test case:
- there are no feature suggestions
- there's only one feature suggestion (most common)
- there are several feature suggestions
2025-05-01 14:56:49 +00:00
Farid Huliiev
ba494bce13
feat: suggest similarly named features 2025-05-01 16:12:36 +02:00
Farid Huliiev
e29810c327
feat: add tests for similarly named features 2025-05-01 16:02:15 +02:00
Farid Huliiev
49e2f84edd
fix: output a blank line between items 2025-04-30 19:56:31 +02:00
dawe
0df8d68cf9
feat(add): check if given crate argument would be valid with inserted @ symbol, suggest fixed argument 2025-04-27 01:23:51 +02:00
dawe
ab0d6a7bd2
test(add): add test to show current behaviour of cargo add when @ symbol is missing for the version 2025-04-27 01:23:26 +02:00
Sebastian Poeplau
aa1b353d64 Prevent undeclared public network access
Stop a few tests which aren't marked with `public_network_test` from
trying to access crates.io. While doing so, also make sure that other
`cargo_add` and `cargo_info` tests initialize the registry.
2025-04-01 11:41:30 +02:00
NOOMA-42
3ea0e6b751
feat: vcs, color, and message format native completion 2025-03-20 22:16:27 +08:00
Ed Page
524d123332 fix(add): Focus on error, rather than large feature lists
Inspired by #11100 and previous work to collapse feature lists down.
2025-02-18 12:44:13 -06:00
Ed Page
1f34b007e8 test(add): Show behavior with unrecognized feature with large list 2025-02-18 12:42:43 -06:00
Eric Huss
b5394da406 Update annotate-snippets from 0.11.4 to 0.11.5
Changelog: https://github.com/rust-lang/annotate-snippets-rs/blob/master/CHANGELOG.md#0115---2024-12-09

Looks to have some minor rendering differences.
2025-02-09 12:46:36 -08:00
Ed Page
5df493ecd9 fix(add): Don't select yanked versions when normalizing names
Fixes #14893
2024-12-05 09:48:21 -06:00
Ed Page
737a5e8325 test(add): Verify yanked behavior 2024-12-05 09:24:46 -06:00
Ed Page
e008a39f47 test(add): Check normalization with a yanked package 2024-12-05 09:21:24 -06:00
Ed Page
9bdc777951 test(add): Make name normalization test names consistent 2024-12-05 09:15:17 -06:00
Ed Page
26844a3331 feat(toml): Allow adding/removing from cargo scripts 2024-11-26 12:23:48 -06:00
Ed Page
589d09917c test(script): Verify manifest modification commands 2024-11-26 12:23:48 -06:00
Ed Page
0498e84f89 feat: Stabilize MSRV-aware resolver config
This includes
- `cargo generate-lockfile --ignore-rust-version`
- `cargo update --ignore-rust-version`

This does not include
- `edition = "2024"`
- `resolver = "3"`
2024-10-04 12:49:28 -05:00
Weihang Lo
b4253e5057
fix(help): mention --config <PATH> in help text 2024-10-01 14:54:52 -04:00
Weihang Lo
5dfdd59009
feat: make lockfile v4 the default
This commit makes lockfile version 4 the default version when Cargo
tries to write to a lockfile.

The lockfile version 4 has been stabilized since 1.78.0,
and will become default in 1.83.0.
the length of transition period is pretty similar as before.

One caveat is that in other output from Cargo,
e.g., `cargo metatada`, status messages,
`SourceID` will display in the v4 URL encoded format.
This shouldn't affect the majority of Rust users,
as `SourceId` representation should be opaque to them,
unless comparing `SourceId` across different version of toolchains.
2024-09-24 20:43:02 -04:00
Daniel Paoliello
8de55540f0 Implement path-bases (RFC 3529) 2/n: cargo add support
RFC: https://github.com/rust-lang/rfcs/pull/3529
Tracking Issue: https://github.com/rust-lang/cargo/issues/14355

This PR adds the `--base` option to `cargo add` to allow adding a path dependency with a path base.
2024-09-06 10:01:49 -07:00
bors
40b6638df6 Auto merge of #13765 - dohse:fix-13702, r=epage
Fix cargo add behaving different when translating package name

Fixes #13702
Fixes #10680

TODOs

- [x] ~Fuzzy match registry dependencies in `cargo remove` as well~
     `cargo remove` does not need fuzzy matching, because there is no unexpected behavior for the user
- [x] ~Don't duplicate name permutation generation~
     Unsure whether this is worth it
- [ ] Shall we reject cases where multiple different permutations match?
- [x] Add comments that explain the behavior
2024-09-04 00:17:46 +00:00
Jonas Dohse
9391bfb34d Fix #10680, Fix #13702 2024-09-01 15:49:34 +02:00
Ed Page
911f5e17b6 feat(resolve): Report MSRV compatible version instead of incomptible
This expands on #14461 to where only MSRV-compatible versions are
"actionable".  MSRV-incompatible versions are therefore unstyled.

We report the MSRV needed so people can choose to unblock by updating
their MSRV.  I had wondered if we should report the the absolute latest
MSRV-incompatible version or the one with the next higher MSRV from
where the user is at.  Both are reasonable use cases, so I erred with
absolute latest version.
2024-08-30 09:40:54 -05:00
Ed Page
ded3f004a4 fix(resolve): Generalize term describing updates
`latest` was easy.  `latest compatible` was ok.  But how do I talk about
"latest compatible with your MSRV".  That gets messy.
2024-08-30 09:26:56 -05:00
Jonas Dohse
140911cc12 Add test case for feature adding with fuzzy name #10680 2024-08-30 12:16:29 +02:00
Jonas Dohse
cdab0c0058 Add test case for fuzzy package adding issue #13702 2024-08-30 12:16:29 +02:00
Ed Page
3c19a8cb7b feat(resolve): Report incompatible with rustc when MSRV-resolve disabled 2024-08-26 14:12:54 -05:00
Ed Page
d2ec764995 fix(resolve): Dont show locking workspace members
This is for `cargo generate-lockfile` and when syncing the lockfile with
the manifest.
We still show it for `cargo update` because of `cargo update
--workspace`.

We hacked around this previously by filtering out the `num_pkgs==1` case
for single packages but this didn't help with workspaces.
2024-08-22 16:57:06 -05:00
bors
3293d22f00 Auto merge of #14326 - Ifropc:5707-lock-path, r=weihanglo
Add `--lockfile-path` flag

This change implements a new `--lockfile-path` proposed in #5707 .

Functionality added:
- Add `--lockfile-path <PATH>` to all commands that support `manifest-path` with exception of:
   - `locate-project` (doesn't use lock file)
   - `verify-project` (is deprecated)
   - `read-manifest` (doesn't use lock file)
- Behind -Zunstable-options and docs
   - The flag's docs / `--help` has (unstable) in them
- `<PATH>` must end with `Cargo.lock`. If specified path doesn't exist (or parent director(ies), create all the parent directories and the lockfile itself

Implementation TLDR: add `requested_lockfile_path` into `Workspace` and set it on `workspace(gctx)` call (setting from the context)
Update `lockfile.lock_root()` to respect `requested_lockfile_path` (if set)
Add test cases covering all affected commands. Tested creating lockfile, reading lockfile, overriding default (`./Cargo.lock`) lockfile, symlink tests. Extra tests for package to make sure pinned versions from path's lockfile are respected (i.e. double check correct lockfile is used)
I doubt this flag will be used for any command that's not read-only, but I tried to cover all the commands.
2024-08-16 14:38:39 +00:00
Daniel Paoliello
4d49d2d179 Don't specify the depdency name in the inferred name test 2024-08-06 09:29:50 -07:00
Ifropc
bf7e2dcc1d
feat: lockfile path refactoring 2024-08-03 16:40:10 -07:00
Ifropc
3da56677e1
refactoring: lockfile-path documentation and implementation cleanup 2024-07-31 21:30:44 -07:00
Ed Page
8622918953 fix(config): Adjust MSRV resolve config field name / values
Fixes #13540
2024-07-31 15:27:01 -05:00
Ifropc
c25dcf00df
doc: add docs for lockfile-path 2024-07-30 21:20:17 -07:00
Scott Schafer
6a7b15a61e
test: Auto-redact host target and alt target 2024-06-12 13:27:08 -06:00
Ed Page
c00c5cd1cf fix(add): Avoid escaping double-quotes by using string literals
Fixes #14002
2024-06-03 11:22:00 -05:00
Ed Page
5c3b534101 test(add): Show quoting behavior for --target 2024-06-03 10:39:53 -05:00
Ed Page
9af864ee55 refactor: Resolve deprecations 2024-05-27 21:27:03 -05:00
Ed Page
4a6f25c112 refactor: Resolve snapbox deprecations 2024-05-27 10:28:13 -05:00
bors
7e9c2ef30f Auto merge of #13775 - epage:incomplete-dep, r=weihanglo
fix(toml)!: Disallow source-less dependencies

### What does this PR try to resolve?

This is part of #13629 addressing “dependency without path, version, git, workspace specified”.

This turns deps like
```toml
foo = { optional = true }
```
from `version="*"` deps with a warning into errors. This breaking change was deemed acceptable because this behavior has been considered a bug from the beginning.
We have gotten little to no feedback about people wanting this behavior.

This improves our forwards-compatibility story as we can add new dependency sources and they won't be considered a wildcard registry dependency on older cargo.

### How should we test and review this PR?

I removed the `cargo_add` test because it is redundant.

We no longer get the “unused key” warnings because those warnings get deferred to after this error gets reported.

### Additional information
2024-04-18 22:02:05 +00:00
Ed Page
cf23e4b538 fix(toml)!: Disallow source-less dependencies
This is part of #13629

This turns deps like
```toml
foo = { optional = true }
```
from `version="*"` deps with a warning into errors.
This breaking change was deemed acceptable because this behavior has
been considered a bug from the beginning.
We have gotten little to no feedback about people wanting this behavior.

This improves our forwards-compatibility story as we can add new
dependency sources and they won't be considered a wildcard registry
dependency on older cargo.
2024-04-18 12:55:27 -05:00
Ed Page
34afc4f1ff test(msrv): Prep for config to be added 2024-04-17 11:44:02 -05:00
Ed Page
1876326b6b feat(resolve): Tell the user the style of resovle done
This is to help with #9930

Example changes:
```diff
-[LOCKING] 4 packages
+[LOCKING] 4 packages to latest version
-[LOCKING] 2 packages
+[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
-[LOCKING] 2 packages
+[LOCKING] 2 packages to earliest versions
```

Benefits
- The package count is of "added" packages and this makes that more
  logically clear
- This gives users transparency into what is happening, especially with
  - what rust-version is use
  - the transition to this feature in the new edition
  - whether the planned config was applied or not (as I don't want it to
    require an MSRV bump)
- Will make it easier in tests to show what changed
- Provides more motiviation to show this message in `cargo update` and
  `cargo install` (that will be explored in a follow up PR)

This does come at the cost of more verbose output but hopefully not too
verbose.  This is why I left off other factors, like avoid-dev-deps.
2024-04-13 20:39:59 -05:00