#!/usr/bin/env bash
set -e

if [ -z "$RBENV_GEMSET_FILE" ]; then
  root="$(pwd)"
  while [ -n "$root" ]; do
    if [ -e "${root}/.rbenv-gemsets" ]; then
      RBENV_GEMSET_FILE="${root}/.rbenv-gemsets"
      break
    elif [ -e "${root}/.ruby-gemset" ]; then
      RBENV_GEMSET_FILE="${root}/.ruby-gemset"
      break
    fi
    root="${root%/*}"
  done
fi

if [ -e "$RBENV_GEMSET_FILE" ]; then
  echo "$RBENV_GEMSET_FILE"
  exit
fi

exit 1
