#!/bin/bash

cd "$(mktemp -d ${TMPDIR:-/tmp}/git-XXXXXXX)"

git --version

set -eux

git init

touch p1 && git add p1 && git commit -m 1

# create problematic situation
rm p1 && mkdir p1 && touch p1/p2 && git add p1/p2

git commit -m 2 p1/p2 p1 \
&& { echo "must have crashed!"; exit 1; } \
|| { echo "that did not work when imho should have!"; }

git commit -m 2 p1/p2 \
&& echo "done -- committed just fine"

# but why it works if I do specify removed path to commit?
touch p2 p3 && git add p2 p3 && git commit -m 3 p2 p3

rm p2 p3
git add p2
git commit -m 'removed and even staged one of them' p2 p3

echo "and it worked just fine"

