这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/turborepo-paths/src/absolute_system_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ impl AbsoluteSystemPath {
fs::create_dir_all(&self.0)
}

pub fn remove_dir_all(&self) -> Result<(), io::Error> {
fs::remove_dir_all(&self.0)
}

pub fn extension(&self) -> Option<&str> {
self.0.extension()
}
Expand Down
47 changes: 45 additions & 2 deletions crates/turborepo-scm/src/package_deps.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;

use itertools::{Either, Itertools};
use tracing::debug;
use turbopath::{AbsoluteSystemPath, AnchoredSystemPathBuf, PathError, RelativeUnixPathBuf};

use crate::{hash_object::hash_objects, Error, Git, SCM};
Expand All @@ -20,7 +21,19 @@ impl SCM {
package_path,
inputs,
),
SCM::Git(git) => git.get_package_file_hashes(turbo_root, package_path, inputs),
SCM::Git(git) => git
.get_package_file_hashes(turbo_root, package_path, inputs)
.or_else(|e| {
debug!(
"failed to use git to hash files: {}. Falling back to manual",
e
);
crate::manual::get_package_file_hashes_from_processing_gitignore(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I carefully moved a lot of this fallback into "application" code inside of Go because doing the fallback lower-level caused the "we have three different ways that we hash files which are only mostly-compatible" situation.

I'd much prefer to hoist this back into application code out of scm.

turbo_root,
package_path,
inputs,
)
}),
}
}

Expand Down Expand Up @@ -155,7 +168,7 @@ impl Git {

#[cfg(test)]
mod tests {
use std::{collections::HashMap, process::Command};
use std::{assert_matches::assert_matches, collections::HashMap, process::Command};

use turbopath::{AbsoluteSystemPathBuf, RelativeUnixPathBuf};

Expand Down Expand Up @@ -218,6 +231,36 @@ mod tests {
assert!(manual_hashes.is_empty());
}

#[test]
fn test_get_package_deps_fallback() {
let (_repo_root_tmp, repo_root) = tmp_dir();
let my_pkg_dir = repo_root.join_component("my-pkg");
my_pkg_dir.create_dir_all().unwrap();

// create file 1
let committed_file_path = my_pkg_dir.join_component("committed-file");
committed_file_path
.create_with_contents("committed bytes")
.unwrap();

setup_repository(&repo_root);
commit_all(&repo_root);
let git = SCM::new(&repo_root);
assert_matches!(git, SCM::Git(_));
// Remove the .git directory to trigger an error in git hashing
repo_root.join_component(".git").remove_dir_all().unwrap();
let pkg_path = repo_root.anchor(&my_pkg_dir).unwrap();
let hashes = git
.get_package_file_hashes::<&str>(&repo_root, &pkg_path, &[])
.unwrap();
let mut expected = GitHashes::new();
expected.insert(
RelativeUnixPathBuf::new("committed-file").unwrap(),
"3a29e62ea9ba15c4a4009d1f605d391cdd262033".to_string(),
);
assert_eq!(hashes, expected);
}

#[test]
fn test_get_package_deps() -> Result<(), Error> {
// Directory structure:
Expand Down