From 7ee2a78a8a865980ed9a2f07be3f55211e5a90b3 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 10 Oct 2016 15:34:51 -0400 Subject: [PATCH] add configuration option to not stop at branch base The previous commit changes the default behavior to always stop scanning at the base of a branch. This change adds a configuration option to allow that behavior to be disabled, so that revisions along the history of the branch prior to the point where it diverged from master can be included. The new default behavior established in the previous commit is not changed. Change-Id: I2c4968e1291c1b7d268896cfbb79e320d4085bce Signed-off-by: Doug Hellmann --- doc/source/usage.rst | 2 ++ ...anning-branch-option-6a0156b183814d7f.yaml | 9 ++++++ reno/config.py | 4 +++ reno/main.py | 9 ++++++ reno/scanner.py | 4 ++- reno/sphinxext.py | 4 ++- reno/tests/test_scanner.py | 28 +++++++++++++++++++ 7 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/stop-scanning-branch-option-6a0156b183814d7f.yaml diff --git a/doc/source/usage.rst b/doc/source/usage.rst index 47cd317..b005d28 100644 --- a/doc/source/usage.rst +++ b/doc/source/usage.rst @@ -160,6 +160,7 @@ configuration file. For example, a couple reno commands allow you to specify - ``--earliest-version`` - ``--collapse-pre-releases``/``--no-collapse-pre-releases`` - ``--ignore-cache`` +- ``--stop-at-branch-base``/``--no-stop-at-branch-base`` So you might write a config file (if you use these often) like: @@ -169,6 +170,7 @@ So you might write a config file (if you use these often) like: branch: master earliest_version: 12.0.0 collapse_pre_releases: false + stop_at_branch_base: true These will be parsed first and then the CLI options will be applied after the config files. diff --git a/releasenotes/notes/stop-scanning-branch-option-6a0156b183814d7f.yaml b/releasenotes/notes/stop-scanning-branch-option-6a0156b183814d7f.yaml new file mode 100644 index 0000000..fbba24b --- /dev/null +++ b/releasenotes/notes/stop-scanning-branch-option-6a0156b183814d7f.yaml @@ -0,0 +1,9 @@ +--- +features: + - Add a new configuration option, stop_at_branch_base, to control + whether or not the scanner stops looking for changes at the point + where a branch diverges from master. The default is True, meaning + that the scanner does stop. A false value means that versions that + appear on master from a point earlier than when the branch was + created will be included when scanning the branch for release + notes. diff --git a/reno/config.py b/reno/config.py index 5e47eb8..224d57f 100644 --- a/reno/config.py +++ b/reno/config.py @@ -32,6 +32,10 @@ class Config(object): # of the same number (1.0.0.0a1 notes appear under 1.0.0). 'collapse_pre_releases': True, + # Should the scanner stop at the base of a branch (True) or go + # ahead and scan the entire history (False)? + 'stop_at_branch_base': True, + # The git branch to scan. Defaults to the "current" branch # checked out. 'branch': None, diff --git a/reno/main.py b/reno/main.py index 50af629..3ca29c3 100644 --- a/reno/main.py +++ b/reno/main.py @@ -44,6 +44,15 @@ _query_args = [ dict(default=False, action='store_true', help='if there is a cache file present, do not use it')), + (('--stop-at-branch-base',), + dict(action='store_true', + default=True, + dest='stop_at_branch_base', + help='stop scanning when the branch meets master')), + (('--no-stop-at-branch-base',), + dict(action='store_false', + dest='stop_at_branch_base', + help='do not stop scanning when the branch meets master')), ] diff --git a/reno/scanner.py b/reno/scanner.py index 559aa52..8247dfd 100644 --- a/reno/scanner.py +++ b/reno/scanner.py @@ -224,13 +224,15 @@ def get_notes_by_version(conf): branch = conf.branch earliest_version = conf.earliest_version collapse_pre_releases = conf.collapse_pre_releases + stop_at_branch_base = conf.stop_at_branch_base LOG.debug('scanning %s/%s (branch=%s)' % (reporoot, notesdir, branch)) # If the user has not told us where to stop, try to work it out # for ourselves. If branch is set and is not "master", then we # want to stop at the base of the branch. - if (not earliest_version) and branch and (branch != 'master'): + if (stop_at_branch_base and + (not earliest_version) and branch and (branch != 'master')): LOG.debug('determining earliest_version from branch') earliest_version = _get_branch_base(reporoot, branch) if earliest_version and collapse_pre_releases: diff --git a/reno/sphinxext.py b/reno/sphinxext.py index e561e6c..018ce71 100644 --- a/reno/sphinxext.py +++ b/reno/sphinxext.py @@ -36,6 +36,7 @@ class ReleaseNotesDirective(rst.Directive): 'version': directives.unchanged, 'collapse-pre-releases': directives.flag, 'earliest-version': directives.unchanged, + 'stop-at-branch-base': directives.flag, } def run(self): @@ -56,10 +57,11 @@ class ReleaseNotesDirective(rst.Directive): if 'notesdir' in self.options: opt_overrides['notesdir'] = self.options.get('notesdir') version_opt = self.options.get('version') - # FIXME(dhellmann): Force this flag True for now and figure + # FIXME(dhellmann): Force these flags True for now and figure # out how Sphinx passes a "false" flag later. # 'collapse-pre-releases' in self.options opt_overrides['collapse_pre_releases'] = True + opt_overrides['stop_at_branch_base'] = True if 'earliest-version' in self.options: opt_overrides['earliest_version'] = self.options.get( 'earliest-version') diff --git a/reno/tests/test_scanner.py b/reno/tests/test_scanner.py index 810fca4..94b99f2 100644 --- a/reno/tests/test_scanner.py +++ b/reno/tests/test_scanner.py @@ -821,6 +821,34 @@ class BranchTest(Base): results, ) + def test_files_stable_from_master_no_stop_base(self): + self._run_git('checkout', '2.0.0') + self._run_git('checkout', '-b', 'stable/2') + f21 = self._add_notes_file('slug21') + self._run_git('checkout', 'master') + log_text = self._run_git('log', '--pretty=%x00%H %d', '--name-only', + 'stable/2') + self.addDetail('git log', text_content(log_text)) + self.c.override( + branch='stable/2', + ) + self.c.override( + stop_at_branch_base=False, + ) + raw_results = scanner.get_notes_by_version(self.c) + results = { + k: [f for (f, n) in v] + for (k, v) in raw_results.items() + } + self.assertEqual( + { + '1.0.0': [self.f1], + '2.0.0': [self.f2], + '2.0.0-1': [f21], + }, + results, + ) + def test_pre_release_branch_no_collapse(self): f4 = self._add_notes_file('slug4') self._run_git('tag', '-s', '-m', 'pre-release', '4.0.0.0rc1')