Skip to content

Commit

Permalink
feat(git_entity): add GIT_DIFF_EXCLUSIONS for command-line git calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsahaj committed Feb 26, 2025
1 parent 17281c7 commit c60b202
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/git_entity/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::error::LumenError;
use std::process::Command;
use thiserror::Error;

use super::GIT_DIFF_EXCLUSIONS;

#[derive(Error, Debug, Clone)]
pub enum CommitError {
#[error("Commit '{0}' not found")]
Expand Down Expand Up @@ -64,6 +66,7 @@ impl Commit {
"--compact-summary",
sha,
])
.args(GIT_DIFF_EXCLUSIONS)
.output()?;

let diff = String::from_utf8(output.stdout)?;
Expand All @@ -82,8 +85,8 @@ impl Commit {
let mut message = String::from_utf8(output.stdout)?;
message.pop(); // Remove trailing newline
if message.ends_with('\n') {
message.pop(); // Remove the second trailing newline in commits where it exists (the ones not from github GUI)
}
message.pop(); // Remove the second trailing newline in commits where it exists (the ones not from github GUI)
}
Ok(message)
}

Expand Down
8 changes: 6 additions & 2 deletions src/git_entity/diff.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error::LumenError;
use thiserror::Error;

use super::commit::Commit;
use super::{commit::Commit, GIT_DIFF_EXCLUSIONS};

#[derive(Error, Debug)]
pub enum DiffError {
Expand Down Expand Up @@ -30,7 +30,10 @@ impl Diff {
vec!["diff"]
};

let output = std::process::Command::new("git").args(args).output()?;
let output = std::process::Command::new("git")
.args(args)
.args(GIT_DIFF_EXCLUSIONS)
.output()?;

let diff = String::from_utf8(output.stdout)?;
if diff.is_empty() {
Expand All @@ -49,6 +52,7 @@ impl Diff {

let output = std::process::Command::new("git")
.args(["diff", &range])
.args(GIT_DIFF_EXCLUSIONS)
.output()?;

let diff = String::from_utf8(output.stdout)?;
Expand Down
10 changes: 10 additions & 0 deletions src/git_entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ pub enum GitEntity {
Diff(Diff),
}

pub const GIT_DIFF_EXCLUSIONS: [&str; 7] = [
"--", // Separator for pathspecs
".", // Include everything
":(exclude)package-lock.json",
":(exclude)yarn.lock",
":(exclude)pnpm-lock.yaml",
":(exclude)Cargo.lock",
":(exclude)node_modules/**",
];

impl GitEntity {
pub fn format_static_details(&self, provider: &LumenProvider) -> String {
match self {
Expand Down

0 comments on commit c60b202

Please sign in to comment.