def deep_trees_rmtree(base):
    """Helper function for deep trees test cases.  Delete top-level dirs
     with rmtree instead of svn del."""
    j = os.path.join
    F = j(base, 'F', 'alpha')
    D = j(base, 'D', 'D1')
    DF = j(base, 'DF', 'D1')
    DD = j(base, 'DD', 'D1')
    DDF = j(base, 'DDF', 'D1')
    DDD = j(base, 'DDD', 'D1')
    os.unlink(F)
    main.safe_rmtree(D)
    main.safe_rmtree(DF)
    main.safe_rmtree(DD)
    main.safe_rmtree(DDF)
    main.safe_rmtree(DDD)
Ejemplo n.º 2
0
def deep_trees_rmtree(base):
  """Helper function for deep trees test cases.  Delete top-level dirs
     with rmtree instead of svn del."""
  j = os.path.join
  F   = j(base, 'F', 'alpha')
  D   = j(base, 'D', 'D1')
  DF  = j(base, 'DF', 'D1')
  DD  = j(base, 'DD', 'D1')
  DDF = j(base, 'DDF', 'D1')
  DDD = j(base, 'DDD', 'D1')
  os.unlink(F)
  main.safe_rmtree(D)
  main.safe_rmtree(DF)
  main.safe_rmtree(DD)
  main.safe_rmtree(DDF)
  main.safe_rmtree(DDD)
Ejemplo n.º 3
0
def ensure_tree_conflict(sbox, operation,
                         incoming_scenarios, localmod_scenarios,
                         commit_local_mods):
  sbox.build()
  wc_dir = sbox.wc_dir

  def url_of(repo_relative_path):
    return sbox.repo_url + '/' + repo_relative_path

  verbose_print("")
  verbose_print("=== Starting a set of '" + operation + "' tests.")

  # Path to source branch, relative to wc_dir.
  # Source is where the "incoming" mods are made.
  source_br = "branch1"

  verbose_print("--- Creating changes in repos")
  source_wc_dir = os.path.join(wc_dir, source_br)
  source_left_rev, source_right_rev = set_up_repos(wc_dir, source_wc_dir,
                                                   incoming_scenarios)
  head_rev = source_right_rev  ### assumption

  # Local mods are the outer loop because cleaning up the WC is slow
  # ('svn revert' isn't sufficient because it leaves unversioned files)
  for _loc_init_mods, loc_action in localmod_scenarios:
    # Determine the branch (directory) in which local mods will be made.
    if operation == 'update':
      # Path to target branch (where conflicts are raised), relative to wc_dir.
      target_br = source_br
      target_start_rev = source_left_rev
    else:  # switch/merge
      # Make, and work in, a "branch2" that is a copy of "branch1".
      target_br = "branch2"
      run_and_verify_svn(None, AnyOutput, [],
                         'copy', '-r', str(source_left_rev), url_of(source_br),
                         url_of(target_br),
                         '-m', 'Create target branch.')
      head_rev += 1
      target_start_rev = head_rev

    main.run_svn(None, 'checkout', '-r', str(target_start_rev), sbox.repo_url,
                 wc_dir)

    saved_cwd = os.getcwd()
    os.chdir(wc_dir)

    for _inc_init_mods, inc_action in incoming_scenarios:
      scen_name = "_".join(inc_action)
      source_url = url_of(source_br + '/' + scen_name)
      target_path = os.path.join(target_br, scen_name)

      verbose_print("=== " + str(inc_action) + " onto " + str(loc_action))

      verbose_print("--- Making local mods")
      for modaction in loc_action:
        modify(modaction, localmod_paths(".", target_path))
      if commit_local_mods:
        run_and_verify_svn(None, AnyOutput, [],
                           'commit', target_path,
                           '-m', 'Mods in target branch.')
        head_rev += 1

      # What do we want to test for? (This selection could in future be
      # passed in to this function as a parameter.)
      test_what = [
        'commit-ood',
        'action',  # required for any of the following ones to work
        'notify',
        'commit-c',
        'status-c',
        'resolve',  # required for any of the following ones to work
        'status-nc',
        #'commit-ok',
        ]

      if 'commit-ood' in test_what:
        # For update, verify the pre-condition that WC is out of date.
        # For switch/merge, there is no such precondition.
        if operation == 'update':
          verbose_print("--- Trying to commit (expecting 'out-of-date' error)")
          run_and_verify_commit(".", None, None, "Commit failed",
                                target_path)

      if modaction.startswith('f'):
        victim = os.path.join(target_path, 'F')
      else:
        victim = os.path.join(target_path, 'D')

      # Perform the operation that tries to apply incoming changes to the WC.
      # The command is expected to do something (and give some output),
      # and it should raise a conflict but not an error.
      if 'action' in test_what:
        # Determine what notification to expect
        if 'notify' in test_what:
          expected_stdout = svntest.verify.ExpectedOutput("   C " + victim
                                                          + "\n",
                                                          match_all=False)
        else:
          expected_stdout = svntest.verify.AnyOutput
        # Do the main action
        if operation == 'update':
          verbose_print("--- Updating")
          run_and_verify_svn(None, expected_stdout, [],
                             'update', target_path)
        elif operation == 'switch':
          verbose_print("--- Switching")
          run_and_verify_svn(None, expected_stdout, [],
                             'switch', source_url, target_path)
        elif operation == 'merge':
          verbose_print("--- Merging")
          run_and_verify_svn(None, expected_stdout, [],
                             'merge', '--ignore-ancestry',
                             '-r', str(source_left_rev) + ':' + str(source_right_rev),
                             source_url, target_path)
        else:
          raise Exception("unknown operation: '" + operation + "'")

      if 'commit-c' in test_what:
        verbose_print("--- Trying to commit (expecting 'conflict' error)")
        ### run_and_verify_commit() requires an "output_tree" argument, but
        # here we get away with passing None because we know an implementation
        # detail: namely that it's not going to look at that argument if it
        # gets the stderr that we're expecting.
        run_and_verify_commit(".", None, None, ".*conflict.*", victim)

      if 'status-c' in test_what:
        verbose_print("--- Checking that 'status' reports the conflict")
        expected_stdout = svntest.verify.RegexOutput("^......C.* " +
                                                     re.escape(victim) + "$",
                                                     match_all=False)
        run_and_verify_svn(None, expected_stdout, [],
                           'status', victim)

      if 'resolve' in test_what:
        verbose_print("--- Resolving the conflict")
        # Make sure resolving the parent does nothing.
        run_and_verify_resolved([], os.path.dirname(victim))
        # The real resolved call.
        run_and_verify_resolved([victim])

      if 'status-nc' in test_what:
        verbose_print("--- Checking that 'status' does not report a conflict")
        exitcode, stdout, stderr = run_and_verify_svn(None, None, [],
                                                  'status', victim)
        for line in stdout:
          if line[6] == 'C': # and line.endswith(victim + '\n'):
            raise svntest.Failure("unexpected status C") # on path '" + victim + "'")

      if 'commit-ok' in test_what:
        verbose_print("--- Committing (should now succeed)")
        run_and_verify_svn(None, None, [],
                           'commit', '-m', '', target_path)
        target_start_rev += 1

      verbose_print("")

    os.chdir(saved_cwd)

    # Clean up the target branch and WC
    main.run_svn(None, 'revert', '-R', wc_dir)
    main.safe_rmtree(wc_dir)
    if operation != 'update':
      run_and_verify_svn(None, AnyOutput, [],
                         'delete', url_of(target_br),
                         '-m', 'Delete target branch.')
      head_rev += 1
def ensure_tree_conflict(sbox, operation, incoming_scenarios, localmod_scenarios, commit_local_mods):
    sbox.build()
    wc_dir = sbox.wc_dir

    def url_of(repo_relative_path):
        return sbox.repo_url + "/" + repo_relative_path

    verbose_print("")
    verbose_print("=== Starting a set of '" + operation + "' tests.")

    # Path to source branch, relative to wc_dir.
    # Source is where the "incoming" mods are made.
    source_br = "branch1"

    verbose_print("--- Creating changes in repos")
    source_wc_dir = os.path.join(wc_dir, source_br)
    source_left_rev, source_right_rev = set_up_repos(wc_dir, source_wc_dir, incoming_scenarios)
    head_rev = source_right_rev  ### assumption

    # Local mods are the outer loop because cleaning up the WC is slow
    # ('svn revert' isn't sufficient because it leaves unversioned files)
    for _loc_init_mods, loc_action in localmod_scenarios:
        # Determine the branch (directory) in which local mods will be made.
        if operation == "update":
            # Path to target branch (where conflicts are raised), relative to wc_dir.
            target_br = source_br
            target_start_rev = source_left_rev
        else:  # switch/merge
            # Make, and work in, a "branch2" that is a copy of "branch1".
            target_br = "branch2"
            run_and_verify_svn(
                None,
                AnyOutput,
                [],
                "copy",
                "-r",
                str(source_left_rev),
                url_of(source_br),
                url_of(target_br),
                "-m",
                "Create target branch.",
            )
            head_rev += 1
            target_start_rev = head_rev

        main.run_svn(None, "checkout", "-r", str(target_start_rev), sbox.repo_url, wc_dir)

        saved_cwd = os.getcwd()
        os.chdir(wc_dir)

        for _inc_init_mods, inc_action in incoming_scenarios:
            scen_name = "_".join(inc_action)
            source_url = url_of(source_br + "/" + scen_name)
            target_path = os.path.join(target_br, scen_name)

            verbose_print("=== " + str(inc_action) + " onto " + str(loc_action))

            verbose_print("--- Making local mods")
            for modaction in loc_action:
                modify(modaction, localmod_paths(".", target_path))
            if commit_local_mods:
                run_and_verify_svn(None, AnyOutput, [], "commit", target_path, "-m", "Mods in target branch.")
                head_rev += 1

            # What do we want to test for? (This selection could in future be
            # passed in to this function as a parameter.)
            test_what = [
                "commit-ood",
                "action",  # required for any of the following ones to work
                "notify",
                "commit-c",
                "status-c",
                "resolve",  # required for any of the following ones to work
                "status-nc",
                #'commit-ok',
            ]

            if "commit-ood" in test_what:
                # For update, verify the pre-condition that WC is out of date.
                # For switch/merge, there is no such precondition.
                if operation == "update":
                    verbose_print("--- Trying to commit (expecting 'out-of-date' error)")
                    run_and_verify_commit(".", None, None, "Commit failed", target_path)

            if modaction.startswith("f"):
                victim = os.path.join(target_path, "F")
            else:
                victim = os.path.join(target_path, "D")

            # Perform the operation that tries to apply incoming changes to the WC.
            # The command is expected to do something (and give some output),
            # and it should raise a conflict but not an error.
            if "action" in test_what:
                # Determine what notification to expect
                if "notify" in test_what:
                    expected_stdout = svntest.verify.ExpectedOutput("   C " + victim + "\n", match_all=False)
                else:
                    expected_stdout = svntest.verify.AnyOutput
                # Do the main action
                if operation == "update":
                    verbose_print("--- Updating")
                    run_and_verify_svn(None, expected_stdout, [], "update", target_path)
                elif operation == "switch":
                    verbose_print("--- Switching")
                    run_and_verify_svn(None, expected_stdout, [], "switch", source_url, target_path)
                elif operation == "merge":
                    verbose_print("--- Merging")
                    run_and_verify_svn(
                        None,
                        expected_stdout,
                        [],
                        "merge",
                        "--ignore-ancestry",
                        "-r",
                        str(source_left_rev) + ":" + str(source_right_rev),
                        source_url,
                        target_path,
                    )
                else:
                    raise Exception("unknown operation: '" + operation + "'")

            if "commit-c" in test_what:
                verbose_print("--- Trying to commit (expecting 'conflict' error)")
                ### run_and_verify_commit() requires an "output_tree" argument, but
                # here we get away with passing None because we know an implementation
                # detail: namely that it's not going to look at that argument if it
                # gets the stderr that we're expecting.
                run_and_verify_commit(".", None, None, ".*conflict.*", victim)

            if "status-c" in test_what:
                verbose_print("--- Checking that 'status' reports the conflict")
                expected_stdout = svntest.verify.RegexOutput("^......C.* " + re.escape(victim) + "$", match_all=False)
                run_and_verify_svn(None, expected_stdout, [], "status", victim)

            if "resolve" in test_what:
                verbose_print("--- Resolving the conflict")
                # Make sure resolving the parent does nothing.
                run_and_verify_resolved([], os.path.dirname(victim))
                # The real resolved call.
                run_and_verify_resolved([victim])

            if "status-nc" in test_what:
                verbose_print("--- Checking that 'status' does not report a conflict")
                exitcode, stdout, stderr = run_and_verify_svn(None, None, [], "status", victim)
                for line in stdout:
                    if line[6] == "C":  # and line.endswith(victim + '\n'):
                        raise svntest.Failure("unexpected status C")  # on path '" + victim + "'")

            if "commit-ok" in test_what:
                verbose_print("--- Committing (should now succeed)")
                run_and_verify_svn(None, None, [], "commit", "-m", "", target_path)
                target_start_rev += 1

            verbose_print("")

        os.chdir(saved_cwd)

        # Clean up the target branch and WC
        main.run_svn(None, "revert", "-R", wc_dir)
        main.safe_rmtree(wc_dir)
        if operation != "update":
            run_and_verify_svn(None, AnyOutput, [], "delete", url_of(target_br), "-m", "Delete target branch.")
            head_rev += 1