Merge lp:~jelmer/brz/local-git-email into lp:brz/3.1

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/local-git-email
Merge into: lp:brz/3.1
Diff against target: 106 lines (+62/-3)
3 files modified
breezy/git/config.py (+40/-3)
breezy/git/tests/test_blackbox.py (+19/-0)
doc/en/release-notes/brz-3.1.txt (+3/-0)
To merge this branch: bzr merge lp:~jelmer/brz/local-git-email
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+380997@code.launchpad.net

Commit message

Support reading user identity from .git/config in git repositories.

Description of the change

Support reading user identity from .git/config in git repositories.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/git/config.py'
2--- breezy/git/config.py 2018-11-11 14:23:06 +0000
3+++ breezy/git/config.py 2020-03-21 22:11:54 +0000
4@@ -46,19 +46,56 @@
5 return self._get_best_value('_get_user_id')
6
7
8+class GitConfigSectionDefault(config.Section):
9+ """The "default" config section in git config file"""
10+
11+ def __init__(self, config):
12+ self._config = config
13+
14+ def get(self, name, default=None, expand=True):
15+ if name == 'email':
16+ try:
17+ email = self._config.get((b'user', ), b'email')
18+ except KeyError:
19+ return None
20+ try:
21+ name = self._config.get((b'user', ), b'name')
22+ except KeyError:
23+ return email.decode()
24+ return '%s <%s>' % (name.decode(), email.decode())
25+ return None
26+
27+
28+class GitConfigStore(config.Store):
29+ """Store that uses gitconfig."""
30+
31+ def __init__(self, config):
32+ self._config = config
33+
34+ def get_sections(self):
35+ return [
36+ (self, GitConfigSectionDefault(self._config)),
37+ ]
38+
39+
40 class GitBranchStack(config._CompatibleStack):
41 """GitBranch stack."""
42
43 def __init__(self, branch):
44+ section_getters = [self._get_overrides]
45 lstore = config.LocationStore()
46 loc_matcher = config.LocationMatcher(lstore, branch.base)
47+ section_getters.append(loc_matcher.get_sections)
48 # FIXME: This should also be looking in .git/config for
49 # local git branches.
50+ git = getattr(branch.repository, '_git', None)
51+ if git:
52+ cstore = GitConfigStore(git.get_config())
53+ section_getters.append(cstore.get_sections)
54 gstore = config.GlobalStore()
55+ section_getters.append(gstore.get_sections)
56 super(GitBranchStack, self).__init__(
57- [self._get_overrides,
58- loc_matcher.get_sections,
59- gstore.get_sections],
60+ section_getters,
61 # All modifications go to the corresponding section in
62 # locations.conf
63 lstore, branch.base)
64
65=== modified file 'breezy/git/tests/test_blackbox.py'
66--- breezy/git/tests/test_blackbox.py 2020-01-30 19:30:52 +0000
67+++ breezy/git/tests/test_blackbox.py 2020-03-21 22:11:54 +0000
68@@ -426,6 +426,25 @@
69 self.assertEqual(out, '')
70 self.assertTrue(err.endswith, '3 objects\n')
71
72+ def test_local_whoami(self):
73+ r = GitRepo.init("gitr", mkdir=True)
74+ self.build_tree_contents([('gitr/.git/config', """\
75+[user]
76+ email = some@example.com
77+ name = Test User
78+""")])
79+ out, err = self.run_bzr(["whoami", "-d", "gitr"])
80+ self.assertEqual(out, "Test User <some@example.com>\n")
81+ self.assertEqual(err, "")
82+
83+ self.build_tree_contents([('gitr/.git/config', """\
84+[user]
85+ email = some@example.com
86+""")])
87+ out, err = self.run_bzr(["whoami", "-d", "gitr"])
88+ self.assertEqual(out, "some@example.com\n")
89+ self.assertEqual(err, "")
90+
91
92 class ShallowTests(ExternalBase):
93
94
95=== modified file 'doc/en/release-notes/brz-3.1.txt'
96--- doc/en/release-notes/brz-3.1.txt 2020-02-21 22:54:31 +0000
97+++ doc/en/release-notes/brz-3.1.txt 2020-03-21 22:11:54 +0000
98@@ -114,6 +114,9 @@
99 * Python 3 is now used by default to run scripts, etc. from the makefile.
100 (Jelmer Vernooij)
101
102+ * ``.git/config`` is now consulted to determine the users' identity
103+ for commits. (Jelmer Vernooij)
104+
105 Bug Fixes
106 *********
107

Subscribers

People subscribed via source and target branches