Merge lp:~jelmer/brz-git/pushresult into lp:brz-git

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 1913
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz-git/pushresult
Merge into: lp:brz-git
Diff against target: 104 lines (+40/-7)
2 files modified
remote.py (+20/-2)
tests/test_remote.py (+20/-5)
To merge this branch: bzr merge lp:~jelmer/brz-git/pushresult
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+342484@code.launchpad.net

Commit message

Fix push result reporting.

Description of the change

Fix push result reporting.

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
lp:~jelmer/brz-git/pushresult updated
1912. By Jelmer Vernooij

Add extra tests.

1913. By Jelmer Vernooij

Fall back to local branch for revno.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'remote.py'
2--- remote.py 2018-03-31 19:47:40 +0000
3+++ remote.py 2018-03-31 20:29:37 +0000
4@@ -59,6 +59,7 @@
5 GitBranchFormat,
6 GitBranchPushResult,
7 GitTags,
8+ _quick_lookup_revno,
9 )
10 from .dir import (
11 GitControlDirFormat,
12@@ -113,6 +114,24 @@
13 from dulwich.pack import load_pack_index
14
15
16+class GitPushResult(PushResult):
17+
18+ def _lookup_revno(self, revid):
19+ try:
20+ return _quick_lookup_revno(self.source_branch, self.target_branch,
21+ revid)
22+ except GitSmartRemoteNotSupported:
23+ return None
24+
25+ @property
26+ def old_revno(self):
27+ return self._lookup_revno(self.old_revid)
28+
29+ @property
30+ def new_revno(self):
31+ return self._lookup_revno(self.new_revid)
32+
33+
34 # Don't run any tests on GitSmartTransport as it is not intended to be
35 # a full implementation of Transport
36 def get_test_permutations():
37@@ -441,7 +460,7 @@
38 # revision
39 revision_id = source.last_revision()
40
41- push_result = PushResult()
42+ push_result = GitPushResult()
43 push_result.workingtree_updated = None
44 push_result.master_branch = None
45 push_result.source_branch = source
46@@ -478,7 +497,6 @@
47 old_remote = ZERO_SHA
48 push_result.old_revid = repo.lookup_foreign_revision_id(old_remote)
49 self._refs = remote_refs_dict_to_container(new_refs)
50- push_result.old_revno = None
51 push_result.target_branch = self.open_branch(name)
52 if old_remote != ZERO_SHA:
53 push_result.branch_push_result = GitBranchPushResult()
54
55=== modified file 'tests/test_remote.py'
56--- tests/test_remote.py 2018-03-31 18:15:39 +0000
57+++ tests/test_remote.py 2018-03-31 20:29:37 +0000
58@@ -18,6 +18,8 @@
59
60 from __future__ import absolute_import
61
62+from StringIO import StringIO
63+
64 import os
65 import time
66
67@@ -211,9 +213,17 @@
68 revid = wt.commit('blah')
69
70 if self._from_format == 'git':
71- remote.push_branch(wt.branch, name='newbranch')
72- else:
73- remote.push_branch(wt.branch, lossy=True, name='newbranch')
74+ result = remote.push_branch(wt.branch, name='newbranch')
75+ else:
76+ result = remote.push_branch(wt.branch, lossy=True, name='newbranch')
77+
78+ self.assertEqual(0, result.old_revno)
79+ if self._from_format == 'git':
80+ self.assertEqual(1, result.new_revno)
81+ else:
82+ self.assertIs(None, result.new_revno)
83+
84+ result.report(StringIO())
85
86 self.assertEqual(
87 {'refs/heads/newbranch': self.remote_real.refs['refs/heads/newbranch'],
88@@ -237,9 +247,14 @@
89 wt.branch.get_config_stack().set('branch.fetch_tags', True)
90
91 if self._from_format == 'git':
92- wt.branch.push(remote.create_branch('newbranch'))
93+ result = wt.branch.push(remote.create_branch('newbranch'))
94 else:
95- wt.branch.push(remote.create_branch('newbranch'), lossy=True)
96+ result = wt.branch.push(remote.create_branch('newbranch'), lossy=True)
97+
98+ self.assertEqual(0, result.old_revno)
99+ self.assertEqual(2, result.new_revno)
100+
101+ result.report(StringIO())
102
103 self.assertEqual(
104 {'refs/heads/master': self.remote_real.head(),

Subscribers

People subscribed via source and target branches

to all changes: