def git_clone_repo(git_url, repo_dir)
destination = (repo_dir ? " \"#{repo_dir}\"" : "")
cmd = "#{discover_git_executable} clone #{git_url}#{destination}"
debug "Running #{cmd}"
status, stdout, stderr = run_with_tee(cmd)
if status != 0
case stderr
when /fatal: destination path '[^']*' already exists and is not an empty directory./
raise RHC::GitDirectoryExists, "The directory you are cloning into already exists."
when /^Permission denied \(.*?publickey.*?\).$/
raise RHC::GitPermissionDenied, "You don't have permission to access this repository. Check that your SSH public keys are correct."
else
raise RHC::GitException, "Unable to clone your repository. Called Git with: #{cmd}"
end
end
File.expand_path(repo_dir)
end