1
# Copyright (C) 2006, 2007, 2009, 2010, 2011 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2009-2012 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
53
54
"""branch specific user identity works."""
54
55
wt = self.make_branch_and_tree('.')
55
56
b = bzrlib.branch.Branch.open('.')
56
b.get_config().set_user_option('email',
57
'Branch Identity <branch@identi.ty>')
57
b.get_config_stack().set('email', 'Branch Identity <branch@identi.ty>')
58
58
self.assertWhoAmI('Branch Identity <branch@identi.ty>')
59
59
self.assertWhoAmI('branch@identi.ty', '--email')
80
80
wt = self.make_branch_and_tree('.')
81
81
b = bzrlib.branch.Branch.open('.')
82
b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
82
b.get_config_stack().set(
83
'email', u'Branch Identity \u20ac ' + '<branch@identi.ty>')
84
84
self.assertWhoAmI('Branch Identity ? <branch@identi.ty>',
86
86
self.assertWhoAmI('branch@identi.ty', '--email',
108
108
def test_whoami_directory(self):
109
109
"""Test --directory option."""
110
110
wt = self.make_branch_and_tree('subdir')
111
c = wt.branch.get_config()
112
c.set_user_option('email', 'Branch Identity <branch@identi.ty>')
111
c = wt.branch.get_config_stack()
112
c.set('email', 'Branch Identity <branch@identi.ty>')
113
113
self.assertWhoAmI('Branch Identity <branch@identi.ty>',
114
114
'--directory', 'subdir')
115
115
self.run_bzr(['whoami', '--directory', 'subdir', '--branch',
116
116
'Changed Identity <changed@identi.ty>'])
117
c = wt.branch.get_config()
117
c = wt.branch.get_config_stack()
118
118
self.assertEquals('Changed Identity <changed@identi.ty>',
119
c.get_user_option('email'))
121
121
def test_whoami_remote_directory(self):
122
122
"""Test --directory option with a remote directory."""
123
123
wt = self.make_branch_and_tree('subdir')
124
c = wt.branch.get_config()
125
c.set_user_option('email', 'Branch Identity <branch@identi.ty>')
124
c = wt.branch.get_config_stack()
125
c.set('email', 'Branch Identity <branch@identi.ty>')
126
126
url = self.get_readonly_url() + '/subdir'
127
127
self.assertWhoAmI('Branch Identity <branch@identi.ty>',
128
128
'--directory', url)
131
131
'Changed Identity <changed@identi.ty>'])
132
132
# The identity has been set in the branch config (but not the global
134
c = wt.branch.get_config()
134
c = wt.branch.get_config_stack()
135
135
self.assertEquals('Changed Identity <changed@identi.ty>',
136
c.get_user_option('email'))
137
global_conf = config.GlobalConfig()
138
self.assertEquals(None, global_conf.get_user_option('email'))
137
# Ensuring that the value does not come from the bazaar.conf file
138
# itself requires some isolation setup
139
self.overrideEnv('BZR_EMAIL', None)
140
self.overrideEnv('EMAIL', None)
141
self.overrideAttr(config, '_auto_user_id', lambda: (None, None))
142
global_conf = config.GlobalStack()
143
self.assertRaises(errors.NoWhoami, global_conf.get, 'email')
140
145
def test_whoami_nonbranch_directory(self):
141
146
"""Test --directory mentioning a non-branch directory."""