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

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 7502
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 :
lp:~jelmer/brz/local-git-email updated
7502. By Jelmer Vernooij

handle remote repos.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/git/config.py'
--- breezy/git/config.py 2018-11-11 14:23:06 +0000
+++ breezy/git/config.py 2020-03-21 22:11:54 +0000
@@ -46,19 +46,56 @@
46 return self._get_best_value('_get_user_id')46 return self._get_best_value('_get_user_id')
4747
4848
49class GitConfigSectionDefault(config.Section):
50 """The "default" config section in git config file"""
51
52 def __init__(self, config):
53 self._config = config
54
55 def get(self, name, default=None, expand=True):
56 if name == 'email':
57 try:
58 email = self._config.get((b'user', ), b'email')
59 except KeyError:
60 return None
61 try:
62 name = self._config.get((b'user', ), b'name')
63 except KeyError:
64 return email.decode()
65 return '%s <%s>' % (name.decode(), email.decode())
66 return None
67
68
69class GitConfigStore(config.Store):
70 """Store that uses gitconfig."""
71
72 def __init__(self, config):
73 self._config = config
74
75 def get_sections(self):
76 return [
77 (self, GitConfigSectionDefault(self._config)),
78 ]
79
80
49class GitBranchStack(config._CompatibleStack):81class GitBranchStack(config._CompatibleStack):
50 """GitBranch stack."""82 """GitBranch stack."""
5183
52 def __init__(self, branch):84 def __init__(self, branch):
85 section_getters = [self._get_overrides]
53 lstore = config.LocationStore()86 lstore = config.LocationStore()
54 loc_matcher = config.LocationMatcher(lstore, branch.base)87 loc_matcher = config.LocationMatcher(lstore, branch.base)
88 section_getters.append(loc_matcher.get_sections)
55 # FIXME: This should also be looking in .git/config for89 # FIXME: This should also be looking in .git/config for
56 # local git branches.90 # local git branches.
91 git = getattr(branch.repository, '_git', None)
92 if git:
93 cstore = GitConfigStore(git.get_config())
94 section_getters.append(cstore.get_sections)
57 gstore = config.GlobalStore()95 gstore = config.GlobalStore()
96 section_getters.append(gstore.get_sections)
58 super(GitBranchStack, self).__init__(97 super(GitBranchStack, self).__init__(
59 [self._get_overrides,98 section_getters,
60 loc_matcher.get_sections,
61 gstore.get_sections],
62 # All modifications go to the corresponding section in99 # All modifications go to the corresponding section in
63 # locations.conf100 # locations.conf
64 lstore, branch.base)101 lstore, branch.base)
65102
=== modified file 'breezy/git/tests/test_blackbox.py'
--- breezy/git/tests/test_blackbox.py 2020-01-30 19:30:52 +0000
+++ breezy/git/tests/test_blackbox.py 2020-03-21 22:11:54 +0000
@@ -426,6 +426,25 @@
426 self.assertEqual(out, '')426 self.assertEqual(out, '')
427 self.assertTrue(err.endswith, '3 objects\n')427 self.assertTrue(err.endswith, '3 objects\n')
428428
429 def test_local_whoami(self):
430 r = GitRepo.init("gitr", mkdir=True)
431 self.build_tree_contents([('gitr/.git/config', """\
432[user]
433 email = some@example.com
434 name = Test User
435""")])
436 out, err = self.run_bzr(["whoami", "-d", "gitr"])
437 self.assertEqual(out, "Test User <some@example.com>\n")
438 self.assertEqual(err, "")
439
440 self.build_tree_contents([('gitr/.git/config', """\
441[user]
442 email = some@example.com
443""")])
444 out, err = self.run_bzr(["whoami", "-d", "gitr"])
445 self.assertEqual(out, "some@example.com\n")
446 self.assertEqual(err, "")
447
429448
430class ShallowTests(ExternalBase):449class ShallowTests(ExternalBase):
431450
432451
=== modified file 'doc/en/release-notes/brz-3.1.txt'
--- doc/en/release-notes/brz-3.1.txt 2020-02-21 22:54:31 +0000
+++ doc/en/release-notes/brz-3.1.txt 2020-03-21 22:11:54 +0000
@@ -114,6 +114,9 @@
114 * Python 3 is now used by default to run scripts, etc. from the makefile.114 * Python 3 is now used by default to run scripts, etc. from the makefile.
115 (Jelmer Vernooij)115 (Jelmer Vernooij)
116116
117 * ``.git/config`` is now consulted to determine the users' identity
118 for commits. (Jelmer Vernooij)
119
117Bug Fixes120Bug Fixes
118*********121*********
119122

Subscribers

People subscribed via source and target branches