From 9896615a2229b5600813084fc21098e69e017f10 Mon Sep 17 00:00:00 2001 From: tison Date: Mon, 12 Jan 2026 15:05:57 +0800 Subject: [PATCH 1/2] chore: properly handle files after git add Signed-off-by: tison --- fmt/src/git.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fmt/src/git.rs b/fmt/src/git.rs index a464f29..e27bcb3 100644 --- a/fmt/src/git.rs +++ b/fmt/src/git.rs @@ -18,14 +18,14 @@ use std::collections::HashMap; use std::path::Path; use std::path::PathBuf; +use crate::config; +use crate::config::FeatureGate; use anyhow::bail; use anyhow::Context; use gix::bstr::BStr; +use gix::status::Item; use gix::Repository; -use crate::config; -use crate::config::FeatureGate; - #[derive(Debug, Clone)] pub struct GitContext { pub repo: Option, @@ -173,11 +173,14 @@ pub fn resolve_file_attrs( // process dirty working tree let status_platform = repo.status(gix::progress::Discard)?; - let status_iter = status_platform.into_index_worktree_iter(None)?; + let status_iter = status_platform.into_iter(None)?; let now = gix::date::Time::now_local_or_utc(); for item in status_iter { let item = item.context("failed to check git status item")?; - let rel_path = item.rela_path(); + let rel_path = match &item { + Item::IndexWorktree(item) => item.rela_path(), + Item::TreeIndex(item) => item.location(), + }; update_attrs(rel_path, now, current_username.as_str()); } From da9ceff0ae7f4403d855c78f6e8455075447a3aa Mon Sep 17 00:00:00 2001 From: tison Date: Mon, 12 Jan 2026 15:18:24 +0800 Subject: [PATCH 2/2] default_config Signed-off-by: tison --- CHANGELOG.md | 6 +++++- cli/src/subcommand.rs | 16 +++++++++++++++- fmt/src/document/factory.rs | 2 +- fmt/src/document/mod.rs | 5 ++--- fmt/src/git.rs | 5 +++-- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67b76cc..0593d30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ All notable changes to this project will be documented in this file. * `attrs.disk_file_created_year`, `attrs.git_file_created_year`, and `attrs.git_file_modified_year` are now integers instead of strings. Most use cases should not be affected. * `attrs.git_file_created_year` is now set even if the file is not tracked by Git. In this case, it will be set to the current year (as if it were committed now). * `attrs.git_file_modified_year` is now overwritten if the file is modified but not committed by Git. In this case, it will be set to the current year (as if it were committed now). -* `attrs.disk_file_created_year` is then soft-deprecated. It will still be set, but it is recommended to use `attrs.git_file_created_year` and `attrs.git_file_modified_year` directly instead. +* `attrs.disk_file_created_year` is then soft-deprecated. It can still be set, but it is recommended to use `attrs.git_file_created_year` and `attrs.git_file_modified_year` directly instead. The semantic changes above are breaking, but they should not affect most users and should always be what you want. @@ -18,6 +18,10 @@ The semantic changes above are breaking, but they should not affect most users a 2. The baseDir configured. 3. The current working directory. +## Improvements + +* If `--config` is not specified, HawkEye will now search for `.licenserc.toml` in addition to `licenserc.toml`. + ## [6.3.0] 2025-10-09 ### New features diff --git a/cli/src/subcommand.rs b/cli/src/subcommand.rs index e48a859..4fdadca 100644 --- a/cli/src/subcommand.rs +++ b/cli/src/subcommand.rs @@ -306,5 +306,19 @@ fn check_unknown_files(unknown: &[String], fail_if_unknown: bool) -> bool { } fn default_config() -> PathBuf { - PathBuf::new().join("licenserc.toml") + let candidates = [ + PathBuf::from("licenserc.toml"), + PathBuf::from(".licenserc.toml"), + ]; + + for path in &candidates { + if path.exists() { + return path.clone(); + } + } + + panic!( + "cannot find config file in any of the default locations: {:?}", + candidates.iter().map(|p| p.display()).collect::>() + ); } diff --git a/fmt/src/document/factory.rs b/fmt/src/document/factory.rs index 56ddbf4..95db947 100644 --- a/fmt/src/document/factory.rs +++ b/fmt/src/document/factory.rs @@ -69,7 +69,7 @@ impl DocumentFactory { .definitions .get(&header_type) .ok_or_else(|| io::Error::other(format!("header type {header_type} not found"))) - .with_context(|| format!("cannot to create document: {}", filepath.display()))?; + .with_context(|| format!("cannot create document: {}", filepath.display()))?; let props = self.properties.clone(); diff --git a/fmt/src/document/mod.rs b/fmt/src/document/mod.rs index d7ccbc6..8ce01a6 100644 --- a/fmt/src/document/mod.rs +++ b/fmt/src/document/mod.rs @@ -74,9 +74,8 @@ impl Document { log::debug!("skip non-textual file: {}", filepath.display()); Ok(None) } else { - Err(e).with_context(|| { - format!("cannot to create document: {}", filepath.display()) - }) + Err(e) + .with_context(|| format!("cannot create document: {}", filepath.display())) } } } diff --git a/fmt/src/git.rs b/fmt/src/git.rs index e27bcb3..0671118 100644 --- a/fmt/src/git.rs +++ b/fmt/src/git.rs @@ -18,14 +18,15 @@ use std::collections::HashMap; use std::path::Path; use std::path::PathBuf; -use crate::config; -use crate::config::FeatureGate; use anyhow::bail; use anyhow::Context; use gix::bstr::BStr; use gix::status::Item; use gix::Repository; +use crate::config; +use crate::config::FeatureGate; + #[derive(Debug, Clone)] pub struct GitContext { pub repo: Option,