Commit graph

91 commits

Author SHA1 Message Date
Eric Huss c46e57b0cf Fix corrupted git checkout recovery. 2022-07-05 21:02:08 -07:00
Danil Hendra Suryawan 08d10184aa Restrict duplicate deps warning only to published packages 2022-06-21 00:28:25 +00:00
Jakub Sitnicki 26031b9069 Respect submodule update=none strategy in .gitmodules
Git lets users define the default update/checkout strategy for a submodule
by setting the `submodule.<name>.update` key in `.gitmodules` file.

If the update strategy is `none`, the submodule will be skipped during
update. It will not be fetched and checked out:

1. *foo* is a big git repo

```
/tmp $ git init foo
Initialized empty Git repository in /tmp/foo/.git/
/tmp $ dd if=/dev/zero of=foo/big bs=1000M count=1
1+0 records in
1+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 0.482087 s, 2.2 GB/s
/tmp $ git -C foo add big
/tmp $ git -C foo commit -m 'I am big'
[main (root-commit) 84fb533] I am big
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 big
```

2. *bar* is a repo with a big submodule with `update=none`

```
/tmp $ git init bar
Initialized empty Git repository in /tmp/bar/.git/
/tmp $ git -C bar submodule add file:///tmp/foo foo
Cloning into '/tmp/bar/foo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 1 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), 995.50 KiB | 338.00 KiB/s, done.
/tmp $ git -C bar config --file .gitmodules submodule.foo.update none
/tmp $ cat bar/.gitmodules
[submodule "foo"]
        path = foo
        url = file:///tmp/foo
        update = none
/tmp $ git -C bar commit --all -m 'I have a big submodule with update=none'
[main (root-commit) 6c355ea] I have a big submodule not updated by default
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 foo
```

3. *baz* is a clone of *bar*, notice *foo* submodule gets skipped

```
/tmp $ git clone --recurse-submodules file:///tmp/bar baz
Cloning into 'baz'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Submodule 'foo' (file:///tmp/foo) registered for path 'foo'
Skipping submodule 'foo'
/tmp $ git -C baz submodule update --init
Skipping submodule 'foo'
/tmp $
```

Cargo, on the other hand, ignores the submodule update strategy set in
`.gitmodules` properties when updating dependencies. Such behavior can
be considered against the wish of the crate publisher.

4. *bar* is now a lib with a big submodule with update disabled

```
/tmp $ cargo init --lib bar
     Created library package
/tmp $ git -C bar add .
/tmp $ git -C bar commit -m 'I am a lib with a big submodule but update=none'
[main eb07cf7] I am a lib with a big submodule but update=none
 3 files changed, 18 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 Cargo.toml
 create mode 100644 src/lib.rs
/tmp $
```

5. *qux* depends on *bar*, notice *bar*'s submodules are fetched

```
/tmp $ cargo init qux && cd qux
     Created binary (application) package
/tmp/qux $ echo -e '[dependencies.bar]\ngit = "file:///tmp/bar"' >> Cargo.toml
/tmp/qux $ time cargo update
    Updating git repository `file:///tmp/bar`
    Updating git submodule `file:///tmp/foo`

real    0m22.182s
user    0m20.402s
sys     0m1.714s
/tmp/qux $
```

Fix it by checking if a Git repository submodule should be updated when
cargo processes dependencies.

6. With the change applied, submodules with `update=none` are skipped

```
/tmp/qux $ cargo cache -a > /dev/null
/tmp/qux $ time ~/src/cargo/target/debug/cargo update
    Updating git repository `file:///tmp/bar`
    Skipping git submodule `file:///tmp/foo`

real    0m0.029s
user    0m0.021s
sys     0m0.008s
/tmp/qux $
```

Fixes #4247.

Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
2022-06-07 14:52:02 +02:00
Danil Hendra Suryawan e903f7dfc0 Emit warning upon encountering ambiguous deps 2022-05-28 03:32:04 +00:00
Ed Page cdec3838a8 Extend pkgid syntax with @ support
In addition to `foo:1.2.3`, we now support `foo@1.2.3` for pkgids.  We
are also making it the default way of rendering pkgid's for the user.

With cargo-add in #10472, we've decided to only use `@` in it and to add
it as an alternative to `:` in the rest of cargo.  `cargo-add`
originally used `@`.  When preparing it for merge, I switched to `:` to
be consistent with pkgids. When discussing this, it was felt `@` has
precedence in too many tools to switch to `:` but that we should instead
switch pkgid's to use `@`, in a backwards compatible way.

See also https://internals.rust-lang.org/t/feedback-on-cargo-add-before-its-merged/16024/26?u=epage
2022-04-19 16:00:15 -05:00
Martin Pool c45ab7dd30 Remove redundant assertions 2022-04-24 19:51:01 -07:00
Martin Pool 5afc6c7021 Test .cargo/git/CACHEDIR.TAG is created 2022-04-24 19:51:01 -07:00
Ed Page 320c279f43 Port cargo from toml-rs to toml_edit
Benefits:
- A TOML 1.0 compliant parser
- Unblock future work
  - Have `cargo init` add the current crate to the workspace, rather
    than error
  - #5586: Upstream `cargo-add`
2022-01-13 09:27:27 -06:00
Eric Huss 8d5576ba81 Fix fetching git repos after a force push. 2021-10-18 14:08:33 -07:00
flip1995 390af27128
Add rust_metadata to SerializedPackage
After the rust_version field was stabilized in #9732 this adds the
rust_version as output to the `cargo metadata` command, so tools like
Clippy can read and use it as well.
2021-10-12 14:07:19 +02:00
David Tolnay 361b11000a
Add test of git dependency on pull request 2021-09-01 00:42:06 -07:00
hi-rustin f9a5625733 add default_run to SerializedPackage
Delete "default_run": null,
2021-06-07 14:59:57 +08:00
Eric Huss a200640dbd Improve performance of git status check in cargo package. 2021-05-10 18:15:05 -07:00
Gus Wynn 04c8372217 fix test suite 2021-02-21 14:37:42 -08:00
Alex Crichton 1fefa5de26 Add back in deleted tests 2021-02-09 07:29:01 -08:00
Alex Crichton 7dd9872c13 Change git dependencies to use HEAD by default
This commit follows through with work started in #8522 to change the
default behavior of `git` dependencies where if not branch/tag/etc is
listed then `HEAD` is used instead of the `master` branch. This involves
also changing the default lock file format, now including a `version`
marker at the top of the file notably as well as changing the encoding
of `branch=master` directives in `Cargo.toml`.

If we did all our work correctly then this will be a seamless change.
First released on stable in 1.47.0 (2020-10-08) Cargo has been emitting
warnings about situations which may break in the future. This means that
if you don't specify `branch = 'master'` but your HEAD branch isn't
`master`, you've been getting a warning. Similarly if your dependency
graph used both `branch = 'master'` as well as specifying nothing, you
were receiving warnings as well. These two situations are broken by this
commit, but it's hoped that by giving enough times with warnings we
don't actually break anyone in practice.
2021-02-04 08:54:40 -08:00
Eric Huss d88ed1cb6c Normalize SourceID in cargo metadata. 2020-11-01 10:48:21 -08:00
Eric Huss 6f8c7d5a87 Normalize raw string indentation. 2020-09-26 17:59:58 -07:00
Alex Crichton 07162dbaa8 Warn if master unifies with DefaultBranch
This commit implements a simple warning to indicate when `DefaultBranch`
is unified with `Branch("master")`, meaning `Cargo.toml` inconsistently
lists `branch = "master"` and not. The intention here is to ensure that
all projects uniformly use one or the other to ensure we can smoothly
transition to the new lock file format.
2020-07-23 08:35:01 -07:00
Alex Crichton 32f52fd2e1 Warn when default branch is not master
This commit implements a warning in Cargo for when a dependency
directive is using `DefaultBranch` but the default branch of the remote
repository is not actually `master`. We will eventually break this
dependency directive and the warning indicates the fix, which is to
write down `branch = "master"`.
2020-07-23 08:35:01 -07:00
Alex Crichton 538fb1b4ed Effectively revert #8364
This commit is intended to be an effective but not literal revert
of #8364. Internally Cargo will still distinguish between
`DefaultBranch` and `Branch("master")` when reading `Cargo.toml` files,
but for almost all purposes the two are equivalent. This will namely fix
the issue we have with lock file encodings where both are encoded with
no `branch` (and without a branch it's parsed from a lock file as
`DefaultBranch`).

This will preserve the change that `cargo vendor` will not print out
`branch = "master"` annotations but that desugars to match the lock file
on the other end, so it should continue to work.

Tests have been added in this commit for the regressions found on #8468.
2020-07-23 08:35:01 -07:00
Alex Crichton 4c02977c21 Improve support for non-master main branches
This commit improves Cargo's support for git repositories whose "main
branch" is not called `master`. Cargo currently pretty liberally assumes
that if nothing else about a git repository is specified then `master`
is the branch name to use. Instead now Cargo has a fourth option as the
desired reference of a repository named `DefaultBranch`. Cargo doesn't
know anything about the actual name of the default branch, it just
updates how git references are fetched internally.

This commit is motivated by news that GitHub is likely to switch away
from the default branch being named `master` in the near future. It
would be a bit of a bummer if from now on everyone had to type
`branch = '...'`, so this tries to improve that!
2020-06-18 10:56:19 -07:00
Alex Crichton ddc27999c1 Update how locked git commits are fetched
This commit refactors various logic of the git source internals to
ensure that if we have a locked revision that we plumb the desired
branch/tag all the way through to the `fetch`. Previously we'd switch to
`Rev` very early on, but the fetching logic for `Rev` is very eager and
fetches too much, so instead we only resolve the locked revision later
on.

Internally this does some various refactoring to try to make various
bits and pieces of logic a bit easyer to grok, although it's still
perhaps not the cleanest implementation.
2020-06-16 09:36:49 -07:00
Eric Huss 4ae79d2ffd Use fs helpers instead of File functions. 2020-04-17 07:56:16 -07:00
Eric Huss 2fa95e3ec4 Add "Updating" status for git submodules. 2020-03-11 18:37:31 -07:00
Jun Wu a2cddeeb9f Ignore broken Cargo.toml in git sources
Commit 3d6de41774 (#3998) made cargo
ignore Cargo.toml files that are invalid TOML in a git source.
This change further ignores Cargo.toml files that are valid TOML but
cannot really be loaded.

This is potentially an alternative fix for #6822.
2020-02-29 09:31:52 -08:00
Eric Huss 1eca786d7f Add path to the failure to load a dependency. 2020-02-27 08:17:18 -08:00
Eric Huss a07fec1b7b Provide extra context on a query failure. 2020-02-25 10:17:11 -08:00
Matthias Krüger 1d912002e9 fix most remaining clippy findings (mostly redundant imports) 2020-02-21 12:15:16 +01:00
Eric Huss 90887707ed Copy license-file into package if outside of root. 2020-02-20 13:27:25 -08:00
Matthias Krüger 8245e02924 bump git2 dependencies 2019-12-19 23:29:41 +01:00
Eric Huss 83571aee56 Minor testsuite organization. 2019-11-24 18:42:45 -08:00
Dan Aloni 375a46f18b Merge remote-tracking branch 'origin/master' into custom-profile-pr-rfc 2019-09-18 08:56:13 +03:00
Alex Crichton ebd10526f3 Run rustfmt 2019-09-16 12:00:12 -07:00
Alex Crichton 9115b2c326 Extract support directory to its own crate
Extract out all our test support code to its own standalone crate so it
can be shared between multiple test suites if necessary.
2019-09-16 11:47:09 -07:00
Dan Aloni f0896975be Merge remote-tracking branch 'origin/master' into custom-profile-pr-rfc 2019-09-08 21:43:41 +03:00
Eric Huss 22adaf99b3 Update test to handle user.* git config missing in submodule. 2019-08-13 16:35:04 -07:00
Eric Huss 850a9d4282 Check in package/publish if a git submodule is dirty. 2019-08-13 16:10:22 -07:00
bors 85a52ce20e Auto merge of #7242 - ehuss:vendor-ignore-dot, r=alexcrichton
`cargo vendor`: Don't delete hidden top-level files.

`cargo vendor` (without `--no-delete`) will delete all files in the `vendor/` directory when it starts. This changes it so that it will skip any entries starting with a dot. This allows one to track the vendor directory with a source control system like git.

Closes #7109

(Note: two commits, one is a test change.)
2019-08-13 22:47:50 +00:00
Eric Huss b41c209af3 Bump toml 0.5.3 2019-08-13 14:56:22 -07:00
Eric Huss 3c20a24335 Clean up some git test support functions. 2019-08-12 22:25:36 -07:00
Dan Aloni 27da33c67d Merge remote-tracking branch 'origin/master' into custom-profile-pr-rfc 2019-07-28 09:24:31 +03:00
Eric Huss 00fd31dd9b Clean environment when git-fetch-with-cli is used. 2019-06-29 13:32:21 -07:00
Dan Aloni 87183146d9 Merge remote-tracking branch 'origin/master' into custom-profile-pr-rfc 2019-06-20 16:18:42 +03:00
Jethro Beekman 0e0d968825 Update #[test] attribute on all tests in the testsuite
sed -i 's/^#\[test\]/#[cargo_test]/' $(rg -l '^#\[test\]')

Manual fixes:
* proc_macro::proc_macro_doctest
2019-06-07 12:41:26 -07:00
Dan Aloni e25f6a4255 tests: fix finished line for 'cargo test' 2019-06-07 21:47:45 +03:00
Eric Huss 80b9d329ba Move offline tests to a dedicated file. 2019-04-28 19:45:01 -07:00
Eric Huss bb614d4305 Fix test include_overrides_gitignore. 2019-04-14 11:50:41 -07:00
Eric Huss 1667b75abc Support force-pushed repos with git-fetch-with-cli. 2019-03-31 10:06:23 -07:00
Eric Huss ef0b47769b Cleanup: Remove unnecessary borrows. 2019-03-26 18:09:56 -07:00