Skip to content
Open
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
20 changes: 16 additions & 4 deletions bin/git-changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
}

Expand Down Expand Up @@ -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[*]}") )
;;
Expand Down
2 changes: 1 addition & 1 deletion etc/git-extras-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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]' \
Expand Down
6 changes: 6 additions & 0 deletions man/git-changelog.1
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pathspec>
.
.P
Exclude files or directories matching a Git pathspec\. May be specified more than once\.
.
.P
\-m, \-\-merges\-only
.
.P
Expand Down
3 changes: 3 additions & 0 deletions man/git-changelog.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/git-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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.
Expand Down
27 changes: 27 additions & 0 deletions tests/git-changelog.bats
Original file line number Diff line number Diff line change
@@ -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'
}
Loading