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

new: added 'path' config option to limit commit messages #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/gitchangelog/gitchangelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ def tags(self, contains=None):
key=lambda x: int(x.committer_date_timestamp))

def log(self, includes=["HEAD", ], excludes=[], include_merge=True,
encoding=_preferred_encoding):
encoding=_preferred_encoding, path=None):
"""Reverse chronological list of git repository's commits

Note: rev lists can be GitCommit instance list or identifier list.
Expand All @@ -1208,9 +1208,10 @@ def log(self, includes=["HEAD", ], excludes=[], include_merge=True,
refs[ref_type][idx] = self.commit(ref)

## --topo-order: don't mix commits from separate branches.
plog = Proc("git log --stdin -z --topo-order --pretty=format:%s %s --"
plog = Proc("git log --stdin -z --topo-order --pretty=format:%s %s %s"
% (GIT_FULL_FORMAT_STRING,
'--no-merges' if not include_merge else ''),
'--no-merges' if not include_merge else '',
'--' if not path else '-- ' + path),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep "-- %s" in the main string ? And something like path or "" ?

encoding=encoding)
for ref in refs["includes"]:
plog.stdin.write("%s\n" % ref.sha1)
Expand Down Expand Up @@ -1513,6 +1514,7 @@ def versions_data_iter(repository, revlist=None,
subject_process=lambda x: x,
log_encoding=DEFAULT_GIT_LOG_ENCODING,
warn=warn, ## Mostly used for test
path=None,
):
"""Returns an iterator through versions data structures

Expand All @@ -1528,6 +1530,7 @@ def versions_data_iter(repository, revlist=None,
:param subject_process: text processing object to apply to subject
:param log_encoding: the encoding used in git logs
:param warn: callable to output warnings, mocked by tests
:param path: limit commits to those occurring under this path

:returns: iterator of versions data_structures

Expand Down Expand Up @@ -1586,7 +1589,8 @@ def versions_data_iter(repository, revlist=None,
includes=[min(tag, max_rev)],
excludes=tags[idx + 1:] + excludes,
include_merge=include_merge,
encoding=log_encoding)
encoding=log_encoding,
path=path)

for commit in commits:
if any(re.search(pattern, commit.subject) is not None
Expand Down Expand Up @@ -1964,6 +1968,7 @@ def main():
body_process=config.get("body_process", noop),
subject_process=config.get("subject_process", noop),
log_encoding=log_encoding,
path=config.get('path', None)
)

if isinstance(content, basestring):
Expand Down
10 changes: 10 additions & 0 deletions src/gitchangelog/gitchangelog.rc.reference
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,13 @@ include_merge = True
# "HEAD"
#]
revs = []


## ``path`` is a string
##
## This option tells ``gitchangelog`` which path within the repository
## ``git log`` should be called from.
##
## If not defined or None, the default, ``gitchangelog`` will look at commits
## for all directories within the repo.
#path = r''
19 changes: 19 additions & 0 deletions test/test_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ def test_subject_process_syntax_error(self):
self.assertEqual(errlvl, 1)
self.assertContains(err.lower(), "syntax error")

def test_no_path_restrictions(self):
gitchangelog.file_put_contents(
".gitchangelog.rc",
"path = r''")

changelog = w('$tprog')
self.assertContains(changelog, "Bob",
msg="Should include 'Bob'..."
"content of changelog:\n%s" % changelog)

def test_path_restrictions(self):
gitchangelog.file_put_contents(
".gitchangelog.rc",
"path = r'does/not/exist'")

changelog = w('$tprog')
self.assertNotContains(changelog, "Bob",
msg="Should be empty with path restriction..."
"content of changelog:\n%s" % changelog)

class TestOnUnreleased(BaseGitReposTest):

Expand Down
8 changes: 8 additions & 0 deletions test/test_git_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def test_get_commit(self):
commit.subject,
'add ``b`` with non-ascii chars éèà⧵ and HTML chars ``&<``')

def test_log_nonexistent_path(self):
logs = list(self.repos.log(path=r'/does/not/exist'))
self.assertEqual(logs, [], 'Expected no logs with non-existent path restriction')

def test_log_default_path(self):
logs = list(self.repos.log(path=r''))
self.assertTrue(len(logs) > 0, 'Expected logs with default path restriction; got none')

def test_exception_when_requesting_unexistent_commit(self):
commit = self.repos.commit("XXX") ## No exception yet.
with self.assertRaises(ValueError):
Expand Down