Repository: rust-lang/cargo (rust)

Issue:
Why does cargo need to download git dependencies completely?
### Problem

Why does cargo need to download git dependencies completely? 


```
(base) [root@x86 ~]#  cargo check

    Updating git repository `https://code.com/base/cbb-rs.git`
remote: Enumerating objects: 935, done.
remote: Counting objects: 100% (40/40), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 935 (delta 35), reused 30 (delta 30), pack-reused 895 (from 1)
Receiving objects: 100% (935/935), 239.33 KiB | 633.00 KiB/s, done.
Resolving deltas: 100% (346/346), done.
From https://code.com/base/cbb-rs
 * [new branch]      1.x       -> origin/1.x
 * [new branch]      2.x        -> origin/2.x
 * [new branch]      master                       -> origin/master
 * [new ref]                                      -> origin/HEAD
 * [new tag]         1.0.0                        -> 1.0.0
 * [new tag]         1.0.1                        -> 1.0.1
 * [new tag]         1.0.10                       -> 1.0.10
 * [new tag]         1.0.2                        -> 1.0.2
 * [new tag]         1.0.3                        -> 1.0.3
 * [new tag]         1.0.6                        -> 1.0.6
 * [new tag]         1.0.8                        -> 1.0.8
 * [new tag]         1.0.9                        -> 1.0.9
 * [new tag]         2.0.0                        -> 2.0.0
 * [new tag]         2.0.1                        -> 2.0.1
 * [new tag]         2.0.2                        -> 2.0.2
 * [new tag]         2.0.3                        -> 2.0.3
 * [new tag]         2.0.4                        -> 2.0.4
 * [new tag]         2.0.5                        -> 2.0.5
 * [new tag]         2.0.6                        -> 2.0.6
 * [new tag]         2.0.7                        -> 2.0.7
 * [new tag]         2.0.8                        -> 2.0.8
 * [new tag]         2.0.9                        -> 2.0.9
 * [new tag]         2.1.0                        -> 2.1.0
```

### Proposed Solution

Set `depth=1` when git is used for download.

### Notes

_No response_

Pull request description:
fix(git): dont fetch tags by default
### What does this PR try to resolve?

Change Cargo to pass [`--no-tags`] Git CLI option by default. This aligns with how libgit2 works in Cargo.

Based on the Git official doc,
the flag has been there since at least 2.0.5

[`--no-tags`]: https://git-scm.com/docs/git-fetch/2.0.5#Documentation/git-fetch.txt---no-tags

### How should we test and review this PR?

Not sure if we want a test for this.
`CARGO_NET_GIT_FETCH_WITH_CLI` is barely tested.

### Additional information

Fixes #14687

Patch:
diff --git a/src/cargo/sources/git/utils.rs b/src/cargo/sources/git/utils.rs
index 844a4dcf5..f9b2f582c 100644
--- a/src/cargo/sources/git/utils.rs
+++ b/src/cargo/sources/git/utils.rs
@@ -1193,6 +1193,8 @@ fn fetch_with_cli(
     cmd.arg("fetch");
     if tags {
         cmd.arg("--tags");
+    } else {
+        cmd.arg("--no-tags");
     }
     match gctx.shell().verbosity() {
         Verbosity::Normal => {}


Test patch:
diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs
index 0fd25bf2d..6bc72423c 100644
--- a/tests/testsuite/git.rs
+++ b/tests/testsuite/git.rs
@@ -2954,7 +2954,7 @@ fn use_the_cli() {
 
     let stderr = str![[r#"
 [UPDATING] git repository `[ROOTURL]/dep1`
-[RUNNING] `git fetch --verbose --force --update-head-ok [..][ROOTURL]/dep1[..] [..]+HEAD:refs/remotes/origin/HEAD[..]`
+[RUNNING] `git fetch --no-tags --verbose --force --update-head-ok [..][ROOTURL]/dep1[..] [..]+HEAD:refs/remotes/origin/HEAD[..]`
 From [ROOTURL]/dep1
  * [new ref] [..] -> origin/HEAD[..]
 [LOCKING] 1 package to latest compatible version