Merge lp:~jelmer/brz/git-fixes into lp:brz/3.0

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/git-fixes
Merge into: lp:brz/3.0
Diff against target: 142 lines (+54/-8)
5 files modified
breezy/git/cache.py (+1/-3)
breezy/git/git-remote-bzr (+7/-2)
breezy/git/git_remote_helper.py (+1/-1)
breezy/git/tests/test_git_remote_helper.py (+31/-2)
breezy/tests/features.py (+14/-0)
To merge this branch: bzr merge lp:~jelmer/brz/git-fixes
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+363690@code.launchpad.net

Commit message

Fix git-remote-helper and git directory cache setting for bzr remote repositories.

Description of the change

Some more git fixes:

* Fix git-remote-helper
* Fix finding of cache directory for remote URLs

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Looks good, nice to have a test even if it requires subprocess usage inline.

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 :
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/cache.py'
2--- breezy/git/cache.py 2018-11-12 01:41:38 +0000
3+++ breezy/git/cache.py 2019-03-04 07:15:42 +0000
4@@ -613,11 +613,9 @@
5
6 def open(self, transport):
7 try:
8- basepath = transport.local_abspath(".").encode(osutils._fs_enc)
9+ basepath = transport.local_abspath(".")
10 except bzr_errors.NotLocalUrl:
11 basepath = get_cache_dir()
12- if not isinstance(basepath, str):
13- raise TypeError(basepath)
14 try:
15 return TdbBzrGitCache(os.path.join(basepath, "idmap.tdb"))
16 except ImportError:
17
18=== modified file 'breezy/git/git-remote-bzr'
19--- breezy/git/git-remote-bzr 2018-03-26 22:28:24 +0000
20+++ breezy/git/git-remote-bzr 2019-03-04 07:15:42 +0000
21@@ -32,10 +32,12 @@
22 import breezy
23 breezy.initialize()
24
25+from breezy.sixish import PY3
26+
27 from breezy.plugin import load_plugins
28 load_plugins()
29
30-from breezy.plugins.git.git_remote_helper import (
31+from breezy.git.git_remote_helper import (
32 RemoteHelper,
33 open_local_dir,
34 open_remote_dir,
35@@ -46,4 +48,7 @@
36 (shortname, url) = args
37
38 helper = RemoteHelper(open_local_dir(), shortname, open_remote_dir(url))
39-helper.process(sys.stdin, sys.stdout)
40+if PY3:
41+ helper.process(sys.stdin.buffer, sys.stdout.buffer)
42+else:
43+ helper.process(sys.stdin, sys.stdout)
44
45=== modified file 'breezy/git/git_remote_helper.py'
46--- breezy/git/git_remote_helper.py 2018-11-11 14:23:06 +0000
47+++ breezy/git/git_remote_helper.py 2019-03-04 07:15:42 +0000
48@@ -186,7 +186,7 @@
49 self.batchcmd = None
50 else:
51 try:
52- self.commands[argv[0]](self, outf, argv)
53+ self.commands[argv[0].decode()](self, outf, argv)
54 except KeyError:
55 raise Exception("Unknown remote command %r" % argv)
56 outf.flush()
57
58=== modified file 'breezy/git/tests/test_git_remote_helper.py'
59--- breezy/git/tests/test_git_remote_helper.py 2018-11-21 03:39:28 +0000
60+++ breezy/git/tests/test_git_remote_helper.py 2019-03-04 07:15:42 +0000
61@@ -23,12 +23,15 @@
62
63 from io import BytesIO
64 import os
65+import subprocess
66+import sys
67
68 from dulwich.repo import Repo
69
70 from ...tests import (
71 TestCaseWithTransport,
72 )
73+from ...tests.features import PathFeature
74
75 from ..object_store import get_object_store
76 from ..git_remote_helper import (
77@@ -46,6 +49,11 @@
78 return object_store._lookup_revision_sha1(bzr_revid)
79
80
81+git_remote_bzr_path = os.path.abspath(
82+ os.path.join(os.path.dirname(__file__), '..', 'git-remote-bzr'))
83+git_remote_bzr_feature = PathFeature(git_remote_bzr_path)
84+
85+
86 class OpenLocalDirTests(TestCaseWithTransport):
87
88 def test_from_env_dir(self):
89@@ -86,8 +94,29 @@
90 self.assertEqual(out, b"\n")
91 r = Repo('local')
92 self.assertTrue(git_sha1 in r.object_store)
93- self.assertEqual({
94- }, r.get_refs())
95+ self.assertEqual({}, r.get_refs())
96+
97+
98+class ExecuteRemoteHelperTests(TestCaseWithTransport):
99+
100+ def test_run(self):
101+ self.requireFeature(git_remote_bzr_feature)
102+ local_dir = self.make_branch_and_tree('local', format='git').controldir
103+ local_path = local_dir.control_transport.local_abspath('.')
104+ remote_tree = self.make_branch_and_tree('remote')
105+ remote_dir = remote_tree.controldir
106+ shortname = 'bzr'
107+ env = dict(os.environ)
108+ env['GIT_DIR'] = local_path
109+ env['PYTHONPATH'] = ':'.join(sys.path)
110+ p = subprocess.Popen(
111+ [sys.executable, git_remote_bzr_path, local_path, remote_dir.user_url],
112+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,
113+ stderr=subprocess.PIPE, env=env)
114+ (out, err) = p.communicate(b'capabilities\n')
115+ lines = out.splitlines()
116+ self.assertIn(b'push', lines, "no 'push' in %r, error: %r" % (lines, err))
117+ self.assertEqual(b'', err)
118
119
120 class RemoteHelperTests(TestCaseWithTransport):
121
122=== modified file 'breezy/tests/features.py'
123--- breezy/tests/features.py 2019-01-19 01:44:20 +0000
124+++ breezy/tests/features.py 2019-03-04 07:15:42 +0000
125@@ -568,3 +568,17 @@
126
127
128 BackslashFilenameFeature = _BackslashFilenameFeature()
129+
130+
131+class PathFeature(Feature):
132+ """Feature testing whether a particular path exists."""
133+
134+ def __init__(self, path):
135+ super(PathFeature, self).__init__()
136+ self.path = path
137+
138+ def _probe(self):
139+ return os.path.exists(self.path)
140+
141+ def feature_name(self):
142+ return "%s exists" % self.path

Subscribers

People subscribed via source and target branches