From 90178475147b0078b029c88a1aceed09417a47b9 Mon Sep 17 00:00:00 2001 From: vjymisal0 Date: Wed, 16 Sep 2026 12:03:13 +0530 Subject: [PATCH 1/3] feat(changelog): support excluding pathspecs Signed-off-by: vjymisal0 --- bin/git-changelog | 25 +++++++++++++++++++++---- man/git-changelog.1 | 6 ++++++ man/git-changelog.html | 3 +++ man/git-changelog.md | 3 +++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/bin/git-changelog b/bin/git-changelog index ab4367fc..741aa740 100755 --- a/bin/git-changelog +++ b/bin/git-changelog @@ -18,6 +18,8 @@ git_editor() { eval "$GIT_EDITOR" '"$@"' } +GIT_LOG_EXCLUDES=() + _usage() { cat << EOF usage: $PROGNAME options [file] @@ -39,6 +41,7 @@ OPTIONS: --start-commit Like --start-tag but use commit instead of tag -n, --no-merges Suppress commits from merged branches -m, --merges-only Only uses merge commits (uses both subject and body of commit) + -e, --exclude Exclude files or directories matching a pathspec -p, --prune-old Replace existing Changelog entirely with new content -x, --stdout Write output to stdout instead of to a Changelog file -h, --help, ? Show this message @@ -154,17 +157,26 @@ _fetchCommitRange() { local list_all="${1:-false}" local start_tag="$2" local final_tag="$3" + local pathspec=() + + if [[ "${#GIT_LOG_EXCLUDES[@]}" -gt 0 ]]; then + pathspec=(-- .) + local exclude + for exclude in "${GIT_LOG_EXCLUDES[@]}"; do + pathspec+=(":(exclude)$exclude") + done + fi # This shellcheck disable is applied to the whole if-body # shellcheck disable=SC2086 if [[ "$list_all" == true ]]; then - git log $GIT_LOG_OPTS --pretty=format:"${CUR_GIT_LOG_FORMAT}" + git log $GIT_LOG_OPTS --pretty=format:"${CUR_GIT_LOG_FORMAT}" "${pathspec[@]}" elif [[ -n "$final_tag" && "$start_tag" == "null" ]]; then - git log $GIT_LOG_OPTS --pretty=format:"${CUR_GIT_LOG_FORMAT}" "${final_tag}" + git log $GIT_LOG_OPTS --pretty=format:"${CUR_GIT_LOG_FORMAT}" "${final_tag}" "${pathspec[@]}" elif [[ -n "$final_tag" ]]; then - git log $GIT_LOG_OPTS --pretty=format:"${CUR_GIT_LOG_FORMAT}" "${start_tag}"'..'"${final_tag}" + git log $GIT_LOG_OPTS --pretty=format:"${CUR_GIT_LOG_FORMAT}" "${start_tag}"'..'"${final_tag}" "${pathspec[@]}" elif [[ -n "$start_tag" ]]; then - git log $GIT_LOG_OPTS --pretty=format:"${CUR_GIT_LOG_FORMAT}" "${start_tag}"'..' + git log $GIT_LOG_OPTS --pretty=format:"${CUR_GIT_LOG_FORMAT}" "${start_tag}"'..' "${pathspec[@]}" fi | sed 's/^ \* \*/ */g' } @@ -469,6 +481,11 @@ main() { GIT_LOG_OPTS='--merges' CUR_GIT_LOG_FORMAT="$GIT_MERGELOG_FORMAT" ;; + -e | --exclude ) + [ -n "$2" ] || { _error "--exclude requires a pathspec"; return 1; } + GIT_LOG_EXCLUDES+=( "$2" ) + shift + ;; -p | --prune-old ) option=( $(_setValueForKeyFakeAssocArray "prune_old" true "${option[*]}") ) ;; diff --git a/man/git-changelog.1 b/man/git-changelog.1 index e28b870a..04344cbe 100644 --- a/man/git-changelog.1 +++ b/man/git-changelog.1 @@ -78,6 +78,12 @@ Like the \-\-start\-tag but specify the oldest commit instead of tag\. Note that Filters out merge commits (commits with more than 1 parent) from generated changelog\. . .P +\-e, \-\-exclude +. +.P +Exclude files or directories matching a Git pathspec\. May be specified more than once\. +. +.P \-m, \-\-merges\-only . .P diff --git a/man/git-changelog.html b/man/git-changelog.html index 0b979a96..8b4db7e1 100644 --- a/man/git-changelog.html +++ b/man/git-changelog.html @@ -127,6 +127,9 @@

OPTIONS

Filters out merge commits (commits with more than 1 parent) from generated changelog.

+

-e, --exclude <pathspec>

+ +

Exclude files or directories matching a Git pathspec. May be specified more than once.

-m, --merges-only

Uses only merge commits (commits with more than 1 parent) for generated changelog. It also changes the default format to include the merge commit messages body, as on github the commits subject line only contains the branch name but no information about the content of the merge.

diff --git a/man/git-changelog.md b/man/git-changelog.md index d0060698..148cb8e4 100644 --- a/man/git-changelog.md +++ b/man/git-changelog.md @@ -52,6 +52,9 @@ git-changelog(1) -- Generate a changelog report Filters out merge commits (commits with more than 1 parent) from generated changelog. + -e, --exclude + + Exclude files or directories matching a Git pathspec. May be specified more than once. -m, --merges-only Uses only merge commits (commits with more than 1 parent) for generated changelog. It also changes the default format to include the merge commit messages body, as on github the commits subject line only contains the branch name but no information about the content of the merge. From 7ac4233851950e56cfbe39e20bb4d43894fff42a Mon Sep 17 00:00:00 2001 From: vjymisal0 Date: Thu, 17 Sep 2026 10:44:29 +0530 Subject: [PATCH 2/3] fix(changelog): document exclude option in tests and completion Signed-off-by: vjymisal0 --- etc/git-extras-completion.zsh | 2 +- tests/git-changelog.bats | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/git-changelog.bats diff --git a/etc/git-extras-completion.zsh b/etc/git-extras-completion.zsh index c6aab46e..8a2cb080 100644 --- a/etc/git-extras-completion.zsh +++ b/etc/git-extras-completion.zsh @@ -157,8 +157,8 @@ _git-bulk() { _git-changelog() { _arguments \ '(-l --list)'{-l,--list}'[list commits]' \ + '(-e --exclude)'{-e,--exclude}'[exclude files or directories matching a pathspec]:pathspec:' \ } - _git-clear() { _arguments \ '(-f --force)'{-f,--force}'[force clear]' \ diff --git a/tests/git-changelog.bats b/tests/git-changelog.bats new file mode 100644 index 00000000..7cdfcb15 --- /dev/null +++ b/tests/git-changelog.bats @@ -0,0 +1,27 @@ +# shellcheck shell=bash + +source "$BATS_TEST_DIRNAME/test_util.sh" + +setup_file() { + test_util.setup_file + test_util.install_command changelog +} + +setup() { + test_util.cd_test + test_util.git_init +} + +@test "excludes commits matching a pathspec" { + mkdir src docs + touch src/keep + git add . + git commit -m 'keep commit' + touch docs/exclude + git add . + git commit -m 'exclude commit' + + run git changelog --all --list --stdout --exclude docs + assert_success + assert_output ' * keep commit' +} From f90663c04caa53116aea776ff1a5da4f547ee8f5 Mon Sep 17 00:00:00 2001 From: vjymisal0 Date: Fri, 18 Sep 2026 09:23:34 +0530 Subject: [PATCH 3/3] refactor(changelog): use parameter expansion for pathspec and organize globals Signed-off-by: vjymisal0 --- bin/git-changelog | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/bin/git-changelog b/bin/git-changelog index 741aa740..f539908a 100755 --- a/bin/git-changelog +++ b/bin/git-changelog @@ -8,6 +8,7 @@ GIT_MERGELOG_FORMAT="$(git config changelog.mergeformat)" [[ -z "$GIT_MERGELOG_FORMAT" ]] && GIT_MERGELOG_FORMAT=' * %s%n%w(64,4,4)%b' GIT_EDITOR="$(git var GIT_EDITOR)" PROGNAME="git-changelog" +GIT_LOG_EXCLUDES=() git_editor() { if test -z "${GIT_EDITOR:+set}" @@ -18,8 +19,6 @@ git_editor() { eval "$GIT_EDITOR" '"$@"' } -GIT_LOG_EXCLUDES=() - _usage() { cat << EOF usage: $PROGNAME options [file] @@ -160,11 +159,7 @@ _fetchCommitRange() { local pathspec=() if [[ "${#GIT_LOG_EXCLUDES[@]}" -gt 0 ]]; then - pathspec=(-- .) - local exclude - for exclude in "${GIT_LOG_EXCLUDES[@]}"; do - pathspec+=(":(exclude)$exclude") - done + pathspec=(-- . "${GIT_LOG_EXCLUDES[@]/#/:(exclude)}") fi # This shellcheck disable is applied to the whole if-body