37
37
sample_long_alias="log -r-15..-1 --line"
38
sample_config_text = u"""
40
email=Erik B\u00e5gfors <erik@bagfors.nu>
42
gpg_signing_command=gnome-gpg
44
user_global_option=something
47
ll=""" + sample_long_alias + "\n"
50
sample_always_signatures = """
52
check_signatures=ignore
53
create_signatures=always
56
sample_ignore_signatures = """
58
check_signatures=require
59
create_signatures=never
62
sample_maybe_signatures = """
64
check_signatures=ignore
65
create_signatures=when-required
68
sample_branches_text = """
69
[http://www.example.com]
71
email=Robert Collins <robertc@example.org>
72
normal_option = normal
73
appendpath_option = append
74
appendpath_option:policy = appendpath
75
norecurse_option = norecurse
76
norecurse_option:policy = norecurse
77
[http://www.example.com/ignoreparent]
78
# different project: ignore parent dir config
80
[http://www.example.com/norecurse]
81
# configuration items that only apply to this dir
83
normal_option = norecurse
84
[http://www.example.com/dir]
85
appendpath_option = normal
87
check_signatures=require
88
# test trailing / matching with no children
90
check_signatures=check-available
91
gpg_signing_command=false
92
user_local_option=local
93
# test trailing / matching
95
#subdirs will match but not the parent
97
check_signatures=ignore
98
post_commit=bzrlib.tests.test_config.post_commit
99
#testing explicit beats globs
38
sample_config_text = ("[DEFAULT]\n"
39
u"email=Erik B\u00e5gfors <erik@bagfors.nu>\n"
41
"gpg_signing_command=gnome-gpg\n"
43
"user_global_option=something\n"
46
"ll=" + sample_long_alias + "\n")
49
sample_always_signatures = ("[DEFAULT]\n"
50
"check_signatures=ignore\n"
51
"create_signatures=always")
54
sample_ignore_signatures = ("[DEFAULT]\n"
55
"check_signatures=require\n"
56
"create_signatures=never")
59
sample_maybe_signatures = ("[DEFAULT]\n"
60
"check_signatures=ignore\n"
61
"create_signatures=when-required")
64
sample_branches_text = ("[http://www.example.com]\n"
65
"# Top level policy\n"
66
"email=Robert Collins <robertc@example.org>\n"
67
"[http://www.example.com/ignoreparent]\n"
68
"# different project: ignore parent dir config\n"
69
"ignore_parents=true\n"
70
"[http://www.example.com/norecurse]\n"
71
"# configuration items that only apply to this dir\n"
74
"check_signatures=require\n"
75
"# test trailing / matching with no children\n"
77
"check_signatures=check-available\n"
78
"gpg_signing_command=false\n"
79
"user_local_option=local\n"
80
"# test trailing / matching\n"
82
"#subdirs will match but not the parent\n"
84
"check_signatures=ignore\n"
85
"post_commit=bzrlib.tests.test_config.post_commit\n"
86
"#testing explicit beats globs\n")
103
90
class InstrumentedConfigObj(object):
117
104
def __setitem__(self, key, value):
118
105
self._calls.append(('__setitem__', key, value))
120
def __delitem__(self, key):
121
self._calls.append(('__delitem__', key))
124
self._calls.append(('keys',))
127
107
def write(self, arg):
128
108
self._calls.append(('write',))
130
def as_bool(self, value):
131
self._calls.append(('as_bool', value))
134
def get_value(self, section, name):
135
self._calls.append(('get_value', section, name))
139
111
class FakeBranch(object):
271
243
super(TestConfigPath, self).setUp()
244
self.old_home = os.environ.get('HOME', None)
245
self.old_appdata = os.environ.get('APPDATA', None)
272
246
os.environ['HOME'] = '/home/bogus'
273
if sys.platform == 'win32':
274
os.environ['BZR_HOME'] = \
275
r'C:\Documents and Settings\bogus\Application Data'
247
os.environ['APPDATA'] = \
248
r'C:\Documents and Settings\bogus\Application Data'
251
if self.old_home is None:
252
del os.environ['HOME']
254
os.environ['HOME'] = self.old_home
255
if self.old_appdata is None:
256
del os.environ['APPDATA']
258
os.environ['APPDATA'] = self.old_appdata
259
super(TestConfigPath, self).tearDown()
277
261
def test_config_dir(self):
278
262
if sys.platform == 'win32':
279
263
self.assertEqual(config.config_dir(),
402
386
def test_config_creates_local(self):
403
387
"""Creating a new entry in config uses a local path."""
404
branch = self.make_branch('branch', format='knit')
388
branch = self.make_branch('branch')
405
389
branch.set_push_location('http://foobar')
406
390
locations = config.locations_config_filename()
407
391
local_path = osutils.getcwd().encode('utf8')
408
392
# Surprisingly ConfigObj doesn't create a trailing newline
409
393
self.check_file_contents(locations,
410
'[%s/branch]\npush_location = http://foobar\npush_location:policy = norecurse' % (local_path,))
412
def test_autonick_urlencoded(self):
413
b = self.make_branch('!repo')
414
self.assertEqual('!repo', b.get_config().get_nickname())
394
'[%s/branch]\npush_location = http://foobar' % (local_path,))
417
397
class TestGlobalConfigItems(TestCase):
586
566
self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
587
567
self.my_location_config._get_matching_sections())
569
def test__get_matching_sections_norecurse(self):
570
self.get_branch_config('http://www.example.com/norecurse')
571
self.assertEqual([('http://www.example.com/norecurse', ''),
572
('http://www.example.com', 'norecurse')],
573
self.my_location_config._get_matching_sections())
575
def test__get_matching_sections_norecurse_subdir(self):
576
self.get_branch_config(
577
'http://www.example.com/norecurse/childbranch')
578
self.assertEqual([('http://www.example.com', 'norecurse/childbranch')],
579
self.my_location_config._get_matching_sections())
589
581
def test__get_matching_sections_subdir_trailing_slash(self):
590
582
self.get_branch_config('/b')
591
583
self.assertEqual([('/b/', '')],
615
607
self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
616
608
self.my_location_config._get_matching_sections())
618
def test__get_option_policy_normal(self):
619
self.get_branch_config('http://www.example.com')
621
self.my_location_config._get_config_policy(
622
'http://www.example.com', 'normal_option'),
625
def test__get_option_policy_norecurse(self):
626
self.get_branch_config('http://www.example.com')
628
self.my_location_config._get_option_policy(
629
'http://www.example.com', 'norecurse_option'),
630
config.POLICY_NORECURSE)
631
# Test old recurse=False setting:
633
self.my_location_config._get_option_policy(
634
'http://www.example.com/norecurse', 'normal_option'),
635
config.POLICY_NORECURSE)
637
def test__get_option_policy_normal(self):
638
self.get_branch_config('http://www.example.com')
640
self.my_location_config._get_option_policy(
641
'http://www.example.com', 'appendpath_option'),
642
config.POLICY_APPENDPATH)
644
610
def test_location_without_username(self):
645
611
self.get_branch_config('http://www.example.com/ignoreparent')
646
612
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
698
664
self.assertEqual('local',
699
665
self.my_config.get_user_option('user_local_option'))
701
def test_get_user_option_appendpath(self):
702
# returned as is for the base path:
703
self.get_branch_config('http://www.example.com')
704
self.assertEqual('append',
705
self.my_config.get_user_option('appendpath_option'))
706
# Extra path components get appended:
707
self.get_branch_config('http://www.example.com/a/b/c')
708
self.assertEqual('append/a/b/c',
709
self.my_config.get_user_option('appendpath_option'))
710
# Overriden for http://www.example.com/dir, where it is a
712
self.get_branch_config('http://www.example.com/dir/a/b/c')
713
self.assertEqual('normal',
714
self.my_config.get_user_option('appendpath_option'))
716
def test_get_user_option_norecurse(self):
717
self.get_branch_config('http://www.example.com')
718
self.assertEqual('norecurse',
719
self.my_config.get_user_option('norecurse_option'))
720
self.get_branch_config('http://www.example.com/dir')
721
self.assertEqual(None,
722
self.my_config.get_user_option('norecurse_option'))
723
# http://www.example.com/norecurse is a recurse=False section
724
# that redefines normal_option. Subdirectories do not pick up
726
self.get_branch_config('http://www.example.com/norecurse')
727
self.assertEqual('norecurse',
728
self.my_config.get_user_option('normal_option'))
729
self.get_branch_config('http://www.example.com/norecurse/subdir')
730
self.assertEqual('normal',
731
self.my_config.get_user_option('normal_option'))
733
def test_set_user_option_norecurse(self):
734
self.get_branch_config('http://www.example.com')
735
self.my_config.set_user_option('foo', 'bar',
736
store=config.STORE_LOCATION_NORECURSE)
738
self.my_location_config._get_option_policy(
739
'http://www.example.com', 'foo'),
740
config.POLICY_NORECURSE)
742
def test_set_user_option_appendpath(self):
743
self.get_branch_config('http://www.example.com')
744
self.my_config.set_user_option('foo', 'bar',
745
store=config.STORE_LOCATION_APPENDPATH)
747
self.my_location_config._get_option_policy(
748
'http://www.example.com', 'foo'),
749
config.POLICY_APPENDPATH)
751
def test_set_user_option_change_policy(self):
752
self.get_branch_config('http://www.example.com')
753
self.my_config.set_user_option('norecurse_option', 'normal',
754
store=config.STORE_LOCATION)
756
self.my_location_config._get_option_policy(
757
'http://www.example.com', 'norecurse_option'),
760
def test_set_user_option_recurse_false_section(self):
761
# The following section has recurse=False set. The test is to
762
# make sure that a normal option can be added to the section,
763
# converting recurse=False to the norecurse policy.
764
self.get_branch_config('http://www.example.com/norecurse')
765
self.callDeprecated(['The recurse option is deprecated as of 0.14. '
766
'The section "http://www.example.com/norecurse" '
767
'has been converted to use policies.'],
768
self.my_config.set_user_option,
769
'foo', 'bar', store=config.STORE_LOCATION)
771
self.my_location_config._get_option_policy(
772
'http://www.example.com/norecurse', 'foo'),
774
# The previously existing option is still norecurse:
776
self.my_location_config._get_option_policy(
777
'http://www.example.com/norecurse', 'normal_option'),
778
config.POLICY_NORECURSE)
781
667
def test_post_commit_default(self):
782
668
self.get_branch_config('/a/c')
783
669
self.assertEqual('bzrlib.tests.test_config.post_commit',