#!/bin/bash
#****************************************************************************
#* git wrapper
#*
#* This wrapper is used when running 'pip install -r <requirements>' to
#* avoid stomping on editable Git projects already checked out. Editable
#* installs are checked out, then pip runs a 'git reset --hard'. This wrapper
#* ignores the reset to preserve any changes in the area
#****************************************************************************

# Find second occurence of 'git'
first=""
second=""
for elem in `echo $PATH | sed -e 's/:/ /g'`; do
  if test -f ${elem}/git; then
    if test "x$first" != "x"; then
      second=$elem
      break
    else
      first=$elem
    fi
  fi
done

if test "x$1" = "xreset"; then
  echo "IVPM: Skipping git reset"
  exit 0
else
  exec $second/git ${@:1}
fi

