Beispiel #1
0
    def test_file_moves(self):
        """Test moves"""
        builder = MergeBuilder(getcwd())
        builder.add_dir("1", builder.tree_root, "dir1")
        builder.add_dir("2", builder.tree_root, "dir2")
        builder.add_file("3", "1", "file1", "hello1", True)
        builder.add_file("4", "1", "file2", "hello2", True)
        builder.add_file("5", "1", "file3", "hello3", True)
        builder.change_parent("3", other="2")
        builder.change_parent("4", this="2")
        builder.change_parent("5", base="2")
        builder.merge()
        builder.cleanup()

        builder = MergeBuilder(getcwd())
        builder.add_dir("1", builder.tree_root, "dir1")
        builder.add_dir("2", builder.tree_root, "dir2")
        builder.add_dir("3", builder.tree_root, "dir3")
        builder.add_file("4", "1", "file1", "hello1", False)
        builder.change_parent("4", other="2", this="3")
        conflicts = builder.merge()
        path2 = pathjoin('dir2', 'file1')
        path3 = pathjoin('dir3', 'file1')
        self.assertEqual(conflicts, [PathConflict(path3, path2, '4')])
        builder.cleanup()
Beispiel #2
0
    def test_run_bzr_subprocess_working_dir(self):
        """Test that we can specify the working dir for the child"""
        cwd = osutils.getcwd()

        self.make_branch_and_tree('.')
        self.make_branch_and_tree('one')
        self.make_branch_and_tree('two')

        def get_root(**kwargs):
            """Spawn a process to get the 'root' of the tree.

            You can pass in arbitrary new arguments. This just makes
            sure that the returned path doesn't have trailing whitespace.
            """
            return self.run_bzr_subprocess('root', **kwargs)[0].rstrip()

        self.assertEqual(cwd, get_root())
        self.assertEqual(cwd, get_root(working_dir=None))
        # Has our path changed?
        self.assertEqual(cwd, osutils.getcwd())

        dir1 = get_root(working_dir='one')
        self.assertEndsWith(dir1, 'one')
        self.assertEqual(cwd, osutils.getcwd())

        dir2 = get_root(working_dir='two')
        self.assertEndsWith(dir2, 'two')
        self.assertEqual(cwd, osutils.getcwd())
Beispiel #3
0
    def test_open_containing(self):
        branch = self.make_branch_and_tree('.').branch
        local_base = urlutils.local_path_from_url(branch.base)

        # Empty opens '.'
        wt, relpath = WorkingTree.open_containing()
        self.assertEqual('', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # '.' opens this dir
        wt, relpath = WorkingTree.open_containing(u'.')
        self.assertEqual('', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # './foo' finds '.' and a relpath of 'foo'
        wt, relpath = WorkingTree.open_containing('./foo')
        self.assertEqual('foo', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # abspath(foo) finds '.' and relpath of 'foo'
        wt, relpath = WorkingTree.open_containing('./foo')
        wt, relpath = WorkingTree.open_containing(getcwd() + '/foo')
        self.assertEqual('foo', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # can even be a url: finds '.' and relpath of 'foo'
        wt, relpath = WorkingTree.open_containing('./foo')
        wt, relpath = WorkingTree.open_containing(
                    urlutils.local_path_to_url(getcwd() + '/foo'))
        self.assertEqual('foo', relpath)
        self.assertEqual(wt.basedir + '/', local_base)
Beispiel #4
0
    def test_run_bzr_subprocess_working_dir(self):
        """Test that we can specify the working dir for the child"""
        cwd = osutils.getcwd()

        self.make_branch_and_tree('.')
        self.make_branch_and_tree('one')
        self.make_branch_and_tree('two')

        def get_root(**kwargs):
            """Spawn a process to get the 'root' of the tree.

            You can pass in arbitrary new arguments. This just makes
            sure that the returned path doesn't have trailing whitespace.
            """
            return self.run_bzr_subprocess('root', **kwargs)[0].rstrip()

        self.assertEqual(cwd, get_root())
        self.assertEqual(cwd, get_root(working_dir=None))
        # Has our path changed?
        self.assertEqual(cwd, osutils.getcwd())

        dir1 = get_root(working_dir='one')
        self.assertEndsWith(dir1, 'one')
        self.assertEqual(cwd, osutils.getcwd())

        dir2 = get_root(working_dir='two')
        self.assertEndsWith(dir2, 'two')
        self.assertEqual(cwd, osutils.getcwd())
Beispiel #5
0
    def test_open_containing(self):
        branch = self.make_branch_and_tree('.').branch
        local_base = urlutils.local_path_from_url(branch.base)

        # Empty opens '.'
        wt, relpath = WorkingTree.open_containing()
        self.assertEqual('', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # '.' opens this dir
        wt, relpath = WorkingTree.open_containing(u'.')
        self.assertEqual('', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # './foo' finds '.' and a relpath of 'foo'
        wt, relpath = WorkingTree.open_containing('./foo')
        self.assertEqual('foo', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # abspath(foo) finds '.' and relpath of 'foo'
        wt, relpath = WorkingTree.open_containing('./foo')
        wt, relpath = WorkingTree.open_containing(getcwd() + '/foo')
        self.assertEqual('foo', relpath)
        self.assertEqual(wt.basedir + '/', local_base)

        # can even be a url: finds '.' and relpath of 'foo'
        wt, relpath = WorkingTree.open_containing('./foo')
        wt, relpath = WorkingTree.open_containing(
            urlutils.local_path_to_url(getcwd() + '/foo'))
        self.assertEqual('foo', relpath)
        self.assertEqual(wt.basedir + '/', local_base)
Beispiel #6
0
    def test_file_moves(self):
        """Test moves"""
        builder = MergeBuilder(getcwd())
        builder.add_dir("1", builder.tree_root, "dir1")
        builder.add_dir("2", builder.tree_root, "dir2")
        builder.add_file("3", "1", "file1", "hello1", True)
        builder.add_file("4", "1", "file2", "hello2", True)
        builder.add_file("5", "1", "file3", "hello3", True)
        builder.change_parent("3", other="2")
        builder.change_parent("4", this="2")
        builder.change_parent("5", base="2")
        builder.merge()
        builder.cleanup()

        builder = MergeBuilder(getcwd())
        builder.add_dir("1", builder.tree_root, "dir1")
        builder.add_dir("2", builder.tree_root, "dir2")
        builder.add_dir("3", builder.tree_root, "dir3")
        builder.add_file("4", "1", "file1", "hello1", False)
        builder.change_parent("4", other="2", this="3")
        conflicts = builder.merge()
        path2 = pathjoin("dir2", "file1")
        path3 = pathjoin("dir3", "file1")
        self.assertEqual(conflicts, [PathConflict(path3, path2, "4")])
        builder.cleanup()
    def test_cd_dir_and_back_home(self):
        self.assertEqual(self.test_dir, osutils.getcwd())
        self.run_script("""
$ mkdir dir
$ cd dir
""")
        self.assertEqual(osutils.pathjoin(self.test_dir, 'dir'),
                          osutils.getcwd())

        self.run_script('$ cd')
        self.assertEqual(self.test_dir, osutils.getcwd())
Beispiel #8
0
    def test_cd_dir_and_back_home(self):
        self.assertEquals(self.test_dir, osutils.getcwd())
        self.run_script("""
$ mkdir dir
$ cd dir
""")
        self.assertEquals(osutils.pathjoin(self.test_dir, 'dir'),
                          osutils.getcwd())

        self.run_script('$ cd')
        self.assertEquals(self.test_dir, osutils.getcwd())
Beispiel #9
0
 def contents_test_success(self, merge_factory):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "text1", True)
     builder.change_contents("1", other="text4")
     builder.add_file("2", builder.tree_root, "name3", "text2", False)
     builder.change_contents("2", base="text5")
     builder.add_file("3", builder.tree_root, "name5", "text3", True)
     builder.add_file("4", builder.tree_root, "name6", "text4", True)
     builder.remove_file("4", base=True)
     builder.add_file("5", builder.tree_root, "name7", "a\nb\nc\nd\ne\nf\n",
                      True)
     builder.change_contents("5",
                             other="a\nz\nc\nd\ne\nf\n",
                             this="a\nb\nc\nd\ne\nz\n")
     conflicts = builder.merge(merge_factory)
     try:
         self.assertEqual([], conflicts)
         self.assertEqual("text4", builder.this.get_file("1").read())
         self.assertEqual("text2", builder.this.get_file("2").read())
         self.assertEqual("a\nz\nc\nd\ne\nz\n",
                          builder.this.get_file("5").read())
         self.assertTrue(builder.this.is_executable("1"))
         self.assertFalse(builder.this.is_executable("2"))
         self.assertTrue(builder.this.is_executable("3"))
     except:
         builder.unlock()
         raise
     return builder
Beispiel #10
0
    def open_containing(location=None,
                        require_tree=False,
                        ui_mode=False,
                        _critical_dialog=QtGui.QMessageBox.critical):
        """Open the branch and tree at location (or in current directory).

        @return: initialized TreeBranch if opened successfully,
            None if branch or tree not found.

        @param location: URL or local path, if None then current working
            directory will be used.
        @param require_tree: if True then NoWorkingTree error will be
            raised if there is no working tree found. Otherwise it's
            acceptable to open only branch object.
        @param ui_mode: if True show errors in the GUI error dialogs;
            otherwise propagate the error up the stack.
        @param _critical_dialog: hook for testing.
        """
        if location is None:
            location = osutils.getcwd()
        try:
            (tree, branch,
             relpath) = bzrdir.BzrDir.open_containing_tree_or_branch(location)

            if require_tree and tree is None:
                raise errors.NoWorkingTree(location)
        except (errors.NotBranchError, errors.NoWorkingTree), e:
            if not ui_mode:
                raise
            TreeBranch._report_error(location, e, _critical_dialog)
            return None
Beispiel #11
0
  def run(self, file_list=None, revision=None, using=None,
                         diff_options=None, prefix=None):
    """
    Run the external diff tool.
    """

    # Get an instance of this tool:
    assert using is not None
    tool = find_diff_tool(using)
    tool.add_options(diff_options)
    
    # Default to current working directory:
    if (not file_list or len(file_list) == 0):
      file_list = [ osutils.getcwd() ]

    # Pick the right comparison to perform:
    if revision:
      if (len(revision) == 1) or (revision[1].spec is None):
        result = compare_using(tool, file_list, revision[0])
      elif len(revision) == 2:
        result = compare_using(tool, file_list, revision[0], revision[1])
      else:
        raise errors.BzrCommandError(
            '--revision takes exactly one or two revision specifiers')
    else:
      # Just diff against the current base tree:
      result = compare_using(tool, file_list)

    return result
Beispiel #12
0
    def test_pull(self):
        # Make sure we can pull from paths that can't be encoded
        dirname1 = self.info['directory']
        dirname2 = self.info['directory'] + '2'
        url1 = urlutils.local_path_to_url(dirname1)
        url2 = urlutils.local_path_to_url(dirname2)
        out_bzrdir = self.wt.bzrdir.sprout(url1)
        out_bzrdir.sprout(url2)

        self.build_tree_contents(
            [(osutils.pathjoin(dirname1, "a"), 'different text\n')])
        self.wt.commit('mod a')

        txt = self.run_bzr_decode('pull', working_dir=dirname2)

        expected = osutils.pathjoin(osutils.getcwd(), dirname1)
        self.assertEqual(u'Using saved parent location: %s/\n'
                'No revisions or tags to pull.\n' % (expected,), txt)

        self.build_tree_contents(
            [(osutils.pathjoin(dirname1, 'a'), 'and yet more\n')])
        self.wt.commit(u'modifying a by ' + self.info['committer'])

        # We should be able to pull, even if our encoding is bad
        self.run_bzr_decode('pull --verbose', encoding='ascii',
                            working_dir=dirname2)
Beispiel #13
0
    def test_pull(self):
        # Make sure we can pull from paths that can't be encoded
        dirname1 = self.info['directory']
        dirname2 = self.info['directory'] + '2'
        url1 = urlutils.local_path_to_url(dirname1)
        url2 = urlutils.local_path_to_url(dirname2)
        out_bzrdir = self.wt.bzrdir.sprout(url1)
        out_bzrdir.sprout(url2)

        self.build_tree_contents(
            [(osutils.pathjoin(dirname1, "a"), 'different text\n')])
        self.wt.commit('mod a')

        txt = self.run_bzr_decode('pull', working_dir=dirname2)

        expected = osutils.pathjoin(osutils.getcwd(), dirname1)
        self.assertEqual(u'Using saved location: %s/\n'
                'No revisions to pull.\n' % (expected,), txt)

        self.build_tree_contents(
            [(osutils.pathjoin(dirname1, 'a'), 'and yet more\n')])
        self.wt.commit(u'modifying a by ' + self.info['committer'])

        # We should be able to pull, even if our encoding is bad
        self.run_bzr_decode('pull --verbose', encoding='ascii',
                            working_dir=dirname2)
Beispiel #14
0
def _show_location_info(locs, outfile):
    """Show known locations for working, branch and repository."""
    outfile.write('Location:\n')
    path_list = LocationList(osutils.getcwd())
    for name, loc in locs:
        path_list.add_url(name, loc)
    outfile.writelines(path_list.get_lines())
Beispiel #15
0
 def test_diff_outside_tree(self):
     tmp_dir = tempfile.mkdtemp()
     self.addCleanup(lambda: osutils.rmtree(tmp_dir))
     os.chdir(tmp_dir)
     self.run_bzr('init branch1')
     self.run_bzr(['commit', '-m', 'nothing',
                            '--unchanged', 'branch1'])
     self.run_bzr(['commit', '-m', 'nothing',
                            '--unchanged', 'branch1'])
     this_dir = osutils.getcwd()
     branch2 = "%s/branch2" % (this_dir,)
     # -r X..Y
     out, err = self.run_bzr('diff -r revno:2:branch2..revno:1', retcode=3)
     self.assertEquals('', out)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (branch2,),
                      err)
     # -r X
     out, err = self.run_bzr('diff -r revno:2:branch2', retcode=3)
     self.assertEquals('', out)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (branch2,),
                      err)
     # -r X..
     out, err = self.run_bzr('diff -r revno:2:branch2..', retcode=3)
     self.assertEquals('', out)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (branch2,),
                      err)
     # no -r at all.
     out, err = self.run_bzr('diff', retcode=3)
     self.assertEquals('', out)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n' % (this_dir,),
                      err)
Beispiel #16
0
 def test_unbind_format_6_bzrdir(self):
     # bind on a format 6 bzrdir should error
     out,err = self.run_bzr('unbind', retcode=3)
     self.assertEqual('', out)
     cwd = urlutils.local_path_to_url(getcwd())
     self.assertEqual('bzr: ERROR: To use this feature you must '
                      'upgrade your branch at %s/.\n' % cwd, err)
Beispiel #17
0
def _show_location_info(locs, outfile):
    """Show known locations for working, branch and repository."""
    outfile.write('Location:\n')
    path_list = LocationList(osutils.getcwd())
    for name, loc in locs:
        path_list.add_url(name, loc)
    outfile.writelines(path_list.get_lines())
Beispiel #18
0
 def contents_test_success(self, merge_factory):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "text1", True)
     builder.change_contents("1", other="text4")
     builder.add_file("2", builder.tree_root, "name3", "text2", False)
     builder.change_contents("2", base="text5")
     builder.add_file("3", builder.tree_root, "name5", "text3", True)
     builder.add_file("4", builder.tree_root, "name6", "text4", True)
     builder.remove_file("4", base=True)
     builder.add_file("5", builder.tree_root, "name7", "a\nb\nc\nd\ne\nf\n",
                      True)
     builder.change_contents("5", other="a\nz\nc\nd\ne\nf\n", 
                                  this="a\nb\nc\nd\ne\nz\n")
     conflicts = builder.merge(merge_factory)
     try:
         self.assertEqual([], conflicts)
         self.assertEqual("text4", builder.this.get_file("1").read())
         self.assertEqual("text2", builder.this.get_file("2").read())
         self.assertEqual("a\nz\nc\nd\ne\nz\n", 
                          builder.this.get_file("5").read())
         self.assertTrue(builder.this.is_executable("1"))
         self.assertFalse(builder.this.is_executable("2"))
         self.assertTrue(builder.this.is_executable("3"))
     except:
         builder.unlock()
         raise
     return builder
Beispiel #19
0
 def test_merge_one_renamed(self):
     builder = MergeBuilder(getcwd())
     builder.add_file('1', builder.tree_root, 'name1', 'text1a', False)
     builder.change_name('1', this='name2')
     builder.change_contents('1', other='text2')
     builder.merge(interesting_files=['name2'])
     self.assertEqual('text2', builder.this.get_file('1').read())
     builder.cleanup()
Beispiel #20
0
 def test_merge_one_renamed(self):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "text1a", False)
     builder.change_name("1", this="name2")
     builder.change_contents("1", other="text2")
     builder.merge(interesting_files=["name2"])
     self.assertEqual("text2", builder.this.get_file("1").read())
     builder.cleanup()
Beispiel #21
0
 def test_symlink_conflicts(self):
     if sys.platform != "win32":
         builder = MergeBuilder(getcwd())
         builder.add_symlink("2", builder.tree_root, "name2", "target1")
         builder.change_target("2", other="target4", base="text3")
         conflicts = builder.merge()
         self.assertEqual(conflicts, [ContentsConflict("name2", file_id="2")])
         builder.cleanup()
Beispiel #22
0
 def test_change_name(self):
     """Test renames"""
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "hello1", True)
     builder.change_name("1", other="name2")
     builder.add_file("2", builder.tree_root, "name3", "hello2", True)
     builder.change_name("2", base="name4")
     builder.add_file("3", builder.tree_root, "name5", "hello3", True)
     builder.change_name("3", this="name6")
     builder.merge()
     builder.cleanup()
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "hello1", False)
     builder.change_name("1", other="name2", this="name3")
     conflicts = builder.merge()
     self.assertEqual(conflicts, [PathConflict('name3', 'name2', '1')])
     builder.cleanup()
Beispiel #23
0
 def test_cwd_log(self):
     tmp_dir = tempfile.mkdtemp()
     self.addCleanup(lambda: osutils.rmtree(tmp_dir))
     os.chdir(tmp_dir)
     out, err = self.run_bzr('log', retcode=3)
     self.assertEqual(u'bzr: ERROR: Not a branch: "%s/".\n'
                      % (osutils.getcwd(),),
                      err)
Beispiel #24
0
 def test_new_suffix(self):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "text1", True)
     builder.change_contents("1", other="text3")
     builder.add_file("2", builder.tree_root, "name1.new", "text2", True)
     builder.merge()
     os.lstat(builder.this.id2abspath("2"))
     builder.cleanup()
Beispiel #25
0
 def test_merge_one_renamed(self):
     builder = MergeBuilder(getcwd())
     builder.add_file('1', builder.tree_root, 'name1', 'text1a', False)
     builder.change_name('1', this='name2')
     builder.change_contents('1', other='text2')
     builder.merge(interesting_files=['name2'])
     self.assertEqual('text2', builder.this.get_file('1').read())
     builder.cleanup()
Beispiel #26
0
 def test_spurious_conflict(self):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "text1", False)
     builder.remove_file("1", other=True)
     builder.add_file("2", builder.tree_root, "name1", "text1", False, this=False, base=False)
     conflicts = builder.merge()
     self.assertEqual(conflicts, [])
     builder.cleanup()
Beispiel #27
0
 def test_new_suffix(self):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "text1", True)
     builder.change_contents("1", other="text3")
     builder.add_file("2", builder.tree_root, "name1.new", "text2", True)
     builder.merge()
     os.lstat(builder.this.id2abspath("2"))
     builder.cleanup()
Beispiel #28
0
 def test_change_name(self):
     """Test renames"""
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "hello1", True)
     builder.change_name("1", other="name2")
     builder.add_file("2", builder.tree_root, "name3", "hello2", True)
     builder.change_name("2", base="name4")
     builder.add_file("3", builder.tree_root, "name5", "hello3", True)
     builder.change_name("3", this="name6")
     builder.merge()
     builder.cleanup()
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "hello1", False)
     builder.change_name("1", other="name2", this="name3")
     conflicts = builder.merge()
     self.assertEqual(conflicts, [PathConflict("name3", "name2", "1")])
     builder.cleanup()
Beispiel #29
0
    def test_start_and_stop_working_dir(self):
        cwd = osutils.getcwd()

        self.make_branch_and_tree('one')

        process = self.start_bzr_subprocess(['root'], working_dir='one')
        result = self.finish_bzr_subprocess(process, universal_newlines=True)
        self.assertEndsWith(result[0], 'one\n')
        self.assertEqual('', result[1])
Beispiel #30
0
 def test_bind_format_6_bzrdir(self):
     # bind on a format 6 bzrdir should error
     out,err = self.run_bzr('bind ../master', retcode=3)
     self.assertEqual('', out)
     # TODO: jam 20060427 Probably something like this really should
     #       print out the actual path, rather than the URL
     cwd = urlutils.local_path_to_url(getcwd())
     self.assertEqual('bzr: ERROR: To use this feature you must '
                      'upgrade your branch at %s/.\n' % cwd, err)
Beispiel #31
0
 def apply_redirected(self, stdin=None, stdout=None, stderr=None,
                      a_callable=None, *args, **kwargs):
     self.stdin = stdin
     self.factory_stdin = getattr(bzrlib.ui.ui_factory, "stdin", None)
     self.factory = bzrlib.ui.ui_factory
     self.working_dir = osutils.getcwd()
     stdout.write('foo\n')
     stderr.write('bar\n')
     return 0
Beispiel #32
0
    def test_start_and_stop_working_dir(self):
        cwd = osutils.getcwd()

        self.make_branch_and_tree('one')

        process = self.start_bzr_subprocess(['root'], working_dir='one')
        result = self.finish_bzr_subprocess(process, universal_newlines=True)
        self.assertEndsWith(result[0], 'one\n')
        self.assertEqual('', result[1])
Beispiel #33
0
 def test_symlink_conflicts(self):
     if sys.platform != "win32":
         builder = MergeBuilder(getcwd())
         builder.add_symlink("2", builder.tree_root, "name2", "target1")
         builder.change_target("2", other="target4", base="text3")
         conflicts = builder.merge()
         self.assertEqual(conflicts,
                          [ContentsConflict('name2', file_id='2')])
         builder.cleanup()
Beispiel #34
0
 def test_merge_one(self):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "hello1", True)
     builder.change_contents("1", other="text4")
     builder.add_file("2", builder.tree_root, "name2", "hello1", True)
     builder.change_contents("2", other="text4")
     builder.merge(interesting_ids=["1"])
     self.assertEqual(builder.this.get_file("1").read(), "text4")
     self.assertEqual(builder.this.get_file("2").read(), "hello1")
     builder.cleanup()
Beispiel #35
0
 def test_merge_one(self):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "hello1", True)
     builder.change_contents("1", other="text4")
     builder.add_file("2", builder.tree_root, "name2", "hello1", True)
     builder.change_contents("2", other="text4")
     builder.merge(interesting_ids=["1"])
     self.assertEqual(builder.this.get_file("1").read(), "text4")
     self.assertEqual(builder.this.get_file("2").read(), "hello1")
     builder.cleanup()
Beispiel #36
0
 def __init__(self, branch, revid, root=None):
     self.branch = branch
     self.revid = revid
     if root is not None:
         self.root = root
     else:
         self.root = local_path_from_url(branch.base)
     self.cwd = getcwd()
     self.config = []
     self.bound = True
     self.use_snapshot = command_kwargs and 'revision' in command_kwargs
Beispiel #37
0
def _gather_related_branches(branch):
    locs = LocationList(osutils.getcwd())
    locs.add_url('public branch', branch.get_public_branch())
    locs.add_url('push branch', branch.get_push_location())
    locs.add_url('parent branch', branch.get_parent())
    locs.add_url('submit branch', branch.get_submit_branch())
    try:
        locs.add_url('stacked on', branch.get_stacked_on_url())
    except (errors.UnstackableBranchFormat, errors.UnstackableRepositoryFormat,
        errors.NotStacked):
        pass
    return locs
Beispiel #38
0
def _gather_related_branches(branch):
    locs = LocationList(osutils.getcwd())
    locs.add_url('public branch', branch.get_public_branch())
    locs.add_url('push branch', branch.get_push_location())
    locs.add_url('parent branch', branch.get_parent())
    locs.add_url('submit branch', branch.get_submit_branch())
    try:
        locs.add_url('stacked on', branch.get_stacked_on_url())
    except (errors.UnstackableBranchFormat, errors.UnstackableRepositoryFormat,
            errors.NotStacked):
        pass
    return locs
Beispiel #39
0
 def test_commit_merge_reports_all_modified_files(self):
     # the commit command should show all the files that are shown by
     # bzr diff or bzr status when committing, even when they were not
     # changed by the user but rather through doing a merge.
     this_tree = self.make_branch_and_tree('this')
     # we need a bunch of files and dirs, to perform one action on each.
     self.build_tree([
         'this/dirtorename/', 'this/dirtoreparent/', 'this/dirtoleave/',
         'this/dirtoremove/', 'this/filetoreparent', 'this/filetorename',
         'this/filetomodify', 'this/filetoremove', 'this/filetoleave'
     ])
     this_tree.add([
         'dirtorename', 'dirtoreparent', 'dirtoleave', 'dirtoremove',
         'filetoreparent', 'filetorename', 'filetomodify', 'filetoremove',
         'filetoleave'
     ])
     this_tree.commit('create_files')
     other_dir = this_tree.bzrdir.sprout('other')
     other_tree = other_dir.open_workingtree()
     other_tree.lock_write()
     # perform the needed actions on the files and dirs.
     try:
         other_tree.rename_one('dirtorename', 'renameddir')
         other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
         other_tree.rename_one('filetorename', 'renamedfile')
         other_tree.rename_one('filetoreparent',
                               'renameddir/reparentedfile')
         other_tree.remove(['dirtoremove', 'filetoremove'])
         self.build_tree_contents([('other/newdir/', ),
                                   ('other/filetomodify', 'new content'),
                                   ('other/newfile', 'new file content')])
         other_tree.add('newfile')
         other_tree.add('newdir/')
         other_tree.commit('modify all sample files and dirs.')
     finally:
         other_tree.unlock()
     this_tree.merge_from_branch(other_tree.branch)
     os.chdir('this')
     out, err = self.run_bzr('commit -m added')
     self.assertEqual('', out)
     expected = '%s/' % (osutils.getcwd(), )
     self.assertEqualDiff(
         'Committing to: %s\n'
         'modified filetomodify\n'
         'added newdir\n'
         'added newfile\n'
         'renamed dirtorename => renameddir\n'
         'renamed filetorename => renamedfile\n'
         'renamed dirtoreparent => renameddir/reparenteddir\n'
         'renamed filetoreparent => renameddir/reparentedfile\n'
         'deleted dirtoremove\n'
         'deleted filetoremove\n'
         'Committed revision 2.\n' % (expected, ), err)
Beispiel #40
0
    def test_get_invalid_parent(self):
        b = self.make_branch('.')

        cwd = getcwd()
        n_dirs = len(cwd.split('/'))

        # Force the relative path to be something invalid
        # This should attempt to go outside the filesystem
        path = ('../'*(n_dirs+5)) + 'foo'
        b._set_parent_location(path)

        # With an invalid branch parent, just return None
        self.assertRaises(bzrlib.errors.InaccessibleParent, b.get_parent)
Beispiel #41
0
    def test_working_dir(self):
        self.build_tree(['one/', 'two/'])
        cwd = osutils.getcwd()

        # Default is to work in the current directory
        self.run_bzr(['foo', 'bar'])
        self.assertEqual(cwd, self.working_dir)

        self.run_bzr(['foo', 'bar'], working_dir=None)
        self.assertEqual(cwd, self.working_dir)

        # The function should be run in the alternative directory
        # but afterwards the current working dir shouldn't be changed
        self.run_bzr(['foo', 'bar'], working_dir='one')
        self.assertNotEqual(cwd, self.working_dir)
        self.assertEndsWith(self.working_dir, 'one')
        self.assertEqual(cwd, osutils.getcwd())

        self.run_bzr(['foo', 'bar'], working_dir='two')
        self.assertNotEqual(cwd, self.working_dir)
        self.assertEndsWith(self.working_dir, 'two')
        self.assertEqual(cwd, osutils.getcwd())
Beispiel #42
0
    def test_working_dir(self):
        self.build_tree(['one/', 'two/'])
        cwd = osutils.getcwd()

        # Default is to work in the current directory
        self.run_bzr(['foo', 'bar'])
        self.assertEqual(cwd, self.working_dir)

        self.run_bzr(['foo', 'bar'], working_dir=None)
        self.assertEqual(cwd, self.working_dir)

        # The function should be run in the alternative directory
        # but afterwards the current working dir shouldn't be changed
        self.run_bzr(['foo', 'bar'], working_dir='one')
        self.assertNotEqual(cwd, self.working_dir)
        self.assertEndsWith(self.working_dir, 'one')
        self.assertEqual(cwd, osutils.getcwd())

        self.run_bzr(['foo', 'bar'], working_dir='two')
        self.assertNotEqual(cwd, self.working_dir)
        self.assertEndsWith(self.working_dir, 'two')
        self.assertEqual(cwd, osutils.getcwd())
Beispiel #43
0
 def test_symlink_merge(self):
     if sys.platform != "win32":
         builder = MergeBuilder(getcwd())
         builder.add_symlink("1", builder.tree_root, "name1", "target1")
         builder.add_symlink("2", builder.tree_root, "name2", "target1")
         builder.add_symlink("3", builder.tree_root, "name3", "target1")
         builder.change_target("1", this="target2")
         builder.change_target("2", base="target2")
         builder.change_target("3", other="target2")
         builder.merge()
         self.assertEqual(builder.this.get_symlink_target("1"), "target2")
         self.assertEqual(builder.this.get_symlink_target("2"), "target1")
         self.assertEqual(builder.this.get_symlink_target("3"), "target2")
         builder.cleanup()
Beispiel #44
0
 def apply_redirected(self,
                      stdin=None,
                      stdout=None,
                      stderr=None,
                      a_callable=None,
                      *args,
                      **kwargs):
     self.stdin = stdin
     self.factory_stdin = getattr(bzrlib.ui.ui_factory, "stdin", None)
     self.factory = bzrlib.ui.ui_factory
     self.working_dir = osutils.getcwd()
     stdout.write('foo\n')
     stderr.write('bar\n')
     return 0
Beispiel #45
0
 def test_spurious_conflict(self):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "text1", False)
     builder.remove_file("1", other=True)
     builder.add_file("2",
                      builder.tree_root,
                      "name1",
                      "text1",
                      False,
                      this=False,
                      base=False)
     conflicts = builder.merge()
     self.assertEqual(conflicts, [])
     builder.cleanup()
Beispiel #46
0
 def test_symlink_merge(self):
     if sys.platform != "win32":
         builder = MergeBuilder(getcwd())
         builder.add_symlink("1", builder.tree_root, "name1", "target1")
         builder.add_symlink("2", builder.tree_root, "name2", "target1")
         builder.add_symlink("3", builder.tree_root, "name3", "target1")
         builder.change_target("1", this="target2")
         builder.change_target("2", base="target2")
         builder.change_target("3", other="target2")
         builder.merge()
         self.assertEqual(builder.this.get_symlink_target("1"), "target2")
         self.assertEqual(builder.this.get_symlink_target("2"), "target1")
         self.assertEqual(builder.this.get_symlink_target("3"), "target2")
         builder.cleanup()
Beispiel #47
0
    def start_bzr_subprocess(self, process_args, env_changes=None,
                             working_dir=None):
        """Start bzr in a subprocess for testing.

        Copied and modified from `bzrlib.tests.TestCase.start_bzr_subprocess`.
        This version removes some of the skipping stuff, some of the
        irrelevant comments (e.g. about win32) and uses Launchpad's own
        mechanisms for getting the path to 'bzr'.

        Comments starting with 'LAUNCHPAD' are comments about our
        modifications.
        """
        if env_changes is None:
            env_changes = {}
        env_changes['BZR_PLUGIN_PATH'] = get_BZR_PLUGIN_PATH_for_subprocess()
        old_env = {}

        def cleanup_environment():
            for env_var, value in env_changes.iteritems():
                old_env[env_var] = osutils.set_or_unset_env(env_var, value)

        def restore_environment():
            for env_var, value in old_env.iteritems():
                osutils.set_or_unset_env(env_var, value)

        cwd = None
        if working_dir is not None:
            cwd = osutils.getcwd()
            os.chdir(working_dir)

        # LAUNCHPAD: Because of buildout, we need to get a custom Python
        # binary, not sys.executable.
        python_path = self.get_python_path()
        # LAUNCHPAD: We can't use self.get_bzr_path(), since it'll find
        # lib/bzrlib, rather than the path to sourcecode/bzr/bzr.
        bzr_path = get_bzr_path()
        try:
            cleanup_environment()
            command = [python_path, bzr_path]
            command.extend(process_args)
            process = self._popen(
                command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
        finally:
            restore_environment()
            if cwd is not None:
                os.chdir(cwd)

        return process
Beispiel #48
0
 def test_verbose_commit_moved(self):
     # Verbose commit of file moved to new directory should say so
     wt = self.prepare_simple_history()
     os.mkdir('subdir')
     wt.add(['subdir'])
     wt.rename_one('hello.txt', 'subdir/hello.txt')
     out, err = self.run_bzr('commit -m renamed')
     self.assertEqual('', out)
     self.assertEqual(set([
         'Committing to: %s/' % osutils.getcwd(),
         'added subdir',
         'renamed hello.txt => subdir/hello.txt',
         'Committed revision 2.',
         '',
         ]), set(err.split('\n')))
Beispiel #49
0
    def test_get_invalid_parent(self):
        b = self.make_branch('.')

        cwd = getcwd()
        n_dirs = len(cwd.split('/'))

        # Force the relative path to be something invalid
        # This should attempt to go outside the filesystem
        path = ('../'*(n_dirs+5)) + 'foo'
        b.lock_write()
        b._set_parent_location(path)
        b.unlock()

        # With an invalid branch parent, just return None
        self.assertRaises(bzrlib.errors.InaccessibleParent, b.get_parent)
Beispiel #50
0
 def test_verbose_commit_moved(self):
     # Verbose commit of file moved to new directory should say so
     wt = self.prepare_simple_history()
     os.mkdir('subdir')
     wt.add(['subdir'])
     wt.rename_one('hello.txt', 'subdir/hello.txt')
     out, err = self.run_bzr('commit -m renamed')
     self.assertEqual('', out)
     self.assertEqual(
         set([
             'Committing to: %s/' % osutils.getcwd(),
             'added subdir',
             'renamed hello.txt => subdir/hello.txt',
             'Committed revision 2.',
             '',
         ]), set(err.split('\n')))
Beispiel #51
0
 def test_perms_merge(self):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "text1", True)
     builder.change_perms("1", other=False)
     builder.add_file("2", builder.tree_root, "name2", "text2", True)
     builder.change_perms("2", base=False)
     builder.add_file("3", builder.tree_root, "name3", "text3", True)
     builder.change_perms("3", this=False)
     builder.add_file("4", builder.tree_root, "name4", "text4", False)
     builder.change_perms("4", this=True)
     builder.remove_file("4", base=True)
     builder.merge()
     self.assertIs(builder.this.is_executable("1"), False)
     self.assertIs(builder.this.is_executable("2"), True)
     self.assertIs(builder.this.is_executable("3"), False)
     builder.cleanup()
Beispiel #52
0
 def contents_test_conflicts(self, merge_factory):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "text1", True)
     builder.change_contents("1", other="text4", this="text3")
     builder.add_file("2", builder.tree_root, "name2", "text1", True)
     builder.change_contents("2", other="\x00", this="text3")
     builder.add_file("3", builder.tree_root, "name3", "text5", False)
     builder.change_perms("3", this=True)
     builder.change_contents('3', this='moretext')
     builder.remove_file('3', other=True)
     conflicts = builder.merge(merge_factory)
     self.assertEqual(conflicts, [TextConflict('name1', file_id='1'),
                                  ContentsConflict('name2', file_id='2'),
                                  ContentsConflict('name3', file_id='3')])
     self.assertEqual(builder.this.get_file('2').read(), '\x00')
     builder.cleanup()
Beispiel #53
0
 def test_perms_merge(self):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "text1", True)
     builder.change_perms("1", other=False)
     builder.add_file("2", builder.tree_root, "name2", "text2", True)
     builder.change_perms("2", base=False)
     builder.add_file("3", builder.tree_root, "name3", "text3", True)
     builder.change_perms("3", this=False)
     builder.add_file('4', builder.tree_root, 'name4', 'text4', False)
     builder.change_perms('4', this=True)
     builder.remove_file('4', base=True)
     builder.merge()
     self.assertIs(builder.this.is_executable("1"), False)
     self.assertIs(builder.this.is_executable("2"), True)
     self.assertIs(builder.this.is_executable("3"), False)
     builder.cleanup()
Beispiel #54
0
 def contents_test_conflicts(self, merge_factory):
     builder = MergeBuilder(getcwd())
     builder.add_file("1", builder.tree_root, "name1", "text1", True)
     builder.change_contents("1", other="text4", this="text3")
     builder.add_file("2", builder.tree_root, "name2", "text1", True)
     builder.change_contents("2", other="\x00", this="text3")
     builder.add_file("3", builder.tree_root, "name3", "text5", False)
     builder.change_perms("3", this=True)
     builder.change_contents('3', this='moretext')
     builder.remove_file('3', other=True)
     conflicts = builder.merge(merge_factory)
     self.assertEqual(conflicts, [
         TextConflict('name1', file_id='1'),
         ContentsConflict('name2', file_id='2'),
         ContentsConflict('name3', file_id='3')
     ])
     self.assertEqual(builder.this.get_file('2').read(), '\x00')
     builder.cleanup()