#!/bin/sh -e
# Stage moved files fitting the already staged ones
set -o pipefail
git diff --name-only --cached >/tmp/staged
root=$(git rev-parse --show-toplevel)
git add "$root"
git status --porcelain --find-renames=.2 |
  grep -vf /tmp/staged | cut -c4- | sed 's/ -> /\n/' |
  xargs git -C "$root" restore --staged
test "$1" = "-q" || git status --short --find-renames=.2
