Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ› Fix up commit template path bug #35

Merged
merged 9 commits into from
Apr 23, 2023
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
34 changes: 17 additions & 17 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ jobs:
command: fmt
args: --all -- --check

clippy:
name: clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
# clippy:
# name: clippy
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: stable
# override: true
# - run: rustup component add clippy
# - uses: actions-rs/cargo@v1
# with:
# command: clippy
# args: -- -D warnings

test:
name: test
Expand All @@ -69,7 +69,7 @@ jobs:
args: -- --show-output

os-test:
needs: [check, fmt, clippy, test]
needs: [check, fmt, test]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
Expand Down Expand Up @@ -126,6 +126,6 @@ jobs:
args: --target=${{ matrix.target }}

cargo-check:
uses: xsv24/git-kit/.github/workflows/cargo-publish.yml@binary-relase
uses: xsv24/git-kit/.github/workflows/cargo-publish.yml@main
with:
dry-run: true
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

cargo:
needs: ["github-release"]
uses: xsv24/git-kit/.github/workflows/cargo-publish.yml@binary-relase
uses: xsv24/git-kit/.github/workflows/cargo-publish.yml@main
with:
version: ${{ needs.github-release.version }}
dry-run: false
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

# 🧰 git-kit

> 🚨 **IMPORTANT**
>
> This repository has been **renamed** to [inkan](https://github.com/xsv24/inkan) and thus this repository is now deprecated.
>
> Please head over to the [inkan](https://github.com/xsv24/inkan) repository to continue πŸ™

Use this CLI to help format your git commit messages consistently with less effort via pre-provided templates! 🀩

There are two default templates provided:
Expand Down
13 changes: 2 additions & 11 deletions src/adapters/git/git_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,12 @@ impl<S: GitSystem> adapters::Git for Git<S> {
Ok(())
}

fn template_file_path(&self) -> Result<AbsolutePath, GitError> {
fn template_file_path(&self) -> Result<PathBuf, GitError> {
// Template file and stored in the .git directory to avoid users having to adding to their .gitignore
// In future maybe we could make our own .git-kit dir to house config / templates along with this.
let path: PathBuf = self.root_directory()?.into();

let path: AbsolutePath = path
.join(".git")
.join("GIT_KIT_COMMIT_TEMPLATE")
.try_into()
.map_err(|e| {
log::error!("{}", e);
GitError::Validation {
message: "Failed to build template file path".into(),
}
})?;
let path = path.join(".git").join("GIT_KIT_COMMIT_TEMPLATE");

Ok(path)
}
Expand Down
2 changes: 2 additions & 0 deletions src/cli/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::{

use super::{checkout, commit, config, context, templates};

#[allow(clippy::almost_swapped)]
#[allow(clippy::correctness)]
#[derive(Debug, Clone, Subcommand)]
pub enum Commands {
/// Commit staged changes via git with a template message.
Expand Down
6 changes: 4 additions & 2 deletions src/cli/config/args.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::Args;
use clap::{Args, Subcommand};

use crate::{
domain::{
Expand All @@ -12,7 +12,9 @@ use crate::{
entry::Interactive,
};

#[derive(Debug, Clone, clap::Subcommand)]
#[allow(clippy::almost_swapped)]
#[allow(clippy::correctness)]
#[derive(Debug, Clone, Subcommand)]
pub enum Arguments {
/// Add / register a custom config file.
Add(ConfigAdd),
Expand Down
4 changes: 2 additions & 2 deletions src/domain/adapters/git.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::Path;
use std::path::{Path, PathBuf};

use crate::domain::{errors::GitError, models::path::AbsolutePath};

Expand Down Expand Up @@ -29,7 +29,7 @@ pub trait Git {
fn checkout(&self, name: &str, status: CheckoutStatus) -> Result<(), GitError>;

/// Get the commit file path for the current repository.
fn template_file_path(&self) -> Result<AbsolutePath, GitError>;
fn template_file_path(&self) -> Result<PathBuf, GitError>;

/// Commit changes and open and editor with template file.
fn commit_with_template(
Expand Down
4 changes: 0 additions & 4 deletions src/domain/commands/commit/handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::path::PathBuf;

use crate::{
domain::{
adapters::{CommitMsgStatus, Git, Store},
Expand All @@ -25,8 +23,6 @@ pub fn handler<G: Git, S: Store>(git: &G, store: &S, commit: Commit) -> Result<S

let template_file = git.template_file_path().map_err(Errors::Git)?;

let template_file: PathBuf = template_file.into();

std::fs::write(&template_file, &contents).map_err(|_| Errors::ValidationError {
message: "Failed attempting to write commit template file".into(),
})?;
Expand Down
6 changes: 3 additions & 3 deletions tests/fakers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct GitCommandMock {
pub branch_name: Result<String, String>,
pub checkout_res: fn(&str, CheckoutStatus) -> Result<(), GitError>,
pub commit_res: fn(&Path, CommitMsgStatus) -> Result<(), GitError>,
pub template_file_path: fn() -> Result<AbsolutePath, GitError>,
pub template_file_path: fn() -> Result<PathBuf, GitError>,
}

impl GitCommandMock {
Expand All @@ -86,7 +86,7 @@ impl GitCommandMock {
branch_name: Ok(Faker.fake()),
checkout_res: |_, _| Ok(()),
commit_res: |_, _| Ok(()),
template_file_path: || Ok(VALID_FILE_PATH.clone()),
template_file_path: || Ok(VALID_FILE_PATH.clone().into()),
}
}
}
Expand Down Expand Up @@ -114,7 +114,7 @@ impl Git for GitCommandMock {
panic!("Did not expect Git 'root_directory' to be called.");
}

fn template_file_path(&self) -> Result<AbsolutePath, GitError> {
fn template_file_path(&self) -> Result<PathBuf, GitError> {
(self.template_file_path)()
}

Expand Down