[Pkg-bazaar-commits] r128 ./bzr-builddeb/people/jdw/merge_upstream: Make merge upstream support merging in to an empty branch.
James Westby
jw+debian at jameswestby.net
Mon Jun 25 21:37:31 UTC 2007
------------------------------------------------------------
revno: 128
committer: James Westby <jw+debian at jameswestby.net>
branch nick: merge_upstream
timestamp: Mon 2007-06-25 22:37:31 +0100
message:
Make merge upstream support merging in to an empty branch.
modified:
merge_upstream.py
tests/test_merge_upstream.py
-------------- next part --------------
=== modified file 'merge_upstream.py'
--- a/merge_upstream.py 2007-06-24 15:01:46 +0000
+++ b/merge_upstream.py 2007-06-25 21:37:31 +0000
@@ -102,59 +102,63 @@
raise BzrCommandError("Working tree has uncommitted changes.")
if not os.path.exists(source):
raise NoSuchFile(source)
- try:
- tree.branch.tags.lookup_tag(make_upstream_tag(version_number))
- raise TagAlreadyExists(make_upstream_tag(version_number))
- except NoSuchTag:
- pass
- current_revision = tree.last_revision()
- rev_id = lookup_tag(tree)
- if rev_id != tree.branch.last_revision():
- tree.revert([], tree.branch.repository.revision_tree(rev_id))
- if os.path.isdir(source):
- s = StringIO(source)
- s.seek(0)
- import_dir(tree, s)
- else:
- if (source.endswith('.tar') or source.endswith('.tar.gz') or
- source.endswith('.tar.bz2') or source.endswith('.tgz')):
- if source.endswith('.bz2'):
- tar_input = BZ2File(source, 'r')
- tar_input = StringIO(tar_input.read())
- else:
- tar_input = open(source, 'rb')
- try:
- import_tar(tree, tar_input)
- finally:
- tar_input.close()
- elif source.endswith('.zip'):
- import_zip(tree, open(source, 'rb'))
- tree.set_parent_ids([rev_id])
- tree.branch.set_last_revision_info(
- tree.branch.revision_id_to_revno(rev_id), rev_id)
- tree.commit('import upstream from %s' % os.path.basename(source))
- tree.branch.tags.set_tag(make_upstream_tag(version_number),
- tree.branch.last_revision())
- tree.merge_from_branch(tree.branch, to_revision=current_revision)
+ empty_branch = len(tree.branch.revision_history()) == 0
+ if not empty_branch:
+ try:
+ tree.branch.tags.lookup_tag(make_upstream_tag(version_number))
+ raise TagAlreadyExists(make_upstream_tag(version_number))
+ except NoSuchTag:
+ pass
+ current_revision = tree.last_revision()
+ rev_id = lookup_tag(tree)
+ if rev_id != tree.branch.last_revision():
+ tree.revert([], tree.branch.repository.revision_tree(rev_id))
+ if os.path.isdir(source):
+ s = StringIO(source)
+ s.seek(0)
+ import_dir(tree, s)
+ else:
+ if (source.endswith('.tar') or source.endswith('.tar.gz') or
+ source.endswith('.tar.bz2') or source.endswith('.tgz')):
+ if source.endswith('.bz2'):
+ tar_input = BZ2File(source, 'r')
+ tar_input = StringIO(tar_input.read())
+ else:
+ tar_input = open(source, 'rb')
+ try:
+ import_tar(tree, tar_input)
+ finally:
+ tar_input.close()
+ elif source.endswith('.zip'):
+ import_zip(tree, open(source, 'rb'))
+ tree.set_parent_ids([rev_id])
+ tree.branch.set_last_revision_info(
+ tree.branch.revision_id_to_revno(rev_id), rev_id)
+ tree.commit('import upstream from %s' % os.path.basename(source))
+ tree.branch.tags.set_tag(make_upstream_tag(version_number),
+ tree.branch.last_revision())
+ tree.merge_from_branch(tree.branch, to_revision=current_revision)
+ return
+ # Fast forward the merge.
+ if os.path.isdir(source):
+ s = StringIO(source)
+ s.seek(0)
+ import_dir(tree, s)
else:
- # Fast forward the merge.
- if os.path.isdir(source):
- s = StringIO(source)
- s.seek(0)
- import_dir(tree, s)
- else:
- if (source.endswith('.tar') or source.endswith('.tar.gz') or
- source.endswith('.tar.bz2') or source.endswith('.tgz')):
- if source.endswith('.bz2'):
- tar_input = BZ2File(source, 'r')
- tar_input = StringIO(tar_input.read())
- else:
- tar_input = open(source, 'rb')
- try:
- import_tar(tree, tar_input)
- finally:
- tar_input.close()
- elif source.endswith('.zip'):
- import_zip(tree, open(source, 'rb'))
- tree.commit('import upstream from %s' % os.path.basename(source))
+ if (source.endswith('.tar') or source.endswith('.tar.gz') or
+ source.endswith('.tar.bz2') or source.endswith('.tgz')):
+ if source.endswith('.bz2'):
+ tar_input = BZ2File(source, 'r')
+ tar_input = StringIO(tar_input.read())
+ else:
+ tar_input = open(source, 'rb')
+ try:
+ import_tar(tree, tar_input)
+ finally:
+ tar_input.close()
+ elif source.endswith('.zip'):
+ import_zip(tree, open(source, 'rb'))
+ tree.commit('import upstream from %s' % os.path.basename(source))
+ tree.branch.tags.set_tag(make_upstream_tag(version_number),
+ tree.branch.last_revision())
=== modified file 'tests/test_merge_upstream.py'
--- a/tests/test_merge_upstream.py 2007-06-24 15:01:46 +0000
+++ b/tests/test_merge_upstream.py 2007-06-25 21:37:31 +0000
@@ -176,6 +176,7 @@
self.assertEqual(revision.message,
'import upstream from %s' % \
os.path.basename(self.upstream_tarball))
+ self.assertEqual(wt.branch.tags.lookup_tag('upstream-0.2'), rh[1])
def test_merge_upstream_new_tag_extant(self):
self.make_first_upstream_commit()
@@ -300,3 +301,21 @@
os.path.basename(self.upstream_tarball))
self.assertEqual(wt.branch.tags.lookup_tag('upstream-0.2'), rh[1])
+ def test_merge_upstream_to_empty_branch(self):
+ self.wt = self.make_branch_and_tree('.', format='dirstate-tags')
+ self.make_new_upstream()
+ merge_upstream(self.wt, self.upstream_tarball, '0.2')
+ wt = self.wt
+ basis = wt.basis_tree()
+ self.assertEqual(wt.changes_from(basis).has_changed(), False)
+ parents = wt.get_parent_ids()
+ self.assertEqual(len(parents), 1)
+ self.assertEqual(wt.conflicts(), [])
+ rh = wt.branch.revision_history()
+ self.assertEqual(len(rh), 1)
+ self.assertEqual(rh[0], parents[0])
+ self.assertEqual(wt.branch.repository.get_revision(rh[0]).message,
+ 'import upstream from %s' % \
+ os.path.basename(self.upstream_tarball))
+ self.assertEqual(wt.branch.tags.lookup_tag('upstream-0.2'), rh[0])
+
More information about the Pkg-bazaar-commits
mailing list