#!/bin/bash

# Thanks Carl!

# hacked up a bit to deal with '..' by matyas

file=file:///p/condor/workspaces/vdt/svn
https=https://vdt.cs.wisc.edu/svn

in_git () {
  until [[ -d .svn || -d .git || . -ef / ]]; do cd ..; done

  if [[ ! -d .svn && -d .git ]]; then
    echo git
  fi
}

svn_info () {
  local dir="$1"
  # cd -P doesn't work on all systems so I'm emulating it
  (
    cd "$dir"
    cd "$(pwd -P)"
    $(in_git) svn info | awk -F': ' '$1 == "URL" {print $2}'
  )
}

if [[ $1 = -h ]]; then
  shift
  svn_info "$1" | sed "s,^$file\>,$https,"
else
  svn_info "$1"
fi

