diff --git a/CHANGELOG.md b/CHANGELOG.md index bd697aaa..2748443f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Fixed + +- always update git-cache of a branch or tag `imports` source +- track `imports:` sources, trigger new download if source has changed + ## [0.1.27] - 2024-12-06 ### Fixed diff --git a/src/data/import/download.rs b/src/data/import/download.rs index f46337e0..0c748d98 100644 --- a/src/data/import/download.rs +++ b/src/data/import/download.rs @@ -1,4 +1,4 @@ -use std::fs::{remove_dir_all, File}; +use std::fs::remove_dir_all; use anyhow::{Context as _, Error}; use camino::{Utf8Path, Utf8PathBuf}; @@ -32,6 +32,7 @@ fn git_clone_commit(url: &str, target_path: &Utf8Path, commit: &str) -> Result<( fn git_clone_branch(url: &str, target_path: &Utf8Path, branch: &str) -> Result<(), Error> { git_cloner(url, target_path) + .update(true) .extra_clone_args(Some(vec!["--branch".into(), branch.into()])) .do_clone() } @@ -43,8 +44,15 @@ impl Import for Download { let mut skip_download = false; if tagfile.exists() { - // TODO: check if tagfile was created with same info - skip_download = true; + let tagfile_contents = std::fs::read_to_string(tagfile.as_path())?; + let tagfile_source = + bincode::deserialize_from::<_, Source>(tagfile_contents.as_bytes()); + + if let Ok(tagfile_source) = tagfile_source { + if tagfile_source == self.source { + skip_download = true; + } + } } if !skip_download { if target_path.exists() { @@ -60,7 +68,7 @@ impl Import for Download { format!("cloning git url: \"{url}\" commit: \"{commit}\"") })?; - File::create(tagfile)?; + self.create_tagfile(tagfile)?; } Source::Git(Git::Branch { url, @@ -76,7 +84,7 @@ impl Import for Download { format!("cloning git url: \"{url}\" branch/tag: \"{branch_or_tag}\"") })?; - File::create(tagfile)?; + self.create_tagfile(tagfile)?; } Source::Git(Git::Default { url }) => { println!("IMPORT Git {url} -> {target_path}"); @@ -85,7 +93,7 @@ impl Import for Download { .do_clone() .with_context(|| format!("cloning git url: \"{url}\""))?; - File::create(tagfile)?; + self.create_tagfile(tagfile)?; } Source::Laze(name) => { let mut at_least_one = false; @@ -107,7 +115,8 @@ impl Import for Download { .with_context(|| format!("creating {filename}"))?; } if at_least_one { - File::create(&tagfile).with_context(|| format!("creating {tagfile}"))?; + self.create_tagfile(&tagfile) + .with_context(|| format!("creating {tagfile}"))?; } else { return Err(anyhow!("could not import from laze defaults: {name}")); } diff --git a/src/download.rs b/src/download.rs index 10af45ca..c4443e66 100644 --- a/src/download.rs +++ b/src/download.rs @@ -1,6 +1,6 @@ //! This module deals with "download:" directives -use std::borrow::Cow; +use std::{borrow::Cow, path::Path}; use anyhow::Result; use im::HashMap; @@ -72,6 +72,13 @@ impl Download { } } + pub fn create_tagfile>(&self, path: P) -> Result<()> { + let path = path.as_ref(); + let contents = bincode::serialize(&self.source)?; + std::fs::write(path, contents)?; + Ok(()) + } + fn render( &self, module: &Module,