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
9 changes: 6 additions & 3 deletions crates/prek/src/cli/run/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ impl IntentToAddRestorer {
fn restore(&self) -> Result<()> {
// Restore the intent-to-add changes.
if !self.0.is_empty() {
Command::new(GIT.as_ref()?)
let mut cmd = Command::new(GIT.as_ref()?);
git::apply_git_work_tree(&mut cmd)
.arg("add")
.arg("--intent-to-add")
.arg("--")
Expand Down Expand Up @@ -154,7 +155,8 @@ impl UnstagedChangesRestorer {
}

fn checkout_working_tree(root: &Path) -> Result<()> {
let output = Command::new(GIT.as_ref()?)
let mut cmd = Command::new(GIT.as_ref()?);
let output = git::apply_git_work_tree(&mut cmd)
.arg("-c")
.arg("submodule.recurse=0")
.arg("checkout")
Expand All @@ -173,7 +175,8 @@ impl UnstagedChangesRestorer {
}

fn git_apply(patch: &Path) -> Result<()> {
let output = Command::new(GIT.as_ref()?)
let mut cmd = Command::new(GIT.as_ref()?);
let output = git::apply_git_work_tree(&mut cmd)
.arg("apply")
.arg("--whitespace=nowarn")
.arg(patch)
Expand Down
42 changes: 22 additions & 20 deletions crates/prek/src/cli/update/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use semver::Version;
use tracing::{debug, trace};

use crate::cli::update::{CommitPresence, RevisionSelection, SkippedDowngrade, TagTimestamp};
use crate::git::GitCommandExt;
use crate::{config, git};

/// Initializes a temporary git repo and fetches the remote HEAD plus tags.
Expand All @@ -27,7 +28,7 @@ pub(super) async fn setup_and_fetch_repo(repo_url: &str, repo_path: &Path) -> Re
.arg("--filter=blob:none")
.arg("--tags")
.current_dir(repo_path)
.remove_git_envs()
.isolate_from_git_env()
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
Expand All @@ -43,7 +44,7 @@ pub(super) async fn resolve_revision_to_commit(repo_path: &Path, rev: &str) -> R
.arg(format!("{rev}^{{}}"))
.check(true)
.current_dir(repo_path)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await?;

Expand Down Expand Up @@ -83,7 +84,7 @@ pub(super) async fn is_commit_present(repo_path: &Path, commit: &str) -> Result<
.env(EnvVars::LC_ALL, "C")
.check(false)
.current_dir(repo_path)
.remove_git_envs()
.isolate_from_git_env()
.stdout(Stdio::null())
.output()
.await?;
Expand Down Expand Up @@ -127,7 +128,7 @@ pub(super) async fn resolve_bleeding_edge(repo_path: &Path) -> Result<Option<Str
.arg("--exact-match")
.check(false)
.current_dir(repo_path)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await?;
let rev = if output.status.success() {
Expand All @@ -139,7 +140,7 @@ pub(super) async fn resolve_bleeding_edge(repo_path: &Path) -> Result<Option<Str
.arg("FETCH_HEAD")
.check(true)
.current_dir(repo_path)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await?;
String::from_utf8_lossy(&output.stdout).trim().to_string()
Expand All @@ -161,7 +162,7 @@ pub(super) async fn list_tag_metadata(repo: &Path) -> Result<Vec<TagTimestamp>>
.arg("refs/tags")
.check(true)
.current_dir(repo)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await?;

Expand Down Expand Up @@ -380,7 +381,7 @@ pub(super) async fn checkout_and_validate_manifest(
.arg("show")
.arg(format!("{rev}:{PRE_COMMIT_HOOKS_YAML}"))
.current_dir(repo_path)
.remove_git_envs()
.isolate_from_git_env()
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
Expand All @@ -394,7 +395,7 @@ pub(super) async fn checkout_and_validate_manifest(
.arg("--")
.arg(PRE_COMMIT_HOOKS_YAML)
.current_dir(repo_path)
.remove_git_envs()
.isolate_from_git_env()
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
Expand Down Expand Up @@ -431,6 +432,7 @@ mod tests {
};
use crate::cli::update::{RevisionSelection, SkippedDowngrade};
use crate::git;
use crate::git::GitCommandExt;
use crate::process::Cmd;
use std::path::Path;
use std::time::{SystemTime, UNIX_EPOCH};
Expand All @@ -443,7 +445,7 @@ mod tests {
.unwrap()
.arg("init")
.current_dir(repo)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await
.unwrap();
Expand All @@ -452,7 +454,7 @@ mod tests {
.unwrap()
.args(["config", "user.email", "[email protected]"])
.current_dir(repo)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await
.unwrap();
Expand All @@ -461,7 +463,7 @@ mod tests {
.unwrap()
.args(["config", "user.name", "Test"])
.current_dir(repo)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await
.unwrap();
Expand All @@ -477,7 +479,7 @@ mod tests {
"initial",
])
.current_dir(repo)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await
.unwrap();
Expand All @@ -486,7 +488,7 @@ mod tests {
.unwrap()
.args(["branch", "-M", "trunk"])
.current_dir(repo)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await
.unwrap();
Expand Down Expand Up @@ -522,7 +524,7 @@ mod tests {
async fn create_commit(repo: &Path, message: &str) {
git_cmd(repo)
.args(["commit", "--allow-empty", "-m", message])
.remove_git_envs()
.isolate_from_git_env()
.output()
.await
.unwrap();
Expand All @@ -541,7 +543,7 @@ mod tests {
.args(["commit", "--allow-empty", "-m", message])
.env("GIT_AUTHOR_DATE", &date_str)
.env("GIT_COMMITTER_DATE", &date_str)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await
.unwrap();
Expand All @@ -551,7 +553,7 @@ mod tests {
git_cmd(repo)
.arg("tag")
.arg(tag)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await
.unwrap();
Expand All @@ -573,7 +575,7 @@ mod tests {
.arg(tag)
.env("GIT_AUTHOR_DATE", &date_str)
.env("GIT_COMMITTER_DATE", &date_str)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await
.unwrap();
Expand Down Expand Up @@ -611,7 +613,7 @@ mod tests {
.unwrap()
.args(["fetch", ".", "HEAD"])
.current_dir(repo)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await
.unwrap();
Expand All @@ -631,7 +633,7 @@ mod tests {
.unwrap()
.args(["fetch", ".", "HEAD"])
.current_dir(repo)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await
.unwrap();
Expand All @@ -642,7 +644,7 @@ mod tests {
.unwrap()
.args(["rev-parse", "HEAD"])
.current_dir(repo)
.remove_git_envs()
.isolate_from_git_env()
.output()
.await
.unwrap()
Expand Down
Loading
Loading