#!/bin/bash

export LC_ALL=C

for d in "${@-.}"; do
(
  cd "$d" &&
  if git branch >&/dev/null; then
    exec 3< <(find . -type f | cut -c3- | grep -v '^\.git/' | sort)
    git ls-tree -r HEAD | cut -f2 -d'	' | sort |
      while read -r f; do
        while { read -r g; } <&3 && [ "$g" '<' "$f" ]; do echo "$g"; done
      done
    while { read -r g; } <&3; do echo "$g"; done
    exec 3<&-
  else
    echo "Ignored directory $PWD"
  fi
)
done
