Repository: carbon-language/carbon-lang
File: testing/file_test/test_file.cpp (C++)

Code before:
// Processes conflict markers, including tracking of whether code is within a
// conflict marker. Returns true if the line is consumed.
static auto TryConsumeConflictMarker(bool running_autoupdate,
                                     llvm::StringRef line,
                                     llvm::StringRef line_trimmed,
                                     bool& inside_conflict_marker)
    -> ErrorOr<bool> {
  bool is_start = line.starts_with("<<<<<<<");
  bool is_end = line.starts_with(">>>>>>>");
  bool is_middle =
      // git internal conflict markers ("merge" and "diff3" style).
      line.starts_with("=======") ||
      line.starts_with("|||||||")
      // jj internal conflict markers ("snapshot" style).
      || line.starts_with("+++++++") || line.starts_with("-------");
  // jj internal conflict marker ("diff" style)
  bool is_jj_diff = line.starts_with("%%%%%%%");

  // When running the test, any conflict marker is an error.
  if (!running_autoupdate && (is_start || is_middle || is_end || is_jj_diff)) {
    return ErrorBuilder() << "Conflict marker found:\n" << line;
  }

  if (is_jj_diff && running_autoupdate) {
    return ErrorBuilder()
           << "Found jj \"diff\" style conflict marker."
              " Autoupdate only supports \"snapshot\" style conflict markers."
              " To switch, use `jj config set --repo ui.conflict-marker-style"
              " \"snapshot\"`, and then navigate to a different change and "
              "back.";
  }

  // Autoupdate tracks conflict markers for context, and will discard
  // conflicting lines when it can autoupdate them.
  if (inside_conflict_marker) {
    if (is_start) {
      return ErrorBuilder() << "Unexpected conflict marker inside conflict:\n"
                            << line;
    }
    if (is_middle) {
      return true;
    }
    if (is_end) {
      inside_conflict_marker = false;
      return true;
    }

    // Look for CHECK and TIP lines, which can be discarded.
    if (line_trimmed.starts_with("// CHECK:STDOUT:") ||
        line_trimmed.starts_with("// CHECK:STDERR:") ||
        line_trimmed.starts_with("// TIP:")) {

Review comment (suggestion):
Might be worth leaving a TODO? (I much prefer the diff style conflict markers, but definitely not trivial to add support for them.)

```suggestion
    // TODO: Add support for JJ's diff-style conflict markers.
    return ErrorBuilder()
```

Code after:
// Processes conflict markers, including tracking of whether code is within a
// conflict marker. Returns true if the line is consumed.
static auto TryConsumeConflictMarker(bool running_autoupdate,
                                     llvm::StringRef line,
                                     llvm::StringRef line_trimmed,
                                     bool& inside_conflict_marker)
    -> ErrorOr<bool> {
  bool is_start = line.starts_with("<<<<<<<");
  bool is_end = line.starts_with(">>>>>>>");
  bool is_middle =
      // git internal conflict markers ("merge" and "diff3" style).
      line.starts_with("=======") ||
      line.starts_with("|||||||")
      // jj internal conflict markers ("snapshot" style).
      || line.starts_with("+++++++") || line.starts_with("-------");
  // jj internal conflict marker ("diff" style)
  bool is_jj_diff = line.starts_with("%%%%%%%");

  // When running the test, any conflict marker is an error.
  if (!running_autoupdate && (is_start || is_middle || is_end || is_jj_diff)) {
    return ErrorBuilder() << "Conflict marker found:\n" << line;
  }

  if (is_jj_diff && running_autoupdate) {
    // TODO: Add support for JJ's diff-style conflict markers.
    return ErrorBuilder()
           << "Found jj \"diff\" style conflict marker."
              " Autoupdate only supports \"snapshot\" style conflict markers."
              " To switch, use `jj config set --repo ui.conflict-marker-style"
              " \"snapshot\"`, and then run `jj new` (or `jj edit`) again to "
              " materialize the new style. For more details, see: "
              "https://docs.jj-vcs.dev/latest/conflicts/";
  }

  // Autoupdate tracks conflict markers for context, and will discard
  // conflicting lines when it can autoupdate them.
  if (inside_conflict_marker) {
    if (is_start) {
      return ErrorBuilder() << "Unexpected conflict marker inside conflict:\n"
                            << line;
    }
    if (is_middle) {
      return true;
    }
    if (is_end) {
      inside_conflict_marker = false;
      return true;
    }

    // Look for CHECK and TIP lines, which can be discarded.
    if (line_trimmed.starts_with("// CHECK:STDOUT:") ||