#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
source "$PLUGIN_AVAILABLE_PATH/git/internal-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x

trigger-git-post-app-rename-setup() {
  declare desc="modifies git-hook"
  declare trigger="post-app-rename-setup"
  declare OLD_APP="$1" NEW_APP="$2"

  fn-plugin-property-clone "git" "$OLD_APP" "$NEW_APP"
  fn-plugin-property-destroy "git" "$OLD_APP"

  pushd "$DOKKU_ROOT/$OLD_APP/." >/dev/null
  find ./* \( -name ".cache" -o -name "cache" -o -name "VHOST" -o -name "URLS" \) -prune -o -print | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP"
  popd &>/dev/null || pushd "/tmp" >/dev/null

  fn-git-create-hook "$NEW_APP"
}

trigger-git-post-app-rename-setup "$@"
