Skip to content

Commit aabbf66

Browse files
gate git2 behind feature flag
1 parent 4d7be97 commit aabbf66

File tree

10 files changed

+30
-22
lines changed

10 files changed

+30
-22
lines changed

crates/turborepo-filewatch/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tokio = { workspace = true, features = ["full", "time"] }
2121
tracing = "0.1.37"
2222
turbopath = { workspace = true }
2323
turborepo-repository = { version = "0.1.0", path = "../turborepo-repository" }
24-
turborepo-scm = { workspace = true }
24+
turborepo-scm = { workspace = true, features = ["git2"] }
2525
walkdir = "2.3.3"
2626
wax = { workspace = true }
2727

crates/turborepo-filewatch/src/hash_watcher.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ use tokio::{
1717
use tracing::{debug, trace};
1818
use turbopath::{AbsoluteSystemPathBuf, AnchoredSystemPath, AnchoredSystemPathBuf};
1919
use turborepo_repository::discovery::DiscoveryResponse;
20-
use turborepo_scm::{
21-
package_deps::{GitHashes, INPUT_INCLUDE_DEFAULT_FILES},
22-
Error as SCMError, SCM,
23-
};
20+
use turborepo_scm::{package_deps::INPUT_INCLUDE_DEFAULT_FILES, Error as SCMError, GitHashes, SCM};
2421

2522
use crate::{
2623
debouncer::Debouncer,
@@ -691,7 +688,7 @@ mod tests {
691688
use turbopath::{
692689
AbsoluteSystemPath, AbsoluteSystemPathBuf, AnchoredSystemPathBuf, RelativeUnixPathBuf,
693690
};
694-
use turborepo_scm::{package_deps::GitHashes, SCM};
691+
use turborepo_scm::{GitHashes, SCM};
695692

696693
use super::{FileHashes, HashState};
697694
use crate::{

crates/turborepo-lib/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ turborepo-graph-utils = { path = "../turborepo-graph-utils" }
138138
turborepo-lockfiles = { workspace = true }
139139
turborepo-microfrontends = { workspace = true }
140140
turborepo-repository = { path = "../turborepo-repository" }
141-
turborepo-scm = { workspace = true }
141+
turborepo-scm = { workspace = true, features = ["git2"] }
142142
turborepo-signals = { workspace = true }
143143
turborepo-telemetry = { path = "../turborepo-telemetry" }
144144
turborepo-ui = { workspace = true }

crates/turborepo-scm/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ workspace = true
1111

1212
[dependencies]
1313
bstr = "1.4.0"
14-
git2 = { workspace = true, default-features = false }
14+
git2 = { workspace = true, default-features = false, optional = true }
1515
globwalk = { path = "../turborepo-globwalk" }
1616
hex = { workspace = true }
1717
ignore = "0.4.20"
@@ -28,5 +28,9 @@ wax = { workspace = true }
2828
which = { workspace = true }
2929

3030
[dev-dependencies]
31+
git2 = { workspace = true, default-features = false }
3132
tempfile = { workspace = true }
3233
test-case = "3.1.0"
34+
35+
[features]
36+
git2 = ["dep:git2"]

crates/turborepo-scm/src/hash_object.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
#![cfg(feature = "git2")]
12
use tracing::Span;
23
use turbopath::{AbsoluteSystemPath, AnchoredSystemPathBuf, RelativeUnixPathBuf};
34

4-
use crate::{package_deps::GitHashes, Error};
5+
use crate::{Error, GitHashes};
56

67
#[tracing::instrument(skip(git_root, hashes, to_hash))]
78
pub(crate) fn hash_objects(
@@ -49,7 +50,7 @@ mod test {
4950
use turbopath::{AbsoluteSystemPathBuf, RelativeUnixPathBuf, RelativeUnixPathBufTestExt};
5051

5152
use super::hash_objects;
52-
use crate::{find_git_root, package_deps::GitHashes};
53+
use crate::{find_git_root, GitHashes};
5354

5455
#[test]
5556
fn test_read_object_hashes() {

crates/turborepo-scm/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
use std::{
1111
backtrace::{self, Backtrace},
12+
collections::HashMap,
1213
io::Read,
1314
process::{Child, Command},
1415
};
@@ -27,6 +28,7 @@ mod status;
2728

2829
#[derive(Debug, Error)]
2930
pub enum Error {
31+
#[cfg(feature = "git2")]
3032
#[error("Git error on {1}: {0}")]
3133
Git2(
3234
#[source] git2::Error,
@@ -65,6 +67,8 @@ pub enum Error {
6567
UnableToResolveRef,
6668
}
6769

70+
pub type GitHashes = HashMap<RelativeUnixPathBuf, String>;
71+
6872
impl From<wax::BuildError> for Error {
6973
fn from(value: wax::BuildError) -> Self {
7074
Error::Glob(Box::new(value), Backtrace::capture())
@@ -76,6 +80,7 @@ impl Error {
7680
Error::Git(s.into(), Backtrace::capture())
7781
}
7882

83+
#[cfg(feature = "git2")]
7984
pub(crate) fn git2_error_context(error: git2::Error, error_context: String) -> Self {
8085
Error::Git2(error, error_context, Backtrace::capture())
8186
}

crates/turborepo-scm/src/ls_tree.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
use nom::Finish;
77
use turbopath::{AbsoluteSystemPathBuf, RelativeUnixPathBuf};
88

9-
use crate::{package_deps::GitHashes, wait_for_success, Error, Git};
9+
use crate::{wait_for_success, Error, Git, GitHashes};
1010

1111
impl Git {
1212
#[tracing::instrument(skip(self))]
@@ -82,7 +82,7 @@ mod tests {
8282

8383
use turbopath::RelativeUnixPathBuf;
8484

85-
use crate::{ls_tree::read_ls_tree, package_deps::GitHashes};
85+
use crate::{ls_tree::read_ls_tree, GitHashes};
8686

8787
fn to_hash_map(pairs: &[(&str, &str)]) -> GitHashes {
8888
HashMap::from_iter(

crates/turborepo-scm/src/manual.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use sha1::{Digest, Sha1};
77
use turbopath::{AbsoluteSystemPath, AnchoredSystemPath, IntoUnix};
88
use wax::{any, Glob, Program};
99

10-
use crate::{package_deps::GitHashes, Error};
10+
use crate::{Error, GitHashes};
1111

1212
fn git_like_hash_file(path: &AbsoluteSystemPath) -> Result<String, Error> {
1313
let mut hasher = Sha1::new();

crates/turborepo-scm/src/package_deps.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
use std::{collections::HashMap, str::FromStr};
1+
#![cfg(feature = "git2")]
2+
use std::str::FromStr;
23

34
use globwalk::ValidatedGlob;
45
use tracing::debug;
5-
use turbopath::{AbsoluteSystemPath, AnchoredSystemPath, PathError, RelativeUnixPathBuf};
6+
use turbopath::{AbsoluteSystemPath, AnchoredSystemPath, PathError};
67
use turborepo_telemetry::events::task::{FileHashMethod, PackageTaskEventBuilder};
78

8-
use crate::{hash_object::hash_objects, Error, Git, SCM};
9-
10-
pub type GitHashes = HashMap<RelativeUnixPathBuf, String>;
9+
#[cfg(feature = "git2")]
10+
use crate::hash_object::hash_objects;
11+
use crate::{Error, Git, GitHashes, SCM};
1112

1213
pub const INPUT_INCLUDE_DEFAULT_FILES: &str = "$TURBO_DEFAULT$";
1314

@@ -291,9 +292,9 @@ impl Git {
291292

292293
#[cfg(test)]
293294
mod tests {
294-
use std::{assert_matches::assert_matches, process::Command};
295+
use std::{assert_matches::assert_matches, collections::HashMap, process::Command};
295296

296-
use turbopath::{AbsoluteSystemPathBuf, AnchoredSystemPathBuf};
297+
use turbopath::{AbsoluteSystemPathBuf, AnchoredSystemPathBuf, RelativeUnixPathBuf};
297298

298299
use super::*;
299300
use crate::manual::get_package_file_hashes_without_git;

crates/turborepo-scm/src/status.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
use nom::Finish;
77
use turbopath::{AbsoluteSystemPath, RelativeUnixPathBuf};
88

9-
use crate::{package_deps::GitHashes, wait_for_success, Error, Git};
9+
use crate::{wait_for_success, Error, Git, GitHashes};
1010

1111
impl Git {
1212
#[tracing::instrument(skip(self, root_path, hashes))]
@@ -111,7 +111,7 @@ mod tests {
111111
use turbopath::{AbsoluteSystemPathBuf, RelativeUnixPathBuf, RelativeUnixPathBufTestExt};
112112

113113
use super::read_status;
114-
use crate::package_deps::GitHashes;
114+
use crate::GitHashes;
115115

116116
#[test]
117117
fn test_status() {

0 commit comments

Comments
 (0)