Commit Graph

178 Commits

Author SHA1 Message Date
Eric Huss 888100352a Move ProcessBuilder to cargo-util. 2021-03-20 15:19:03 -07: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
Matthias Krüger c4e5670bdb Fix more clippy warnings;
clippy::comparison_to_empty
clippy::needless_question_mark
clippy::needless_borrow
clippy::match_like_matches_macro
clippy::vec_init_then_push
clippy::redundant_clone
clippy::nonminimal_bool
clippy::ptr_arg
2021-01-06 15:15:22 +01:00
Eric Huss d5541331cf Some minor clippy fixes. 2020-10-22 10:40:16 -07:00
Eric Huss 3bbb44c76a Reinitialize index on "Object not found" error. 2020-09-25 13:44:49 -07:00
Matthias Krüger f23b91190c use sort_by_key() instead of comparing by keys manually
replace format!() macro by String::from()
use eprintln() instead of manually writing to std::io::stderr
2020-08-03 22:52:01 +02:00
Alex Crichton 7f65cae857 Tweak wording of comment 2020-07-23 08:35:01 -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
Alexis Beingessner 4a1e71072d Mask out system core.autocrlf settings before resetting git repos
This fixes an issue the gecko developers noticed when vendoring
on windows. [0] If a user has `core.autocrlf=true` set
(a reasonable default on windows), vendoring from a git source
would cause all the newlines to be rewritten to include carriage
returns, creating churn and platform-specific results.

To fix this, we simply set the global cargo checkout's "local"
core.autocrlf value before performing a `reset`. This masks out
the system configuration without interfering with the user's
own system/project settings.

[0]:  https://bugzilla.mozilla.org/show_bug.cgi?id=1647582
2020-07-21 12:38:03 -04:00
Matthias Krüger 833ad21d49 fix clippy warnings 2020-07-17 12:31:45 +02:00
bors 8fc3da5e4a Auto merge of #8409 - alexcrichton:git-instead-of, r=Eh2406
Improve git error messages a bit

This commit is targeted at further improving the error messages
generated from git errors. For authentication errors the actual URL
fetched is now printed out as well if it's different from the original
URL. This should help handle `insteadOf` logic where SSH urls are used
instead of HTTPS urls and users can know to track that down.

Otherwise the logic about recommending `net.git-fetch-with-cli` was
tweaked a bit and moved to the same location as the rest of our error
reporting.

Note that a change piggy-backed here as well is that `Caused by:` errors
are now automatically all tabbed over a bit instead of only having the
first line tabbed over. This required a good number of tests to be
updated, but it's just an updated in renderings.
2020-06-25 18:47:08 +00:00
Alex Crichton 6514c289d2 Improve git error messages a bit
This commit is targeted at further improving the error messages
generated from git errors. For authentication errors the actual URL
fetched is now printed out as well if it's different from the original
URL. This should help handle `insteadOf` logic where SSH urls are used
instead of HTTPS urls and users can know to track that down.

Otherwise the logic about recommending `net.git-fetch-with-cli` was
tweaked a bit and moved to the same location as the rest of our error
reporting.

Note that a change piggy-backed here as well is that `Caused by:` errors
are now automatically all tabbed over a bit instead of only having the
first line tabbed over. This required a good number of tests to be
updated, but it's just an updated in renderings.
2020-06-25 08:47:15 -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
Alex Crichton 437e5d7ee1 Strip `.git` from urls on GitHub fast-path 2020-06-16 08:31:19 -07:00
Alex Crichton 869642bb09 Cut down on data fetch from git dependencies
Currently Cargo pretty heavily over-approximates data fetch for git
dependencies. For the index it fetches precisely one branch, but for all
other git dependencies Cargo will fetch all branches and all tags all
the time. In each of these situations, however, Cargo knows if one
branch is desired or if only one tag is desired.

This commit updates Cargo's fetching logic to plumb the desired
`GitReference` all the way down to `fetch`. In that one location we then
determine what to fetch. Namely if a branch or tag is explicitly
selected then we only fetch that one reference from the remote, cutting
down on the amount of traffic to the git remote.

Additionally a bugfix included here is that the GitHub fast path for
checking if a repository is up-to-date now works for non-`master`-based
branch dependencies.
2020-06-16 08:01:33 -07:00
Eric Huss ce86e866e9 Add context to some fs errors. 2020-05-11 14:10:10 -07:00
Kornel Lesiński 4fd483507a Hint git-fetch-with-cli on git errors 2020-05-03 18:13:42 +01:00
dylan_DPC ee98c3517c remove mem replace instead 2020-04-20 15:40:41 +02:00
dylan_DPC a06744b3e8 fix mem replace unused 2020-04-20 15:08:26 +02:00
Eric Huss 2fa95e3ec4 Add "Updating" status for git submodules. 2020-03-11 18:37:31 -07:00
Eric Huss 0d44a8267b Rework internal errors. 2020-02-17 19:03:57 -08:00
Alex Crichton 3a18c89a55 Migrate from the `failure` crate to `anyhow`
The `anyhow` crate interoperates with the `std::error::Error` trait
rather than a custom `Fail` trait, and this is the general trend of
error handling in Rust as well.

Note that this is mostly mechanical (sed) and intended to get the test
suite passing. As usual there's still more idiomatic cleanup that can
happen, but that's left to later commits.
2020-01-07 16:50:09 -08:00
Alex Crichton 8d659063e5 Consolidate `net` configuration into a typed structure
Less need for `get_bool` and friends!
2019-10-07 17:12:03 -07:00
Alex Crichton 5102de2b7d Improve error messages on mkdir failure
This commit ensures that `fs::create_dir*` isn't called throughout Cargo
and is instead routed through our own wrapper `paths::create_dir_all`
which brings with it a few benefits:

* Gracefully handles when the directory already exists (which is the
  behavior we always want anyway)
* Includes the path name in the error message of what failed
* Handles races of creating a directory by default

Closes #7304
2019-08-27 13:52:15 -07:00
Matthias Krüger 61c1b1ca86 fix a bunch of clippy warnings 2019-08-19 17:57:57 +02:00
Eric Huss 04008795f9 Allow git dependency with shorthand ssh submodules to work. 2019-08-11 18:13:04 -07:00
Eric Huss 00fd31dd9b Clean environment when git-fetch-with-cli is used. 2019-06-29 13:32:21 -07:00
Jeremy Stucki 2415a2980f
Make rustfmt happy 2019-06-20 18:23:55 +02:00
Jeremy Stucki 930134c75b
Rename to_url -> into_url 2019-06-20 16:53:24 +02:00
Matthias Krüger b4cd609579 fix more typos (codespell) 2019-05-03 14:22:11 +02:00
Matthias Krüger 2b41dd4a4f fix typo (superfluous "o" after period). 2019-04-25 20:22:46 +02:00
Alex Crichton f16efff150 Run `cargo fmt` 2019-04-10 10:42:07 -07:00
Eric Huss 1667b75abc Support force-pushed repos with git-fetch-with-cli. 2019-03-31 10:06:23 -07:00
bors dc83ead224 Auto merge of #6687 - dwijnand:cosmetic-2, r=dwijnand
Various cosmetic improvements

Resubmit of #6673 which, somehow, broke.
cc @alexreg
2019-02-20 11:34:33 +00:00
Alexander Regueiro f7c91ba622
Various cosmetic improvements. 2019-02-20 10:58:27 +00:00
Harry Marr 96ab67b847 Add comment and reuse existing variable 2019-02-19 11:48:36 -05:00
Harry Marr 08d3fcca91 Don't retry git credential helpers
If the git credential helper returns invalid credentials, we currently
get stuck in an infinite retry loop by calling the credentials callback
over and over, each time returning the same invalid credentials. This
change means we only invoke the credential helper once.
2019-02-19 10:22:02 -05:00
Dale Wijnand 54c4214251
Remove trailing extern crate usage 2018-12-13 15:21:32 +00:00
Dale Wijnand 920d552750
Replace CargoError with failure::Error 2018-12-12 23:25:08 +00:00
Alex Crichton b8b7faee50 Run `cargo fix --edition-idioms` and fixup output
This gets Cargo passing the `--edition-idioms` lints and more down the
road of the 2018 edition!
2018-12-11 05:45:46 -08:00
Alex Crichton 9ed82b5779 Start using 2018 idioms in Cargo
Remove a number of `extern crate` directives and tweak a number of
imports. Not all `extern crate` is gone yet but this is the bulk of
them!
2018-12-11 05:45:46 -08:00
Alex Crichton fecb724643 Format with `cargo fmt` 2018-12-08 03:19:47 -08:00
Dale Wijnand 04ddd4d0fc
Upgrade to Rust 2018 2018-12-06 20:18:35 +01:00
bors 5998a46f0f Auto merge of #6250 - alexcrichton:more-flags, r=dwijnand
Pass `--update-head-ok` when fetching via git CLI

Discovered in a recent [comment] it looks like not passing this may
cause the git CLI to fail in some situations.

[comment]: https://github.com/rust-lang/cargo/issues/2078#issuecomment-435333292
2018-11-02 21:50:52 +00:00
Alex Crichton 2a4cdc677c Never use templates when managing git repos
This commit disables usage of git templates whenever Cargo manages
repositories in its internal git database. Templates don't want to be
used at all in these situations and have been known to cause usability
bugs.

Closes #6240
2018-11-02 11:50:04 -07:00
Alex Crichton e307f047a0 Pass `--update-head-ok` when fetching via git CLI
Discovered in a recent [comment] it looks like not passing this may
cause the git CLI to fail in some situations.

[comment]: https://github.com/rust-lang/cargo/issues/2078#issuecomment-435333292
2018-11-02 07:07:48 -07:00
Alex Crichton a0591eeac1 Add a configuration option to fetch with git-the-CLI
Currently Cargo always uses `libgit2` to perform all fetches of git
repositories, but sometimes this is not sufficient. The `libgit2` library
doesn't support all authentication schemes that `git` does and it isn't always
quite at feature parity with `git` itself, especially in terms of network
configuration.

This commit adds a configuration option to Cargo for fetching git repositories
with the `git` CLI tool rather than the internal `libgit2`. While this exposes
us to changes over time in the `git` CLI it's hopefully a very targeted use case
that doesn't change much. The internal `libgit2` library should be sufficient
for all other forms of git repository management. (and using `git` for only
fetches shouldn't slow us down much)

The new configuration option in `.cargo/config` is:

    [net]
    git-fetch-with-cli = true

which can also be specified with `CARGO_NET_GIT_FETCH_WITH_CLI=true` via an
environment variable.

Closes #5903
2018-08-21 09:09:20 -07:00