From 2eec02452b1a9606405e373d00d5da10f1775be7 Mon Sep 17 00:00:00 2001 From: "kiloconnect[bot]" <240665456+kiloconnect[bot]@users.noreply.github.com> Date: Thu, 30 Apr 2026 10:08:23 +0000 Subject: [PATCH] chore(cli): add script to find merge conflict markers in a file Provides a small helper for upstream merge workflows so agents can be allowlisted to search for conflict markers without needing general shell access. Wraps the canonical ripgrep invocation with a POSIX grep fallback. --- script/upstream/find-conflict-markers.sh | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 script/upstream/find-conflict-markers.sh diff --git a/script/upstream/find-conflict-markers.sh b/script/upstream/find-conflict-markers.sh new file mode 100755 index 00000000000..69fa65bd79e --- /dev/null +++ b/script/upstream/find-conflict-markers.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# Find git merge conflict markers in a file. +# +# Prints the line number and the marker for each of: +# <<<<<<< (ours start) +# ||||||| (base / diff3 separator) +# ======= (separator) +# >>>>>>> (theirs end) +# +# Usage: +# script/upstream/find-conflict-markers.sh +set -euo pipefail + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " >&2 + exit 2 +fi + +file=$1 + +if [ ! -f "$file" ]; then + echo "error: not a file: $file" >&2 + exit 2 +fi + +# Match the four conflict marker line shapes. `=======` must be the whole line; +# the others may have trailing content (branch name, commit hash, etc.). +# +# Prefer ripgrep when available (matches the historical invocation), fall back +# to POSIX grep so the script works in minimal environments. +if command -v rg >/dev/null 2>&1; then + rg -n '^(<{7}|\|{7}|={7}$|>{7})' "$file" || { + status=$? + # rg exits 1 when no matches are found; treat that as success (clean file). + if [ "$status" -eq 1 ]; then + exit 0 + fi + exit "$status" + } +else + grep -nE '^(<{7}|\|{7}|={7}$|>{7})' "$file" || { + status=$? + if [ "$status" -eq 1 ]; then + exit 0 + fi + exit "$status" + } +fi