Skip to content

Commit

Permalink
Added test for shallow cloned repo
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Apr 17, 2023
1 parent 9b2e848 commit d7c0598
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/turborepo-scm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ thiserror = { workspace = true }
turbopath = { workspace = true }

[dev-dependencies]
git2 = { version = "0.16.1", default-features = false }
tempfile = { workspace = true }
39 changes: 34 additions & 5 deletions crates/turborepo-scm/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,9 @@ mod tests {

use git2::{Oid, Repository};
use tempfile::TempDir;
use turbopath::AbsoluteSystemPathBuf;

use super::previous_content;
use crate::{
git::{changed_files, reanchor_path_from_git_root_to_turbo_root},
Error,
};
use crate::{git::changed_files, Error};

fn setup_repository() -> Result<(TempDir, Repository), Error> {
let repo_root = tempfile::tempdir()?;
Expand Down Expand Up @@ -208,6 +204,39 @@ mod tests {
)?)
}

#[test]
fn test_shallow_clone() -> Result<(), Error> {
let tmp_dir = tempfile::tempdir()?;
let output = Command::new("git")
.args(&[
"clone",
"--depth",
"2",
"https://github.com/vercel/app-playground.git",
tmp_dir.path().to_str().unwrap(),
])
.output()?;
assert!(output.status.success());

assert!(changed_files(
tmp_dir.path().to_owned(),
tmp_dir.path().to_owned(),
Some("HEAD~1"),
"HEAD",
)
.is_ok());

assert!(changed_files(
tmp_dir.path().to_owned(),
tmp_dir.path().to_owned(),
None,
"HEAD",
)
.is_ok());

Ok(())
}

#[test]
fn test_deleted_files() -> Result<(), Error> {
let (repo_root, repo) = setup_repository()?;
Expand Down
2 changes: 2 additions & 0 deletions crates/turborepo-scm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub mod git;

#[derive(Debug, Error)]
pub enum Error {
#[error("git error: {0}")]
Git(#[from] git2::Error),
#[error("repository not found")]
RepositoryNotFound,
#[error("io error: {0}")]
Expand Down

0 comments on commit d7c0598

Please sign in to comment.