Merge lp:~jelmer/brz-git/read-gitfile into lp:brz-git

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 1901
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz-git/read-gitfile
Merge into: lp:brz-git
Diff against target: 98 lines (+23/-6)
4 files modified
__init__.py (+2/-2)
dir.py (+1/-1)
tests/test_dir.py (+8/-0)
transportgit.py (+12/-3)
To merge this branch: bzr merge lp:~jelmer/brz-git/read-gitfile
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+342256@code.launchpad.net

Commit message

Support reading .git files.

Description of the change

Support reading .git files.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Rubberstamp! Proposer approves of own proposal.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2018-03-26 22:28:24 +0000
3+++ __init__.py 2018-03-28 01:52:31 +0000
4@@ -136,14 +136,14 @@
5 from ... import urlutils
6 if urlutils.split(transport.base)[1] == ".git":
7 raise bzr_errors.NotBranchError(path=transport.base)
8- if not transport.has_any(['objects', '.git/objects']):
9+ if not transport.has_any(['objects', '.git/objects', '.git']):
10 raise bzr_errors.NotBranchError(path=transport.base)
11 lazy_check_versions()
12 from .dir import (
13 BareLocalGitControlDirFormat,
14 LocalGitControlDirFormat,
15 )
16- if transport.has_any(['.git/objects']):
17+ if transport.has_any(['.git/objects', '.git']):
18 return LocalGitControlDirFormat()
19 if transport.has('info') and transport.has('objects'):
20 return BareLocalGitControlDirFormat()
21
22=== modified file 'dir.py'
23--- dir.py 2018-03-26 22:28:24 +0000
24+++ dir.py 2018-03-28 01:52:31 +0000
25@@ -391,7 +391,7 @@
26
27 @property
28 def control_transport(self):
29- return self.transport
30+ return self._git._controltransport
31
32 def __init__(self, transport, gitrepo, format):
33 self._format = format
34
35=== modified file 'tests/test_dir.py'
36--- tests/test_dir.py 2018-03-17 17:34:12 +0000
37+++ tests/test_dir.py 2018-03-28 01:52:31 +0000
38@@ -67,6 +67,14 @@
39 gd = controldir.ControlDir.open('.')
40 self.assertRaises(errors.NoWorkingTree, gd.open_workingtree)
41
42+ def test_git_file(self):
43+ gitrepo = GitRepo.init("blah", mkdir=True)
44+ self.build_tree_contents([('foo/', ), ('foo/.git', 'gitdir: ../blah/.git\n')])
45+
46+ gd = controldir.ControlDir.open('foo')
47+ self.assertEqual(gd.control_url.rstrip('/'),
48+ urlutils.local_path_to_url(os.path.abspath(gitrepo.controldir())))
49+
50
51 class TestGitDirFormat(tests.TestCase):
52
53
54=== modified file 'transportgit.py'
55--- transportgit.py 2018-03-26 22:28:24 +0000
56+++ transportgit.py 2018-03-28 01:52:31 +0000
57@@ -50,11 +50,13 @@
58 RefsContainer,
59 BASE_DIRECTORIES,
60 COMMONDIR,
61+ CONTROLDIR,
62 INDEX_FILENAME,
63 OBJECTDIR,
64 REFSDIR,
65 SYMREF,
66 check_ref_format,
67+ read_gitfile,
68 read_packed_refs_with_peeled,
69 read_packed_refs,
70 write_packed_refs,
71@@ -68,6 +70,7 @@
72 FileExists,
73 LockError,
74 NoSuchFile,
75+ ReadError,
76 TransportNotPossible,
77 )
78
79@@ -349,10 +352,16 @@
80 def __init__(self, transport, bare, refs_text=None):
81 self.transport = transport
82 self.bare = bare
83- if self.bare:
84- self._controltransport = self.transport
85+ try:
86+ with transport.get(CONTROLDIR) as f:
87+ path = read_gitfile(f)
88+ except (ReadError, NoSuchFile):
89+ if self.bare:
90+ self._controltransport = self.transport
91+ else:
92+ self._controltransport = self.transport.clone('.git')
93 else:
94- self._controltransport = self.transport.clone('.git')
95+ self._controltransport = self.transport.clone(path)
96 commondir = self.get_named_file(COMMONDIR)
97 if commondir is not None:
98 with commondir:

Subscribers

People subscribed via source and target branches

to all changes: