Merge lp:~allenap/bzr-update-copyright/force-ranges-on-commit into lp:bzr-update-copyright

Proposed by Gavin Panella
Status: Merged
Approved by: Richard Wilbur
Approved revision: 18
Merged at revision: 17
Proposed branch: lp:~allenap/bzr-update-copyright/force-ranges-on-commit
Merge into: lp:bzr-update-copyright
Diff against target: 99 lines (+54/-5)
2 files modified
__init__.py (+23/-5)
test_update_copyright.py (+31/-0)
To merge this branch: bzr merge lp:~allenap/bzr-update-copyright/force-ranges-on-commit
Reviewer Review Type Date Requested Status
Richard Wilbur Approve
Review via email: mp+295604@code.launchpad.net

Commit message

Allow optional --force-range behaviour in commit hooks.

To post a comment you must log in.
Revision history for this message
Richard Wilbur (richard-wilbur) wrote :

I like the changes. Please update the documentation in __init__.py docstring to describe the new capability. If you can't get to that right now, let me know and I can do it.

review: Needs Fixing
18. By Gavin Panella

Update documentation for commit hook.

Revision history for this message
Gavin Panella (allenap) wrote :

> Please update the documentation in __init__.py docstring to describe
> the new capability.

Done.

Thanks!

Revision history for this message
Richard Wilbur (richard-wilbur) wrote :

Looks great, Gavin! Thanks for the new, documented functionality.
+2

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

Richard, I don't have write access to lp:bzr-update-copyright. Would you merge it for me? Thanks.

Revision history for this message
Richard Wilbur (richard-wilbur) wrote :

Gavin, I'll be happy to merge it for you tomorrow. I've been very
busy lately or I would have merged it the day I approved it.

Revision history for this message
Gavin Panella (allenap) wrote :

Thanks, that's grand.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2015-05-07 11:37:32 +0000
3+++ __init__.py 2016-05-31 19:12:18 +0000
4@@ -34,6 +34,7 @@
5 mutabletree, # I wish we could make the hook registration fully lazy
6 option,
7 trace,
8+ ui,
9 )
10
11 version_info = (0, 1, 0, 'dev', 0)
12@@ -88,16 +89,33 @@
13 def _update_copyright_start_commit_hook(tree):
14 """A hook that will update copyrights at commit time.
15
16- This is configured via "auto_update_copyright=True" in your configuration
17- files.
18+ This is configured by setting "auto_update_copyright" in your
19+ configuration files:
20+
21+ # Update copyright headers in changed files when committing:
22+ auto_update_copyright = true
23+
24+ # As above, but force the use of a range of years, like
25+ # using --force-range at the command-line.
26+ auto_update_copyright = force-range
27+
28+ # Don't update copyright headers; override configuration
29+ # set in a wider scope.
30+ auto_update_copyright = false
31+
32 """
33 conf = tree.branch.get_config()
34- auto_update = conf.get_user_option_as_bool('auto_update_copyright')
35- if auto_update is None or not auto_update:
36+ auto_update = conf.get_user_option('auto_update_copyright')
37+ if ui.bool_from_string(auto_update):
38+ force_range = False
39+ elif auto_update == "force-range":
40+ force_range = True
41+ else:
42 trace.mutter('Auto-update set to %s' % (auto_update,))
43 return
44 import update_copyright
45- res = update_copyright.update_tree_copyright(tree, None, only_changed=True)
46+ res = update_copyright.update_tree_copyright(
47+ tree, None, only_changed=True, force_range=force_range)
48 # TODO: Consider only muttering if something is actually changed...
49 trace.mutter('Auto-updating copyright:\n'
50 ' Checked %(count)d files\n'
51
52=== modified file 'test_update_copyright.py'
53--- test_update_copyright.py 2015-05-07 11:37:32 +0000
54+++ test_update_copyright.py 2016-05-31 19:12:18 +0000
55@@ -368,6 +368,23 @@
56 self.assertFileEqual('Copyright 2008 Bar\n'
57 'content\n', 'dir/subdir/foo')
58
59+ def test_auto_update_hook_disabled_with_false(self):
60+ t, rev_ids = self.make_tree_with_dirs_modified()
61+ # We have to install it here, because the test suite clears out hooks
62+ # as part of its isolation mechanism.
63+ mutabletree.MutableTree.hooks.install_named_hook(
64+ 'start_commit', _update_copyright_start_commit_hook,
65+ 'update-copyright')
66+ t.branch.get_config().set_user_option('auto_update_copyright', 'false')
67+ # Without a false-like config, nothing should be modified.
68+ t.commit('Modified content')
69+ self.assertFileEqual('Copyright (c) 2008 Foo Bar\n'
70+ 'different content\n', 'file')
71+ self.assertFileEqual('Copyright 2008 Foo\r\n'
72+ 'modified content\r\n', 'dir/file')
73+ self.assertFileEqual('Copyright 2008 Bar\n'
74+ 'content\n', 'dir/subdir/foo')
75+
76 def test_auto_update_hook_enabled(self):
77 t, rev_ids = self.make_tree_with_dirs_modified()
78 # We have to install it here, because the test suite clears out hooks
79@@ -381,6 +398,20 @@
80 # modified file
81 self.check_tree_with_dirs_modified()
82
83+ def test_auto_update_hook_enabled_with_force_range(self):
84+ t, rev_ids = self.make_tree_with_dirs_modified()
85+ # We have to install it here, because the test suite clears out hooks
86+ # as part of its isolation mechanism.
87+ mutabletree.MutableTree.hooks.install_named_hook(
88+ 'start_commit', _update_copyright_start_commit_hook,
89+ 'update-copyright')
90+ t.branch.get_config().set_user_option(
91+ 'auto_update_copyright', 'force-range')
92+ t.commit('Modified content')
93+ # With the hook enabled, commit should update the copyright in the
94+ # modified file
95+ self.check_tree_with_dirs_modified_using_ranges()
96+
97 def test_blackbox(self):
98 t, rev_ids = self.make_old_modified_tree()
99 # We need to unlock so that run_bzr can grab a lock

Subscribers

People subscribed via source and target branches