bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.436.2
by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands. |
1 |
# Copyright (C) 2007 by Jelmer Vernooij
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
0.436.1
by Jelmer Vernooij
Add framework for git-rebase plugin. |
16 |
|
|
0.436.4
by Jelmer Vernooij
Add some tests. |
17 |
from bzrlib.commands import Command, Option, display_command, register_command |
|
0.436.16
by Jelmer Vernooij
Some more work on maptree. |
18 |
from bzrlib.errors import (BzrCommandError, ConflictsInTree, NoSuchFile, |
19 |
UnrelatedBranches) |
|
|
0.436.9
by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue. |
20 |
from bzrlib.trace import info |
|
0.436.1
by Jelmer Vernooij
Add framework for git-rebase plugin. |
21 |
|
22 |
class cmd_rebase(Command): |
|
23 |
"""Re-base a branch. |
|
24 |
||
25 |
"""
|
|
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
26 |
takes_args = ['upstream_location?'] |
|
0.436.19
by Jelmer Vernooij
- Add blackbox tests |
27 |
takes_options = ['revision', 'merge-type', 'verbose', |
|
0.436.13
by Jelmer Vernooij
Add progress bar, some optimizations. Make merge type configurable. |
28 |
Option('onto', help='Different revision to replay onto')] |
|
0.436.1
by Jelmer Vernooij
Add framework for git-rebase plugin. |
29 |
|
30 |
@display_command
|
|
|
0.436.16
by Jelmer Vernooij
Some more work on maptree. |
31 |
def run(self, upstream_location=None, onto=None, revision=None, |
|
0.436.19
by Jelmer Vernooij
- Add blackbox tests |
32 |
merge_type=None, verbose=False): |
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
33 |
from bzrlib.branch import Branch |
34 |
from bzrlib.revisionspec import RevisionSpec |
|
35 |
from bzrlib.workingtree import WorkingTree |
|
|
0.436.16
by Jelmer Vernooij
Some more work on maptree. |
36 |
from rebase import (generate_simple_plan, rebase, rebase_plan_exists, |
37 |
read_rebase_plan, remove_rebase_plan, |
|
38 |
workingtree_replay, write_rebase_plan) |
|
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
39 |
wt = WorkingTree.open('.') |
40 |
wt.lock_write() |
|
41 |
if upstream_location is None: |
|
42 |
upstream_location = wt.branch.get_parent() |
|
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
43 |
upstream = Branch.open(upstream_location) |
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
44 |
upstream_repository = upstream.repository |
45 |
upstream_revision = upstream.last_revision() |
|
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
46 |
try: |
47 |
# Abort if there already is a plan file
|
|
48 |
if rebase_plan_exists(wt): |
|
49 |
raise BzrCommandError("A rebase operation was interrupted. Continue using 'bzr rebase-continue' or abort using 'bzr rebase-abort'") |
|
50 |
||
51 |
# Pull required revisions
|
|
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
52 |
wt.branch.repository.fetch(upstream_repository, |
53 |
upstream_revision) |
|
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
54 |
if onto is None: |
55 |
onto = upstream.last_revision() |
|
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
56 |
else: |
57 |
onto = RevisionSpec.from_string(onto) |
|
58 |
||
59 |
wt.branch.repository.fetch(upstream_repository, onto) |
|
60 |
||
61 |
revhistory = wt.branch.revision_history() |
|
62 |
revhistory.reverse() |
|
|
0.436.12
by Jelmer Vernooij
Give sane error when branch is already rebased. |
63 |
common_revid = None |
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
64 |
for revid in revhistory: |
65 |
if revid in upstream.revision_history(): |
|
|
0.436.12
by Jelmer Vernooij
Give sane error when branch is already rebased. |
66 |
common_revid = revid |
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
67 |
break
|
68 |
||
|
0.436.12
by Jelmer Vernooij
Give sane error when branch is already rebased. |
69 |
if common_revid is None: |
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
70 |
raise UnrelatedBranches() |
|
0.436.4
by Jelmer Vernooij
Add some tests. |
71 |
|
|
0.436.12
by Jelmer Vernooij
Give sane error when branch is already rebased. |
72 |
if common_revid == upstream.last_revision(): |
73 |
raise BzrCommandError("Already rebased on %s" % upstream) |
|
74 |
||
|
0.436.16
by Jelmer Vernooij
Some more work on maptree. |
75 |
start_revid = wt.branch.get_rev_id( |
76 |
wt.branch.revision_id_to_revno(common_revid)+1) |
|
|
0.436.12
by Jelmer Vernooij
Give sane error when branch is already rebased. |
77 |
|
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
78 |
# Create plan
|
|
0.436.4
by Jelmer Vernooij
Add some tests. |
79 |
replace_map = generate_simple_plan( |
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
80 |
wt.branch.repository, |
81 |
wt.branch.revision_history(), start_revid, onto) |
|
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
82 |
|
83 |
# Write plan file
|
|
|
0.436.4
by Jelmer Vernooij
Add some tests. |
84 |
write_rebase_plan(wt, replace_map) |
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
85 |
|
|
0.436.19
by Jelmer Vernooij
- Add blackbox tests |
86 |
if verbose: |
87 |
for revid in rebase_todo(wt.branch.repository, replace_map): |
|
88 |
info("%s -> %s" % (revid, replace_map[revid][0])) |
|
89 |
||
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
90 |
# Start executing plan
|
91 |
try: |
|
|
0.436.13
by Jelmer Vernooij
Add progress bar, some optimizations. Make merge type configurable. |
92 |
rebase(wt.branch.repository, replace_map, workingtree_replay(wt, merge_type=merge_type)) |
|
0.436.8
by Jelmer Vernooij
Couple more minor fixes. |
93 |
except ConflictsInTree: |
94 |
raise BzrCommandError("A conflict occurred replaying a commit. Resolve the conflict and run 'bzr rebase-continue' or run 'bzr rebase-abort'.") |
|
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
95 |
# Remove plan file
|
96 |
remove_rebase_plan(wt) |
|
97 |
finally: |
|
98 |
wt.unlock() |
|
|
0.436.2
by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands. |
99 |
|
|
0.436.12
by Jelmer Vernooij
Give sane error when branch is already rebased. |
100 |
|
|
0.436.2
by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands. |
101 |
class cmd_rebase_abort(Command): |
102 |
"""Abort an interrupted rebase |
|
103 |
||
104 |
"""
|
|
105 |
||
106 |
@display_command
|
|
107 |
def run(self): |
|
|
0.436.10
by Jelmer Vernooij
Add more agressive version of revert. |
108 |
from rebase import read_rebase_plan, remove_rebase_plan, complete_revert |
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
109 |
from bzrlib.workingtree import WorkingTree |
|
0.436.2
by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands. |
110 |
wt = WorkingTree.open('.') |
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
111 |
wt.lock_write() |
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
112 |
try: |
113 |
# Read plan file and set last revision
|
|
|
0.436.9
by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue. |
114 |
try: |
115 |
last_rev_info = read_rebase_plan(wt)[0] |
|
116 |
except NoSuchFile: |
|
117 |
raise BzrCommandError("No rebase to abort") |
|
|
0.436.10
by Jelmer Vernooij
Add more agressive version of revert. |
118 |
complete_revert(wt, [last_rev_info[1]]) |
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
119 |
remove_rebase_plan(wt) |
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
120 |
finally: |
121 |
wt.unlock() |
|
|
0.436.2
by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands. |
122 |
|
123 |
||
124 |
class cmd_rebase_continue(Command): |
|
125 |
"""Continue an interrupted rebase after resolving conflicts |
|
126 |
||
127 |
"""
|
|
|
0.436.13
by Jelmer Vernooij
Add progress bar, some optimizations. Make merge type configurable. |
128 |
takes_options = ['merge-type'] |
|
0.436.2
by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands. |
129 |
|
130 |
@display_command
|
|
|
0.436.13
by Jelmer Vernooij
Add progress bar, some optimizations. Make merge type configurable. |
131 |
def run(self, merge_type=None): |
|
0.436.16
by Jelmer Vernooij
Some more work on maptree. |
132 |
from rebase import (commit_rebase, rebase, rebase_plan_exists, |
133 |
read_rebase_plan, read_active_rebase_revid, |
|
134 |
remove_rebase_plan, workingtree_replay) |
|
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
135 |
from bzrlib.workingtree import WorkingTree |
|
0.436.2
by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands. |
136 |
wt = WorkingTree.open('.') |
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
137 |
wt.lock_write() |
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
138 |
try: |
139 |
# Abort if there are any conflicts
|
|
140 |
if len(wt.conflicts()) != 0: |
|
141 |
raise BzrCommandError("There are still conflicts present") |
|
142 |
# Read plan file
|
|
|
0.436.9
by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue. |
143 |
try: |
144 |
replace_map = read_rebase_plan(wt)[1] |
|
145 |
except NoSuchFile: |
|
146 |
raise BzrCommandError("No rebase to continue") |
|
147 |
oldrevid = read_active_rebase_revid(wt) |
|
148 |
if oldrevid is not None: |
|
149 |
oldrev = wt.branch.repository.get_revision(oldrevid) |
|
150 |
commit_rebase(wt, oldrev, replace_map[oldrevid][0]) |
|
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
151 |
try: |
152 |
# Start executing plan from current Branch.last_revision()
|
|
|
0.436.16
by Jelmer Vernooij
Some more work on maptree. |
153 |
rebase(wt.branch.repository, replace_map, |
154 |
workingtree_replay(wt, merge_type=merge_type)) |
|
|
0.436.8
by Jelmer Vernooij
Couple more minor fixes. |
155 |
except ConflictsInTree: |
156 |
raise BzrCommandError("A conflict occurred replaying a commit. Resolve the conflict and run 'bzr rebase-continue' or run 'bzr rebase-abort'.") |
|
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
157 |
# Remove plan file
|
158 |
remove_rebase_plan(wt) |
|
159 |
finally: |
|
160 |
wt.unlock() |
|
|
0.436.2
by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands. |
161 |
|
162 |
||
|
0.436.9
by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue. |
163 |
class cmd_rebase_todo(Command): |
|
0.436.16
by Jelmer Vernooij
Some more work on maptree. |
164 |
"""Print list of revisions that still need to be replayed as part of the |
165 |
current rebase operation.
|
|
|
0.436.9
by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue. |
166 |
|
167 |
"""
|
|
168 |
||
169 |
def run(self): |
|
|
0.436.16
by Jelmer Vernooij
Some more work on maptree. |
170 |
from rebase import (rebase_todo, read_rebase_plan, |
171 |
read_active_rebase_revid) |
|
|
0.436.9
by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue. |
172 |
from bzrlib.workingtree import WorkingTree |
173 |
wt = WorkingTree.open('.') |
|
174 |
wt.lock_read() |
|
175 |
try: |
|
176 |
try: |
|
177 |
replace_map = read_rebase_plan(wt)[1] |
|
178 |
except NoSuchFile: |
|
|
0.436.16
by Jelmer Vernooij
Some more work on maptree. |
179 |
raise BzrCommandError("No rebase in progress") |
|
0.436.9
by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue. |
180 |
currentrevid = read_active_rebase_revid(wt) |
181 |
if currentrevid is not None: |
|
182 |
info("Currently replaying: %s" % currentrevid) |
|
183 |
for revid in rebase_todo(wt.branch.repository, replace_map): |
|
184 |
info("%s -> %s" % (revid, replace_map[revid][0])) |
|
185 |
finally: |
|
186 |
wt.unlock() |
|
187 |
||
|
0.436.10
by Jelmer Vernooij
Add more agressive version of revert. |
188 |
|
|
0.436.4
by Jelmer Vernooij
Add some tests. |
189 |
register_command(cmd_rebase) |
190 |
register_command(cmd_rebase_abort) |
|
191 |
register_command(cmd_rebase_continue) |
|
|
0.436.9
by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue. |
192 |
register_command(cmd_rebase_todo) |
|
0.436.4
by Jelmer Vernooij
Add some tests. |
193 |
|
|
0.436.2
by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands. |
194 |
def test_suite(): |
195 |
from unittest import TestSuite |
|
196 |
from bzrlib.tests import TestUtil |
|
197 |
||
198 |
loader = TestUtil.TestLoader() |
|
199 |
suite = TestSuite() |
|
|
0.436.19
by Jelmer Vernooij
- Add blackbox tests |
200 |
testmod_names = ['test_blackbox', 'test_rebase', 'test_maptree'] |
|
0.436.16
by Jelmer Vernooij
Some more work on maptree. |
201 |
suite.addTest(loader.loadTestsFromModuleNames( |
202 |
["%s.%s" % (__name__, i) for i in testmod_names])) |
|
|
0.436.2
by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands. |
203 |
|
204 |
return suite |
|
|
0.436.1
by Jelmer Vernooij
Add framework for git-rebase plugin. |
205 |