#!/bin/sh -e
#
# git-diff-search - search for a string in the diff of a branch

if [ "$#" -ne 2 ]; then
  printf '%s\n' 'Usage: git diff-search [branch] [string]' '' \
    'searches for a string in the diff of a branch'
  exit 1
fi

branch="$1"
target="$2"

for file in $(git diff --name-only "${branch}"); do
  if git diff "${branch}" -- "${file}" | rg --quiet "${target}"; then
    printf ' %s\n' "${file}"
    git diff "${branch}" -- "${file}" | rg "${target}"
  fi
done
