summaryrefslogtreecommitdiff
path: root/src/git.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/git.rs')
-rw-r--r--src/git.rs71
1 files changed, 46 insertions, 25 deletions
diff --git a/src/git.rs b/src/git.rs
index 2193add..abbf701 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -1,8 +1,8 @@
use anyhow::{Context as _, Result, bail};
+use log::{debug, error, info, warn};
use std::path::Path;
use std::time::Duration;
use tokio::process::Command;
-use tracing::{debug, error, info, warn};
/// Default timeout for git operations (used when not configured).
pub const GIT_TIMEOUT_DEFAULT: Duration = Duration::from_secs(60);
@@ -104,10 +104,15 @@ pub async fn sync_repo(
pull(clone_dir, branch, timeout, depth).await?;
} else if let Err(e) = clone(repo_url, branch, clone_dir, timeout, depth).await {
if clone_dir.exists() {
- warn!(path = %clone_dir.display(), "cleaning up partial clone after failure");
+ warn!(
+ "cleaning up partial clone after failure: {}",
+ clone_dir.display()
+ );
if let Err(cleanup_err) = tokio::fs::remove_dir_all(clone_dir).await {
- error!(path = %clone_dir.display(), error = %cleanup_err,
- "failed to clean up partial clone");
+ error!(
+ "failed to clean up partial clone: path={} error={cleanup_err}",
+ clone_dir.display()
+ );
}
}
return Err(e);
@@ -142,12 +147,18 @@ pub async fn has_remote_changes(
) -> Result<bool> {
// If clone directory doesn't exist, treat as "needs update"
if !clone_dir.exists() {
- debug!(path = %clone_dir.display(), "clone directory does not exist, needs initial clone");
+ debug!(
+ "clone directory does not exist, needs initial clone: {}",
+ clone_dir.display()
+ );
return Ok(true);
}
// Fetch from remote (update refs only, no working tree changes)
- debug!(path = %clone_dir.display(), branch, "fetching remote refs");
+ debug!(
+ "fetching remote refs: path={} branch={branch}",
+ clone_dir.display()
+ );
let depth_str = depth.to_string();
let mut fetch_args = vec!["fetch"];
if depth > 0 {
@@ -165,10 +176,8 @@ pub async fn has_remote_changes(
let remote_head = get_commit_hash(clone_dir, &remote_ref).await?;
debug!(
- path = %clone_dir.display(),
- local = %local_head,
- remote = %remote_head,
- "comparing commits"
+ "comparing commits: path={} local={local_head} remote={remote_head}",
+ clone_dir.display()
);
Ok(local_head != remote_head)
@@ -198,7 +207,10 @@ async fn clone(
timeout: Duration,
depth: u32,
) -> Result<()> {
- info!(repo_url, branch, path = %clone_dir.display(), "cloning repository");
+ info!(
+ "cloning repository: repo={repo_url} branch={branch} path={}",
+ clone_dir.display()
+ );
// Create parent directory if needed
if let Some(parent) = clone_dir.parent() {
@@ -218,12 +230,15 @@ async fn clone(
args.push(clone_dir_str.as_str());
run_git(&args, None, timeout, "git clone").await?;
- debug!(path = %clone_dir.display(), "clone completed");
+ debug!("clone completed: {}", clone_dir.display());
Ok(())
}
async fn pull(clone_dir: &Path, branch: &str, timeout: Duration, depth: u32) -> Result<()> {
- info!(branch, path = %clone_dir.display(), "pulling latest changes");
+ info!(
+ "pulling latest changes: branch={branch} path={}",
+ clone_dir.display()
+ );
// Fetch from origin (shallow or full depending on depth)
let depth_str = depth.to_string();
@@ -245,7 +260,7 @@ async fn pull(clone_dir: &Path, branch: &str, timeout: Duration, depth: u32) ->
)
.await?;
- debug!(path = %clone_dir.display(), "pull completed");
+ debug!("pull completed: {}", clone_dir.display());
Ok(())
}
@@ -292,7 +307,7 @@ async fn has_lfs_pointers(clone_dir: &Path) -> Result<bool> {
continue;
};
if content.starts_with(LFS_POINTER_SIGNATURE) {
- debug!(file = %file_path, "found LFS pointer");
+ debug!("found LFS pointer: {file_path}");
return Ok(true);
}
}
@@ -310,7 +325,7 @@ async fn is_lfs_available() -> bool {
}
async fn lfs_pull(clone_dir: &Path) -> Result<()> {
- info!(path = %clone_dir.display(), "fetching LFS objects");
+ info!("fetching LFS objects: {}", clone_dir.display());
run_git(
&["lfs", "pull"],
@@ -320,7 +335,7 @@ async fn lfs_pull(clone_dir: &Path) -> Result<()> {
)
.await?;
- debug!(path = %clone_dir.display(), "LFS pull completed");
+ debug!("LFS pull completed: {}", clone_dir.display());
Ok(())
}
@@ -334,11 +349,14 @@ async fn lfs_pull(clone_dir: &Path) -> Result<()> {
async fn maybe_fetch_lfs(clone_dir: &Path) -> Result<()> {
// Step 1: Quick check for LFS configuration
if !has_lfs_configured(clone_dir).await {
- debug!(path = %clone_dir.display(), "no LFS configuration found");
+ debug!("no LFS configuration found: {}", clone_dir.display());
return Ok(());
}
- info!(path = %clone_dir.display(), "LFS configured, checking for pointers");
+ info!(
+ "LFS configured, checking for pointers: {}",
+ clone_dir.display()
+ );
// Step 2: Scan for actual pointer files
match has_lfs_pointers(clone_dir).await {
@@ -346,12 +364,12 @@ async fn maybe_fetch_lfs(clone_dir: &Path) -> Result<()> {
// Pointers found, need to fetch
}
Ok(false) => {
- debug!(path = %clone_dir.display(), "no LFS pointers found");
+ debug!("no LFS pointers found: {}", clone_dir.display());
return Ok(());
}
Err(e) => {
// If scan fails, try to fetch anyway (conservative approach)
- debug!(error = %e, "LFS pointer scan failed, attempting fetch");
+ debug!("LFS pointer scan failed, attempting fetch: {e}");
}
}
@@ -384,11 +402,11 @@ async fn maybe_init_submodules(
is_pull: bool,
) -> Result<()> {
if !has_submodules(clone_dir).await {
- debug!(path = %clone_dir.display(), "no submodules configured");
+ debug!("no submodules configured: {}", clone_dir.display());
return Ok(());
}
- info!(path = %clone_dir.display(), "submodules detected, initializing");
+ info!("submodules detected, initializing: {}", clone_dir.display());
// On pull, sync URLs first (handles upstream submodule URL changes)
if is_pull {
@@ -419,7 +437,10 @@ async fn maybe_init_submodules(
)
.await?;
- debug!(path = %clone_dir.display(), "submodule initialization completed");
+ debug!(
+ "submodule initialization completed: {}",
+ clone_dir.display()
+ );
Ok(())
}
@@ -1045,7 +1066,7 @@ mod tests {
}
/// Create a parent repo with a submodule wired up.
- /// Returns (parent_url, submodule_url).
+ /// Returns `(parent_url, submodule_url)`.
async fn create_repo_with_submodule(temp: &Path, branch: &str) -> (String, String) {
// 1. Create bare submodule repo with a file
let sub_bare = temp.join("sub.git");