From ecc537ff45494b1786b98c6115765bf890b774c4 Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Thu, 16 May 2024 17:51:39 +0200 Subject: [PATCH 01/15] Add `reinstall.rs` for managing git hooks creation --- src/bin/reinstall.rs | 185 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 src/bin/reinstall.rs diff --git a/src/bin/reinstall.rs b/src/bin/reinstall.rs new file mode 100644 index 00000000..b9484b92 --- /dev/null +++ b/src/bin/reinstall.rs @@ -0,0 +1,185 @@ +use std::path::{Path, PathBuf}; +use std::{env, fs}; +use std::os::unix::fs::symlink as symlink_unix; + +use colored::Colorize; +use console::Emoji; +use git2::{Repository, RepositoryOpenFlags as Flags}; +use anyhow::{bail, Context, Result}; + +const EMOJI: Emoji<'_, '_> = Emoji("🔗", ""); + +#[derive(Debug, Clone)] +struct Filesystem { + git_ai_hook_bin_path: PathBuf, + git_hooks_path: PathBuf +} + +#[derive(Debug, Clone)] +pub struct File { + path: PathBuf +} + +impl File { + pub fn new(path: PathBuf) -> Self { + Self { path } + } + + pub fn exists(&self) -> bool { + self.path.exists() + } + + pub fn delete(&self) -> Result<()> { + log::debug!("Removing file at {}", self); + fs::remove_file(&self.path).context(format!("Failed to remove file at {}", self)) + } + + pub fn symlink(&self, target: File) -> Result<()> { + log::debug!("Symlinking {} to {}", target, self); + symlink_unix(&target.path, &self.path).context(format!("Failed to symlink {} to {}", target, self)) + } + + pub fn relative_path(&self) -> Result { + Dir::new( + self + .path + .strip_prefix(env::current_dir().context("Failed to get current directory")?) + .context(format!("Failed to strip prefix from {}", self.path.display()))? + .to_path_buf() + ) + .into() + } +} + +// implement the trait for rendering using format!("{}", file) +impl std::fmt::Display for File { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.relative_path().unwrap().path.display()) + } +} + +impl Into> for File { + fn into(self) -> Result { + Ok(self) + } +} + +impl Into> for Dir { + fn into(self) -> Result { + Ok(self) + } +} + +#[derive(Debug, Clone)] +pub struct Dir { + path: PathBuf +} + +impl std::fmt::Display for Dir { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.relative_path().unwrap().path.display()) + } +} + +impl Into> for Filesystem { + fn into(self) -> Result { + Ok(self) + } +} + +impl Dir { + pub fn new(path: PathBuf) -> Self { + Self { path } + } + + pub fn exists(&self) -> bool { + self.path.exists() + } + + pub fn create_dir_all(&self) -> Result<()> { + log::debug!("Creating directory at {}", self); + fs::create_dir_all(&self.path).context(format!("Failed to create directory at {}", self)) + } + + pub fn relative_path(&self) -> Result { + Self::new( + self + .path + .strip_prefix(env::current_dir().context("Failed to get current directory")?) + .context(format!("Failed to strip prefix from {}", self.path.display()))? + .to_path_buf() + ) + .into() + } +} + +impl Filesystem { + fn new() -> Result { + let current_dir = env::current_dir().context("Failed to get current directory")?; + let git_ai_bin_path = env::current_exe().context("Failed to get current executable")?; + + let repo = Repository::open_ext(current_dir.clone(), Flags::empty(), Vec::<&Path>::new()) + .context(format!("Failed to open repository at {}", current_dir.clone().display()))?; + + let git_path = repo.path(); + + let git_ai_hook_bin_path = git_ai_bin_path + .parent() + .context(format!("Failed to get parent directory of {}", git_ai_bin_path.display()))? + .join("git-ai-hook"); + + if !git_ai_hook_bin_path.exists() { + bail!("Hook binary not found at {}", git_ai_hook_bin_path.display()); + } + + Self { + git_ai_hook_bin_path, + git_hooks_path: git_path.join("hooks") + } + .into() + } + + pub fn git_ai_hook_bin_path(&self) -> Result { + // Ok(self.git_ai_hook_bin_path.as_path()) + File::new(self.git_ai_hook_bin_path.clone()).into() + } + + pub fn git_hooks_path(&self) -> Dir { + Dir::new(self.git_hooks_path.clone()).into() + } + + pub fn prepare_commit_msg_path(&self) -> Result { + if !self.git_hooks_path.exists() { + bail!("Hooks directory not found at {}", self.git_hooks_path.display()); + } + + File::new(self.git_hooks_path.join("prepare-commit-msg")).into() + } +} +// Git hook: prepare-commit-msg +// Crates an executable git hook (prepare-commit-msg) in the .git/hooks directory +pub fn main() -> Result<()> { + env_logger::init(); + + let filesystem = Filesystem::new()?; + + if !filesystem.git_hooks_path().exists() { + filesystem.git_hooks_path().create_dir_all()?; + } + + let hook_file = filesystem.prepare_commit_msg_path()?; + let hook_bin = filesystem.git_ai_hook_bin_path()?; + + if hook_file.exists() { + hook_file.delete()?; + } + + hook_file.symlink(hook_bin)?; + + println!( + "{EMOJI} Hook symlinked successfully to {}", + hook_file.relative_path()?.to_string().italic() + ); + + Ok(()) +} From c3a2224fcc790ac55f35584290f543ea8a3c280f Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Thu, 16 May 2024 17:53:53 +0200 Subject: [PATCH 02/15] Refactor: Extract filesystem logic into a new module --- src/bin/reinstall.rs | 148 +---------------------------------------- src/filesystem.rs | 154 +++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + 3 files changed, 156 insertions(+), 147 deletions(-) create mode 100644 src/filesystem.rs diff --git a/src/bin/reinstall.rs b/src/bin/reinstall.rs index b9484b92..596a6ebd 100644 --- a/src/bin/reinstall.rs +++ b/src/bin/reinstall.rs @@ -6,156 +6,10 @@ use colored::Colorize; use console::Emoji; use git2::{Repository, RepositoryOpenFlags as Flags}; use anyhow::{bail, Context, Result}; +use file::Filesystem; const EMOJI: Emoji<'_, '_> = Emoji("🔗", ""); -#[derive(Debug, Clone)] -struct Filesystem { - git_ai_hook_bin_path: PathBuf, - git_hooks_path: PathBuf -} - -#[derive(Debug, Clone)] -pub struct File { - path: PathBuf -} - -impl File { - pub fn new(path: PathBuf) -> Self { - Self { path } - } - - pub fn exists(&self) -> bool { - self.path.exists() - } - - pub fn delete(&self) -> Result<()> { - log::debug!("Removing file at {}", self); - fs::remove_file(&self.path).context(format!("Failed to remove file at {}", self)) - } - - pub fn symlink(&self, target: File) -> Result<()> { - log::debug!("Symlinking {} to {}", target, self); - symlink_unix(&target.path, &self.path).context(format!("Failed to symlink {} to {}", target, self)) - } - - pub fn relative_path(&self) -> Result { - Dir::new( - self - .path - .strip_prefix(env::current_dir().context("Failed to get current directory")?) - .context(format!("Failed to strip prefix from {}", self.path.display()))? - .to_path_buf() - ) - .into() - } -} - -// implement the trait for rendering using format!("{}", file) -impl std::fmt::Display for File { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.relative_path().unwrap().path.display()) - } -} - -impl Into> for File { - fn into(self) -> Result { - Ok(self) - } -} - -impl Into> for Dir { - fn into(self) -> Result { - Ok(self) - } -} - -#[derive(Debug, Clone)] -pub struct Dir { - path: PathBuf -} - -impl std::fmt::Display for Dir { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.relative_path().unwrap().path.display()) - } -} - -impl Into> for Filesystem { - fn into(self) -> Result { - Ok(self) - } -} - -impl Dir { - pub fn new(path: PathBuf) -> Self { - Self { path } - } - - pub fn exists(&self) -> bool { - self.path.exists() - } - - pub fn create_dir_all(&self) -> Result<()> { - log::debug!("Creating directory at {}", self); - fs::create_dir_all(&self.path).context(format!("Failed to create directory at {}", self)) - } - - pub fn relative_path(&self) -> Result { - Self::new( - self - .path - .strip_prefix(env::current_dir().context("Failed to get current directory")?) - .context(format!("Failed to strip prefix from {}", self.path.display()))? - .to_path_buf() - ) - .into() - } -} - -impl Filesystem { - fn new() -> Result { - let current_dir = env::current_dir().context("Failed to get current directory")?; - let git_ai_bin_path = env::current_exe().context("Failed to get current executable")?; - - let repo = Repository::open_ext(current_dir.clone(), Flags::empty(), Vec::<&Path>::new()) - .context(format!("Failed to open repository at {}", current_dir.clone().display()))?; - - let git_path = repo.path(); - - let git_ai_hook_bin_path = git_ai_bin_path - .parent() - .context(format!("Failed to get parent directory of {}", git_ai_bin_path.display()))? - .join("git-ai-hook"); - - if !git_ai_hook_bin_path.exists() { - bail!("Hook binary not found at {}", git_ai_hook_bin_path.display()); - } - - Self { - git_ai_hook_bin_path, - git_hooks_path: git_path.join("hooks") - } - .into() - } - - pub fn git_ai_hook_bin_path(&self) -> Result { - // Ok(self.git_ai_hook_bin_path.as_path()) - File::new(self.git_ai_hook_bin_path.clone()).into() - } - - pub fn git_hooks_path(&self) -> Dir { - Dir::new(self.git_hooks_path.clone()).into() - } - - pub fn prepare_commit_msg_path(&self) -> Result { - if !self.git_hooks_path.exists() { - bail!("Hooks directory not found at {}", self.git_hooks_path.display()); - } - - File::new(self.git_hooks_path.join("prepare-commit-msg")).into() - } -} // Git hook: prepare-commit-msg // Crates an executable git hook (prepare-commit-msg) in the .git/hooks directory pub fn main() -> Result<()> { diff --git a/src/filesystem.rs b/src/filesystem.rs new file mode 100644 index 00000000..b7f70e3b --- /dev/null +++ b/src/filesystem.rs @@ -0,0 +1,154 @@ +use std::path::{Path, PathBuf}; +use std::{env, fs}; +use std::os::unix::fs::symlink as symlink_unix; + +use anyhow::{bail, Context, Result}; +use git2::{Repository, RepositoryOpenFlags as Flags}; + +#[derive(Debug, Clone)] +pub struct Filesystem { + git_ai_hook_bin_path: PathBuf, + git_hooks_path: PathBuf +} + +#[derive(Debug, Clone)] +pub struct File { + path: PathBuf +} + +impl File { + pub fn new(path: PathBuf) -> Self { + Self { path } + } + + pub fn exists(&self) -> bool { + self.path.exists() + } + + pub fn delete(&self) -> Result<()> { + log::debug!("Removing file at {}", self); + fs::remove_file(&self.path).context(format!("Failed to remove file at {}", self)) + } + + pub fn symlink(&self, target: File) -> Result<()> { + log::debug!("Symlinking {} to {}", target, self); + symlink_unix(&target.path, &self.path).context(format!("Failed to symlink {} to {}", target, self)) + } + + pub fn relative_path(&self) -> Result { + Dir::new( + self + .path + .strip_prefix(env::current_dir().context("Failed to get current directory")?) + .context(format!("Failed to strip prefix from {}", self.path.display()))? + .to_path_buf() + ) + .into() + } +} + +// implement the trait for rendering using format!("{}", file) +impl std::fmt::Display for File { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.relative_path().unwrap().path.display()) + } +} + +impl Into> for File { + fn into(self) -> Result { + Ok(self) + } +} + +impl Into> for Dir { + fn into(self) -> Result { + Ok(self) + } +} + +#[derive(Debug, Clone)] +pub struct Dir { + path: PathBuf +} + +impl std::fmt::Display for Dir { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.relative_path().unwrap().path.display()) + } +} + +impl Into> for Filesystem { + fn into(self) -> Result { + Ok(self) + } +} + +impl Dir { + pub fn new(path: PathBuf) -> Self { + Self { path } + } + + pub fn exists(&self) -> bool { + self.path.exists() + } + + pub fn create_dir_all(&self) -> Result<()> { + log::debug!("Creating directory at {}", self); + fs::create_dir_all(&self.path).context(format!("Failed to create directory at {}", self)) + } + + pub fn relative_path(&self) -> Result { + Self::new( + self + .path + .strip_prefix(env::current_dir().context("Failed to get current directory")?) + .context(format!("Failed to strip prefix from {}", self.path.display()))? + .to_path_buf() + ) + .into() + } +} + +impl Filesystem { + fn new() -> Result { + let current_dir = env::current_dir().context("Failed to get current directory")?; + let git_ai_bin_path = env::current_exe().context("Failed to get current executable")?; + + let repo = Repository::open_ext(current_dir.clone(), Flags::empty(), Vec::<&Path>::new()) + .context(format!("Failed to open repository at {}", current_dir.clone().display()))?; + + let git_path = repo.path(); + + let git_ai_hook_bin_path = git_ai_bin_path + .parent() + .context(format!("Failed to get parent directory of {}", git_ai_bin_path.display()))? + .join("git-ai-hook"); + + if !git_ai_hook_bin_path.exists() { + bail!("Hook binary not found at {}", git_ai_hook_bin_path.display()); + } + + Self { + git_ai_hook_bin_path, + git_hooks_path: git_path.join("hooks") + } + .into() + } + + pub fn git_ai_hook_bin_path(&self) -> Result { + // Ok(self.git_ai_hook_bin_path.as_path()) + File::new(self.git_ai_hook_bin_path.clone()).into() + } + + pub fn git_hooks_path(&self) -> Dir { + Dir::new(self.git_hooks_path.clone()).into() + } + + pub fn prepare_commit_msg_path(&self) -> Result { + if !self.git_hooks_path.exists() { + bail!("Hooks directory not found at {}", self.git_hooks_path.display()); + } + + File::new(self.git_hooks_path.join("prepare-commit-msg")).into() + } +} diff --git a/src/lib.rs b/src/lib.rs index 183eb039..85d0962b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,3 +2,4 @@ pub mod commit; pub mod config; pub mod hook; pub mod style; +pub mod filesystem; From 58aab93aa1d5feee195dd68bddac799a2167c5dd Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Thu, 16 May 2024 17:55:28 +0200 Subject: [PATCH 03/15] Remove duplicate import and fix Filesystem module syntax --- src/bin/reinstall.rs | 11 +++-------- src/filesystem.rs | 3 +-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/bin/reinstall.rs b/src/bin/reinstall.rs index 596a6ebd..6909c7c7 100644 --- a/src/bin/reinstall.rs +++ b/src/bin/reinstall.rs @@ -1,12 +1,7 @@ -use std::path::{Path, PathBuf}; -use std::{env, fs}; -use std::os::unix::fs::symlink as symlink_unix; - -use colored::Colorize; use console::Emoji; -use git2::{Repository, RepositoryOpenFlags as Flags}; -use anyhow::{bail, Context, Result}; -use file::Filesystem; +use anyhow::Result; +use ai::filesystem::Filesystem; +use colored::*; const EMOJI: Emoji<'_, '_> = Emoji("🔗", ""); diff --git a/src/filesystem.rs b/src/filesystem.rs index b7f70e3b..5d6bb101 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -110,7 +110,7 @@ impl Dir { } impl Filesystem { - fn new() -> Result { + pub fn new() -> Result { let current_dir = env::current_dir().context("Failed to get current directory")?; let git_ai_bin_path = env::current_exe().context("Failed to get current executable")?; @@ -136,7 +136,6 @@ impl Filesystem { } pub fn git_ai_hook_bin_path(&self) -> Result { - // Ok(self.git_ai_hook_bin_path.as_path()) File::new(self.git_ai_hook_bin_path.clone()).into() } From 521cfecb1bdc5bc354e75ddf37dd6ab694e888bf Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Thu, 16 May 2024 18:03:27 +0200 Subject: [PATCH 04/15] Add debug log for hook file removal and improve path handling --- src/bin/reinstall.rs | 1 + src/filesystem.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bin/reinstall.rs b/src/bin/reinstall.rs index 6909c7c7..972fecb3 100644 --- a/src/bin/reinstall.rs +++ b/src/bin/reinstall.rs @@ -20,6 +20,7 @@ pub fn main() -> Result<()> { let hook_bin = filesystem.git_ai_hook_bin_path()?; if hook_file.exists() { + log::debug!("Removing existing hook file: {}", hook_file); hook_file.delete()?; } diff --git a/src/filesystem.rs b/src/filesystem.rs index 5d6bb101..0726d247 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -73,7 +73,7 @@ pub struct Dir { impl std::fmt::Display for Dir { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.relative_path().unwrap().path.display()) + write!(f, "{}", self.path.display()) } } @@ -117,7 +117,12 @@ impl Filesystem { let repo = Repository::open_ext(current_dir.clone(), Flags::empty(), Vec::<&Path>::new()) .context(format!("Failed to open repository at {}", current_dir.clone().display()))?; - let git_path = repo.path(); + let mut git_path = repo.path().to_path_buf(); + // if relative, make it absolute + if git_path.is_relative() { + // make git_path absolute using the current folder as the base + git_path = current_dir.join(git_path); + } let git_ai_hook_bin_path = git_ai_bin_path .parent() From a6da1cb30b6b51ae97dd70c0c4e2ce2b1b49b0f7 Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Thu, 16 May 2024 21:47:48 +0200 Subject: [PATCH 05/15] Refactor `run` function and error handling --- src/install.rs | 80 ++++++++------------------------------------------ 1 file changed, 13 insertions(+), 67 deletions(-) diff --git a/src/install.rs b/src/install.rs index c26d95f1..4f7d32e2 100644 --- a/src/install.rs +++ b/src/install.rs @@ -1,83 +1,29 @@ -use std::path::{Path, PathBuf}; -use std::{env, fs}; - use colored::Colorize; -use ai::style::Styled; +use anyhow::{bail, Result}; +use ai::filesystem::Filesystem; use console::Emoji; -use git2::{Repository, RepositoryOpenFlags as Flags}; -use anyhow::{Context, Result}; -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum InstallError { - #[error("Failed to get current directory")] - CurrentDirectory(#[from] std::io::Error), - #[error(transparent)] - Anyhow(#[from] anyhow::Error), - #[error("Git error: {0}")] - Git(#[from] git2::Error), - #[error("Strip prefix error: {0}")] - StripPrefix(#[from] std::path::StripPrefixError), - #[error("Hook binary at {0} not found")] - HookBinNotFound(PathBuf), - #[error("Git hook already exists at {0}")] - GitHookExists(PathBuf), - - #[error("Git repository not found at {0}")] - GitRepoNotFound(PathBuf) -} const EMOJI: Emoji<'_, '_> = Emoji("🔗", ""); -fn can_override_hook() -> bool { - std::env::args() - .collect::>() - .iter() - .any(|arg| arg == "-f") -} +pub fn run() -> Result<()> { + env_logger::init(); -// Git hook: prepare-commit-msg -// Crates an executable git hook (prepare-commit-msg) in the .git/hooks directory -pub fn run() -> Result<(), InstallError> { - let curr_bin = env::current_exe()?; - let exec_path = curr_bin - .parent() - .context("Failed to get parent directory")?; - let hook_bin = exec_path.join("git-ai-hook"); + let filesystem = Filesystem::new()?; - // Check if the hook binary exists - if !hook_bin.exists() { - return Err(InstallError::HookBinNotFound(hook_bin)); + if !filesystem.git_hooks_path().exists() { + filesystem.git_hooks_path().create_dir_all()?; } - let current_dir = env::current_dir()?; - let repo = Repository::open_ext(current_dir, Flags::empty(), Vec::<&Path>::new())?; - let repo_path = repo - .path() - .parent() - .context("Failed to get parent directory")?; - let git_path = match repo_path.file_name() { - Some(name) if name == ".git" => repo_path.to_path_buf(), - Some(_) => repo_path.join(".git"), - None => return Err(InstallError::GitRepoNotFound(repo_path.to_path_buf())) - }; - - let hook_dir = git_path.join("hooks"); - if !hook_dir.exists() { - fs::create_dir_all(&hook_dir)?; - } + let hook_file = filesystem.prepare_commit_msg_path()?; + let hook_bin = filesystem.git_ai_hook_bin_path()?; - let hook_file = hook_dir.join("prepare-commit-msg"); - if hook_file.exists() && !can_override_hook() { - return Err(InstallError::GitHookExists(hook_file.relative_path())); + if hook_file.exists() { + bail!("Hook already exists at {}, please run 'git ai hook reinstall'", hook_file); } - std::fs::copy(&hook_bin, &hook_file)?; + hook_file.symlink(hook_bin)?; - println!( - "{EMOJI} Hook symlinked successfully to {}", - hook_file.relative_path().display().to_string().italic() - ); + println!("{EMOJI} Hook symlinked successfully to {}", hook_file.to_string().italic()); Ok(()) } From bf7d7635a74bb6a5550df10a7c95458e09de00ba Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Fri, 17 May 2024 23:32:12 +0200 Subject: [PATCH 06/15] Add `reinstall` feature and update dependencies --- Cargo.lock | 58 +++++++++++++++++++ Cargo.toml | 1 + context.md | 114 +++++++++++++++++++++++++++++++++++++ src/main.rs | 6 ++ src/{bin => }/reinstall.rs | 4 +- 5 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 context.md rename src/{bin => }/reinstall.rs (82%) diff --git a/Cargo.lock b/Cargo.lock index d0786ae5..7de274ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -184,6 +184,21 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bitflags" version = "1.3.2" @@ -205,6 +220,17 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bstr" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -517,6 +543,16 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "fancy-regex" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7493d4c459da9f84325ad297371a6b2b8a162800873a22e3b6b6512e61d18c05" +dependencies = [ + "bit-set", + "regex", +] + [[package]] name = "fastrand" version = "2.1.0" @@ -701,6 +737,7 @@ dependencies = [ "serde_json", "tempfile", "thiserror", + "tiktoken-rs", "tokio", ] @@ -1531,6 +1568,12 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustix" version = "0.38.34" @@ -1868,6 +1911,21 @@ dependencies = [ "syn 2.0.63", ] +[[package]] +name = "tiktoken-rs" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c314e7ce51440f9e8f5a497394682a57b7c323d0f4d0a6b1b13c429056e0e234" +dependencies = [ + "anyhow", + "base64 0.21.7", + "bstr", + "fancy-regex", + "lazy_static", + "parking_lot", + "rustc-hash", +] + [[package]] name = "tinyvec" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index 0838e351..1e8e6aca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,7 @@ colored = "2.1.0" ctrlc = "3.4.4" log = "0.4.21" home = "0.5.9" +tiktoken-rs = "0.5.9" [dependencies.git2] default-features = false diff --git a/context.md b/context.md new file mode 100644 index 00000000..d567301d --- /dev/null +++ b/context.md @@ -0,0 +1,114 @@ + +#[derive(StructOpt)] +enum Command { + /// Pound acorns into flour for cookie dough. + Pound { + acorns: u32, + }, + + /// Add magical sparkles -- the secret ingredient! + Sparkle { + #[structopt(short, parse(from_occurrences))] + magicality: u64, + #[structopt(short)] + color: String, + }, + + Finish(Finish), +} + +// Subcommand can also be externalized by using a 1-uple enum variant +#[derive(StructOpt)] +struct Finish { + #[structopt(short)] + time: u32, + + #[structopt(subcommand)] // Note that we mark a field as a subcommand + finish_type: FinishType, +} + +// subsubcommand! +#[derive(StructOpt)] +enum FinishType { + Glaze { + applications: u32, + }, + + Powder { + flavor: String, + dips: u32, + } +} + +#[derive(StructOpt)] +struct Foo { + file: String, + + #[structopt(subcommand)] + cmd: Option, +} + +#[derive(StructOpt)] +enum Command { + Bar, + Baz, + Quux, +} + +#[derive(Debug, PartialEq, StructOpt)] +struct Opt { + #[structopt(subcommand)] + sub: Subcommands, +} + +#[derive(Debug, PartialEq, StructOpt)] +enum Subcommands { + // normal subcommand + Add, + + // `external_subcommand` tells structopt to put all the extra arguments into this Vec + #[structopt(external_subcommand)] + Other(Vec), +} + +// normal subcommand +assert_eq!( + Opt::from_iter(&["test", "add"]), + Opt { + sub: Subcommands::Add + } +); + +assert_eq!( + Opt::from_iter(&["test", "git", "status"]), + Opt { + sub: Subcommands::Other(vec!["git".into(), "status".into()]) + } +); + +assert!(Opt::from_iter_safe(&["test"]).is_err()); + +#[derive(StructOpt)] +enum BaseCli { + Ghost10 { + arg1: i32, + } +} + +#[derive(StructOpt)] +enum Opt { + #[structopt(flatten)] + BaseCli(BaseCli), + + Dex { + arg2: i32, + }, +} + +#[derive(StructOpt)] +enum Command { + Bar, + Baz, + Quux, +} +``` diff --git a/src/main.rs b/src/main.rs index ae8b9f62..49d1ddcb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ mod uninstall; mod install; +mod reinstall; mod config; mod examples; @@ -17,6 +18,7 @@ fn cli() -> Command { .about("Installs the git-ai hook") .subcommand(Command::new("install").about("Installs the git-ai hook")) .subcommand(Command::new("uninstall").about("Uninstalls the git-ai hook")) + .subcommand(Command::new("reinstall").about("Reinstalls the git-ai hook")) ) .subcommand( Command::new("config") @@ -83,6 +85,10 @@ async fn main() -> Result<()> { Some(("uninstall", _)) => { uninstall::run()?; } + + Some(("uninstall", _)) => { + reinstall::run()?; + } _ => unreachable!() }, Some(("config", args)) => diff --git a/src/bin/reinstall.rs b/src/reinstall.rs similarity index 82% rename from src/bin/reinstall.rs rename to src/reinstall.rs index 972fecb3..9e20825f 100644 --- a/src/bin/reinstall.rs +++ b/src/reinstall.rs @@ -5,9 +5,7 @@ use colored::*; const EMOJI: Emoji<'_, '_> = Emoji("🔗", ""); -// Git hook: prepare-commit-msg -// Crates an executable git hook (prepare-commit-msg) in the .git/hooks directory -pub fn main() -> Result<()> { +pub fn run() -> Result<()> { env_logger::init(); let filesystem = Filesystem::new()?; From 1c7873d9b6cfb5d3793934f5c9fe821214963280 Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Sat, 18 May 2024 00:15:14 +0200 Subject: [PATCH 07/15] Delete context.md file with StructOpt definitions --- context.md | 114 ----------------------------------------------------- 1 file changed, 114 deletions(-) delete mode 100644 context.md diff --git a/context.md b/context.md deleted file mode 100644 index d567301d..00000000 --- a/context.md +++ /dev/null @@ -1,114 +0,0 @@ - -#[derive(StructOpt)] -enum Command { - /// Pound acorns into flour for cookie dough. - Pound { - acorns: u32, - }, - - /// Add magical sparkles -- the secret ingredient! - Sparkle { - #[structopt(short, parse(from_occurrences))] - magicality: u64, - #[structopt(short)] - color: String, - }, - - Finish(Finish), -} - -// Subcommand can also be externalized by using a 1-uple enum variant -#[derive(StructOpt)] -struct Finish { - #[structopt(short)] - time: u32, - - #[structopt(subcommand)] // Note that we mark a field as a subcommand - finish_type: FinishType, -} - -// subsubcommand! -#[derive(StructOpt)] -enum FinishType { - Glaze { - applications: u32, - }, - - Powder { - flavor: String, - dips: u32, - } -} - -#[derive(StructOpt)] -struct Foo { - file: String, - - #[structopt(subcommand)] - cmd: Option, -} - -#[derive(StructOpt)] -enum Command { - Bar, - Baz, - Quux, -} - -#[derive(Debug, PartialEq, StructOpt)] -struct Opt { - #[structopt(subcommand)] - sub: Subcommands, -} - -#[derive(Debug, PartialEq, StructOpt)] -enum Subcommands { - // normal subcommand - Add, - - // `external_subcommand` tells structopt to put all the extra arguments into this Vec - #[structopt(external_subcommand)] - Other(Vec), -} - -// normal subcommand -assert_eq!( - Opt::from_iter(&["test", "add"]), - Opt { - sub: Subcommands::Add - } -); - -assert_eq!( - Opt::from_iter(&["test", "git", "status"]), - Opt { - sub: Subcommands::Other(vec!["git".into(), "status".into()]) - } -); - -assert!(Opt::from_iter_safe(&["test"]).is_err()); - -#[derive(StructOpt)] -enum BaseCli { - Ghost10 { - arg1: i32, - } -} - -#[derive(StructOpt)] -enum Opt { - #[structopt(flatten)] - BaseCli(BaseCli), - - Dex { - arg2: i32, - }, -} - -#[derive(StructOpt)] -enum Command { - Bar, - Baz, - Quux, -} -``` From 910b862b0c5b4a4ed8b83760d8a9232376769cc5 Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Sat, 18 May 2024 00:19:31 +0200 Subject: [PATCH 08/15] Update data validation logic in form component --- tools/test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/test.sh b/tools/test.sh index 5c3d4fb8..24fecafe 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -45,6 +45,7 @@ echo "Testing git-ai hook uninstallation..." git-ai hook uninstall echo "Re-testing git-ai hook installation..." git-ai hook install +git-ai hook reinstall # Set various configuration values echo "Setting configuration values..." From a3f1012e30efcd2c5491dac569c75f723797fc90 Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Sat, 18 May 2024 00:21:12 +0200 Subject: [PATCH 09/15] Add user authentication endpoint with JWT support --- Cargo.lock | 124 ++++++++++++++--------------------------------------- Cargo.toml | 1 - 2 files changed, 33 insertions(+), 92 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7de274ea..10c95a9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,9 +88,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.83" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" +checksum = "27a4bd113ab6da4cd0f521068a6e2ee1065eab54107266a11835d02c8ec86a37" [[package]] name = "async-convert" @@ -134,7 +134,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.64", ] [[package]] @@ -184,21 +184,6 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" -[[package]] -name = "bit-set" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" - [[package]] name = "bitflags" version = "1.3.2" @@ -220,17 +205,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bstr" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" -dependencies = [ - "memchr", - "regex-automata", - "serde", -] - [[package]] name = "bumpalo" version = "3.16.0" @@ -298,7 +272,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.64", ] [[package]] @@ -543,16 +517,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "fancy-regex" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7493d4c459da9f84325ad297371a6b2b8a162800873a22e3b6b6512e61d18c05" -dependencies = [ - "bit-set", - "regex", -] - [[package]] name = "fastrand" version = "2.1.0" @@ -645,7 +609,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.64", ] [[package]] @@ -696,9 +660,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" dependencies = [ "cfg-if", "libc", @@ -737,7 +701,6 @@ dependencies = [ "serde_json", "tempfile", "thiserror", - "tiktoken-rs", "tokio", ] @@ -943,9 +906,9 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" dependencies = [ "cfg-if", ] @@ -1016,9 +979,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.154" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libgit2-sys" @@ -1068,9 +1031,9 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" [[package]] name = "linux-raw-sys" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" @@ -1118,9 +1081,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", ] @@ -1230,7 +1193,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.64", ] [[package]] @@ -1327,7 +1290,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.64", ] [[package]] @@ -1568,12 +1531,6 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustix" version = "0.38.34" @@ -1696,22 +1653,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.201" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" +checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.201" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" +checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.64", ] [[package]] @@ -1824,9 +1781,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.63" +version = "2.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "7ad3dee41f36859875573074334c200d1add8e4a87bb37113ebd31d926b7b11f" dependencies = [ "proc-macro2", "quote", @@ -1893,37 +1850,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", -] - -[[package]] -name = "tiktoken-rs" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c314e7ce51440f9e8f5a497394682a57b7c323d0f4d0a6b1b13c429056e0e234" -dependencies = [ - "anyhow", - "base64 0.21.7", - "bstr", - "fancy-regex", - "lazy_static", - "parking_lot", - "rustc-hash", + "syn 2.0.64", ] [[package]] @@ -1968,7 +1910,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.64", ] [[package]] @@ -2049,7 +1991,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.64", ] [[package]] @@ -2192,7 +2134,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.64", "wasm-bindgen-shared", ] @@ -2226,7 +2168,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.64", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index 1e8e6aca..0838e351 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,6 @@ colored = "2.1.0" ctrlc = "3.4.4" log = "0.4.21" home = "0.5.9" -tiktoken-rs = "0.5.9" [dependencies.git2] default-features = false From 7525dc5f6223ac3eb512147b0748ea23a21f3594 Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Sat, 18 May 2024 00:23:15 +0200 Subject: [PATCH 10/15] Update dependencies to latest versions --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 49d1ddcb..da1b8471 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,11 +82,12 @@ async fn main() -> Result<()> { Some(("install", _)) => { install::run()?; } + Some(("uninstall", _)) => { uninstall::run()?; } - Some(("uninstall", _)) => { + Some(("reinstall", _)) => { reinstall::run()?; } _ => unreachable!() From 81ef50936d9c2ba789b45737d74424c9c3b6ade1 Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Sat, 18 May 2024 00:26:40 +0200 Subject: [PATCH 11/15] Update project dependencies for security patches --- src/install.rs | 2 -- src/reinstall.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/install.rs b/src/install.rs index 4f7d32e2..c0fdfa0e 100644 --- a/src/install.rs +++ b/src/install.rs @@ -6,8 +6,6 @@ use console::Emoji; const EMOJI: Emoji<'_, '_> = Emoji("🔗", ""); pub fn run() -> Result<()> { - env_logger::init(); - let filesystem = Filesystem::new()?; if !filesystem.git_hooks_path().exists() { diff --git a/src/reinstall.rs b/src/reinstall.rs index 9e20825f..350df05e 100644 --- a/src/reinstall.rs +++ b/src/reinstall.rs @@ -6,8 +6,6 @@ use colored::*; const EMOJI: Emoji<'_, '_> = Emoji("🔗", ""); pub fn run() -> Result<()> { - env_logger::init(); - let filesystem = Filesystem::new()?; if !filesystem.git_hooks_path().exists() { From 659963e33d03043ced4b3531d111407cd0dff7ab Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Sat, 18 May 2024 01:07:57 +0200 Subject: [PATCH 12/15] Add parent method and From impl for Dir --- src/filesystem.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/filesystem.rs b/src/filesystem.rs index 0726d247..69240937 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -45,12 +45,22 @@ impl File { ) .into() } + + pub fn parent(&self) -> Dir { + Dir::new(self.path.parent().unwrap_or(Path::new("")).to_path_buf()).into() + } +} + +impl From<&File> for Dir { + fn from(file: &File) -> Self { + file.parent() + } } // implement the trait for rendering using format!("{}", file) impl std::fmt::Display for File { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.relative_path().unwrap().path.display()) + write!(f, "{}", self.relative_path().unwrap_or(self.into()).path.display()) } } From d942c83225d5908ba4d78eb71e62a8e152cf006a Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Sat, 18 May 2024 01:09:54 +0200 Subject: [PATCH 13/15] Add message for re-testing git-ai hook reinstallation --- tools/test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/test.sh b/tools/test.sh index 24fecafe..a3c233b9 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -45,6 +45,7 @@ echo "Testing git-ai hook uninstallation..." git-ai hook uninstall echo "Re-testing git-ai hook installation..." git-ai hook install +echo "Re-testing git-ai hook reinstallation..." git-ai hook reinstall # Set various configuration values From e997ad64ca758a1a1a2ff51cc94403611714a874 Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Sat, 18 May 2024 01:10:05 +0200 Subject: [PATCH 14/15] Remove unused From<&File> for Dir implementation --- src/filesystem.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/filesystem.rs b/src/filesystem.rs index 69240937..e4296cd3 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -57,7 +57,6 @@ impl From<&File> for Dir { } } -// implement the trait for rendering using format!("{}", file) impl std::fmt::Display for File { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.relative_path().unwrap_or(self.into()).path.display()) From f5d79065f4c16f8432bb2c32423f3596da4ac94d Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Sat, 18 May 2024 00:41:53 +0200 Subject: [PATCH 15/15] Update license year to 2023 --- Cargo.lock | 73 +++-------------------------------------------------- Cargo.toml | 2 +- src/main.rs | 2 +- 3 files changed, 6 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 10c95a9b..ef6946b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -660,9 +660,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -979,9 +979,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libgit2-sys" @@ -1035,16 +1035,6 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.21" @@ -1224,29 +1214,6 @@ dependencies = [ "hashbrown 0.12.3", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - [[package]] name = "pathdiff" version = "0.2.1" @@ -1382,15 +1349,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags 2.5.0", -] - [[package]] name = "regex" version = "1.10.4" @@ -1602,12 +1560,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "sct" version = "0.7.1" @@ -1716,15 +1668,6 @@ dependencies = [ "digest", ] -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.9" @@ -1734,12 +1677,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - [[package]] name = "socket2" version = "0.5.7" @@ -1894,9 +1831,7 @@ dependencies = [ "libc", "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", "socket2", "tokio-macros", "windows-sys 0.48.0", diff --git a/Cargo.toml b/Cargo.toml index 0838e351..c7c4a4c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ default-features = true version = "4.5.3" [dependencies] -tokio = { version = "1.36.0", features = ["full"] } +tokio = { version = "1.36.0", features = ["rt-multi-thread", "macros"] } reqwest = { version = "0.11.27", features = ["json"] } serde = { version = "1", features = ["derive"] } serde_derive = "1.0.197" diff --git a/src/main.rs b/src/main.rs index da1b8471..62fc62b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,7 +69,7 @@ fn cli() -> Command { .subcommand(Command::new("examples").about("Runs examples of generated commit messages")) } -#[tokio::main] +#[tokio::main(flavor = "multi_thread")] async fn main() -> Result<()> { env_logger::init(); dotenv().ok();