45
43
b = bzrlib.branch.Branch.open('.')
46
44
b.get_config().set_user_option('email',
47
45
'Branch Identity <branch@identi.ty>')
48
whoami = self.run_bzr("whoami")[0]
49
self.assertEquals('Branch Identity <branch@identi.ty>\n', whoami)
50
whoami_email = self.run_bzr("whoami --email")[0]
51
self.assertEquals('branch@identi.ty\n', whoami_email)
46
bzr_email = os.environ.get('BZR_EMAIL')
47
if bzr_email is not None:
48
del os.environ['BZR_EMAIL']
50
whoami = self.run_bzr("whoami")[0]
51
self.assertEquals('Branch Identity <branch@identi.ty>\n', whoami)
52
whoami_email = self.run_bzr("whoami --email")[0]
53
self.assertEquals('branch@identi.ty\n', whoami_email)
53
# Verify that the environment variable overrides the value
55
os.environ['BZR_EMAIL'] = 'Different ID <other@environ.ment>'
56
whoami = self.run_bzr("whoami")[0]
57
self.assertEquals('Different ID <other@environ.ment>\n', whoami)
58
whoami_email = self.run_bzr("whoami --email")[0]
59
self.assertEquals('other@environ.ment\n', whoami_email)
55
# Verify that the environment variable overrides the value
57
os.environ['BZR_EMAIL'] = 'Different ID <other@environ.ment>'
58
whoami = self.run_bzr("whoami")[0]
59
self.assertEquals('Different ID <other@environ.ment>\n', whoami)
60
whoami_email = self.run_bzr("whoami --email")[0]
61
self.assertEquals('other@environ.ment\n', whoami_email)
62
del os.environ['BZR_EMAIL']
64
if bzr_email is not None:
65
os.environ['BZR_EMAIL'] = bzr_email
61
67
def test_whoami_utf8(self):
62
68
"""verify that an identity can be in utf-8."""
63
69
wt = self.make_branch_and_tree('.')
64
70
self.run_bzr(['whoami', u'Branch Identity \u20ac <branch@identi.ty>'],
66
whoami = self.run_bzr("whoami", encoding='utf-8')[0]
67
self.assertEquals('Branch Identity \xe2\x82\xac ' +
68
'<branch@identi.ty>\n', whoami)
69
whoami_email = self.run_bzr("whoami --email", encoding='utf-8')[0]
70
self.assertEquals('branch@identi.ty\n', whoami_email)
72
bzr_email = os.environ.get('BZR_EMAIL')
73
if bzr_email is not None:
74
del os.environ['BZR_EMAIL']
76
whoami = self.run_bzr("whoami", encoding='utf-8')[0]
77
self.assertEquals('Branch Identity \xe2\x82\xac ' +
78
'<branch@identi.ty>\n', whoami)
79
whoami_email = self.run_bzr("whoami --email",
81
self.assertEquals('branch@identi.ty\n', whoami_email)
83
if bzr_email is not None:
84
os.environ['BZR_EMAIL'] = bzr_email
72
86
def test_whoami_ascii(self):
78
92
b = bzrlib.branch.Branch.open('.')
79
93
b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
80
94
'<branch@identi.ty>')
81
whoami = self.run_bzr("whoami", encoding='ascii')[0]
82
self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami)
83
whoami_email = self.run_bzr("whoami --email", encoding='ascii')[0]
84
self.assertEquals('branch@identi.ty\n', whoami_email)
95
bzr_email = os.environ.get('BZR_EMAIL')
96
if bzr_email is not None:
97
del os.environ['BZR_EMAIL']
99
whoami = self.run_bzr("whoami", encoding='ascii')[0]
100
self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami)
101
whoami_email = self.run_bzr("whoami --email",
103
self.assertEquals('branch@identi.ty\n', whoami_email)
105
if bzr_email is not None:
106
os.environ['BZR_EMAIL'] = bzr_email
86
108
def test_warning(self):
87
109
"""verify that a warning is displayed if no email is given."""
98
120
osutils.set_or_unset_env('BZR_EMAIL', None)
99
121
out, err = self.run_bzr(['whoami'], 3)
100
122
self.assertContainsRe(err, 'Unable to determine your name')
102
def test_whoami_directory(self):
103
"""Test --directory option."""
104
wt = self.make_branch_and_tree('subdir')
105
c = wt.branch.get_config()
106
c.set_user_option('email', 'Branch Identity <branch@identi.ty>')
107
out, err = self.run_bzr("whoami --directory subdir")
108
self.assertEquals('Branch Identity <branch@identi.ty>\n', out)
109
self.run_bzr(['whoami', '--directory', 'subdir', '--branch',
110
'Changed Identity <changed@identi.ty>'])
111
self.assertEquals('Changed Identity <changed@identi.ty>',
112
c.get_user_option('email'))
114
def test_whoami_remote_directory(self):
115
"""Test --directory option with a remote directory."""
116
wt = self.make_branch_and_tree('subdir')
117
c = wt.branch.get_config()
118
c.set_user_option('email', 'Branch Identity <branch@identi.ty>')
119
url = self.get_readonly_url() + '/subdir'
120
out, err = self.run_bzr(['whoami', '--directory', url])
121
self.assertEquals('Branch Identity <branch@identi.ty>\n', out)
122
url = self.get_url('subdir')
123
self.run_bzr(['whoami', '--directory', url, '--branch',
124
'Changed Identity <changed@identi.ty>'])
125
# The identity has been set in the branch config (but not the global
127
self.assertEquals('Changed Identity <changed@identi.ty>',
128
c.get_user_option('email'))
129
global_conf = config.GlobalConfig()
130
self.assertEquals(None, global_conf.get_user_option('email'))
132
def test_whoami_nonbranch_directory(self):
133
"""Test --directory mentioning a non-branch directory."""
134
wt = self.build_tree(['subdir/'])
135
out, err = self.run_bzr("whoami --directory subdir", retcode=3)
136
self.assertContainsRe(err, 'ERROR: Not a branch')