Commit 394d8aaa authored by Sam Ruby's avatar Sam Ruby Committed by Sam Stephenson
Browse files

cache git clone directory

if RUBY_BUILD_CACHE_PATH is set, create and maintain a local bare git
repository in this location.  The name of the git repository is based
on the git URL, so it will be shared between branches.
parent 5273fb32
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -292,6 +292,20 @@ fetch_git() {
  echo "Cloning ${git_url}..." >&2

  if type git &>/dev/null; then
    if [ -n "$RUBY_BUILD_CACHE_PATH" ]; then
      pushd "$RUBY_BUILD_CACHE_PATH" >&4
      local clone_name=$(echo $git_url | sed "s/[^a-z0-9.]/_/g; s/__*/_/g")
      if [ -e "${clone_name}" ]; then
        { cd "${clone_name}"
          git fetch --force "$git_url" "+${git_ref}:${git_ref}" 
        } >&4 2>&1
      else
        git clone --bare --branch "$git_ref" "$git_url" "${clone_name}" >&4 2>&1
      fi
      git_url="file://$RUBY_BUILD_CACHE_PATH/${clone_name}"
      popd >&4
    fi

    git clone --depth 1 --branch "$git_ref" "$git_url" "${package_name}" >&4 2>&1
  else
    echo "error: please install \`git\` and try again" >&2