# vim:et sts=2 sw=2 ft=zsh
builtin emulate -L zsh

local git_root
git_root=$(git-root) || return 1

if (( # != 2 )); then
  print -u2 "usage: ${0} <source> <destination>"
  return 2
fi

local -r src=${1} dst=${2}
local -r url=$(command git -C ${git_root} config --file .gitmodules --get submodule.${src}.url)
if [[ -z ${url} ]]; then
  print -u2 "${0}: submodule not found: ${src}"
  return 1
fi

command mkdir -p ${dst:h} && \
    git-submodule-remove ${src} && \
    command git -C ${git_root} submodule add ${url} ${dst}
