Repository: rust-lang/cargo (rust)

Issue:
Unimplemented short keyword: '_' when Cargo.toml under path starting with _
### Problem

Since `rust-1.79` we have been unable to build packages that include `build.rs` within our rust workspace with cargo due to the following error.
```
error: failed to determine package fingerprint for build script for foo v0.1.0 (/Users/jemtucker/src/mvp/_code/rust/foo)

Caused by:
  failed to determine the most recently modified file in /Users/jemtucker/src/mvp/_code/rust/foo

Caused by:
  failed to determine list of files in /Users/jemtucker/src/mvp/_code/rust/foo

Caused by:
  Unimplemented short keyword: '_'
```

Our directory structure is as follows.
```
.git/...
_code/rust/Cargo.toml
_code/rust/foo/Cargo.toml
_code/rust/foo/build.rs
_code/rust/foo/src/lib.rs
```

This error occurs when gitoxide is attempting to parse pathspecs of the form `:/_code/rust` and `:!/_code/rust` which are invalid. 

The fix is to use the non-shorthand pathspec keywords e.g. `:(top)_code/rust`.

### Steps

_No response_

### Possible Solution(s)

_No response_

### Notes

_No response_

### Version

_No response_

Pull request description:
Use longhand gitoxide path-spec patterns
Closes #14379 

Patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 2529295dc..f506d8f55 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -140,17 +140,17 @@ jobs:
           os: ubuntu-latest
           rust: nightly
           other: i686-unknown-linux-gnu
-        - name: macOS aarch64 stable
-          os: macos-14
+        - name: macOS x86_64 stable
+          os: macos-13
           rust: stable
-          other: x86_64-apple-darwin
+          other: x86_64-apple-ios
         - name: macOS x86_64 nightly
           os: macos-13
           rust: nightly
           other: x86_64-apple-ios
-        - name: macOS aarch64 nightly
+        - name: macOS aarch64 stable
           os: macos-14
-          rust: nightly
+          rust: stable
           other: x86_64-apple-darwin
         - name: Windows x86_64 MSVC stable
           os: windows-latest
diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs
index 4159da352..d4acb1d20 100644
--- a/src/cargo/sources/path.rs
+++ b/src/cargo/sources/path.rs
@@ -610,11 +610,11 @@ fn list_files_gix(
 
     let pathspec = {
         // Include the package root.
-        let mut include = BString::from(":/");
+        let mut include = BString::from(":(top)");
         include.push_str(package_prefix.as_ref());
 
         // Exclude the target directory.
-        let mut exclude = BString::from(":!/");
+        let mut exclude = BString::from(":!(exclude,top)");
         exclude.push_str(target_prefix.as_ref());
 
         vec![include, exclude]


Test patch:
diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs
index 04af014da..4cd3584bf 100644
--- a/tests/testsuite/build_script.rs
+++ b/tests/testsuite/build_script.rs
@@ -14,7 +14,7 @@ use cargo_test_support::tools;
 use cargo_test_support::{
     basic_manifest, cargo_exe, cross_compile, is_coarse_mtime, project, project_in,
 };
-use cargo_test_support::{rustc_host, sleep_ms, slow_cpu_multiplier, symlink_supported};
+use cargo_test_support::{git, rustc_host, sleep_ms, slow_cpu_multiplier, symlink_supported};
 use cargo_util::paths::{self, remove_dir_all};
 
 #[cargo_test]
@@ -5814,3 +5814,25 @@ fn links_overrides_with_target_applies_to_host() {
 "#]])
         .run();
 }
+
+#[cargo_test]
+fn directory_with_leading_underscore() {
+    let p: cargo_test_support::Project = git::new("foo", |p| {
+        p.no_manifest()
+            .file(
+                "_foo/foo/Cargo.toml",
+                r#"
+                [package]
+                name = "foo"
+                version = "0.1.0"
+                edition = "2021"
+                build = "build.rs"
+            "#,
+            )
+            .file("_foo/foo/src/main.rs", "fn main() {}")
+            .file("_foo/foo/build.rs", "fn main() { }")
+    });
+    p.cargo("build --manifest-path=_foo/foo/Cargo.toml -v")
+        .with_status(0)
+        .run();
+}