#!/bin/bash
set -e

function run_quiet()
{
  /system/internal/setuser app "$@"
}

function run()
{
  echo " --> $@"
  /system/internal/setuser app "$@"
}

/system/internal/inituidgid

cd /git
if [[ -e .git ]]; then
  run_quiet rm -rf *
  run git fetch
else
  run git clone "$GIT_URL" .
fi
if [[ -e .gitmodules ]]; then
  run git submodule update --init --recursive
fi
run git reset --hard "$GIT_REF"
