diff --git a/bin/git-changelog b/bin/git-changelog index ab4367fc..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}" @@ -39,6 +40,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 +156,22 @@ _fetchCommitRange() { local list_all="${1:-false}" local start_tag="$2" local final_tag="$3" + local pathspec=() + + if [[ "${#GIT_LOG_EXCLUDES[@]}" -gt 0 ]]; then + pathspec=(-- . "${GIT_LOG_EXCLUDES[@]/#/:(exclude)}") + 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 +476,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/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/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. 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' +}