From 9546c9c4a4fc30303272445b05e81d0d5a7c70aa Mon Sep 17 00:00:00 2001 From: Mitch Tishmack Date: Fri, 27 Nov 2015 01:26:57 -0600 Subject: [PATCH] Update magic git function to be simpler. --- git/.profile.d/20-functions-git.sh | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/git/.profile.d/20-functions-git.sh b/git/.profile.d/20-functions-git.sh index a98f151..5ef4a6e 100644 --- a/git/.profile.d/20-functions-git.sh +++ b/git/.profile.d/20-functions-git.sh @@ -7,6 +7,7 @@ maybe_git_repo() echo "${1}" | grep '://' > /dev/null 2>&1 [ $? = 0 ] && proto=$(echo "${1}" | sed -e 's|[:]\/\/.*||g') git_dir=$(echo "${1}" | sed -e 's|.*[:]\/\/||g') + rrepo="${proto}://${git_dir}" # strip user@, :NNN, and .git from input uri's repo="${destination}/"$(echo "${git_dir}" | @@ -16,22 +17,13 @@ maybe_git_repo() tr -d '~') if [ ! -d "${repo}" ]; then - mkdir -p "${repo}" - echo "git clone ${proto}://${git_dir} ${repo}" - git clone "${proto}://${git_dir}" "${repo}" - ${cmd} - if [ $? != 0 ]; then - # Try removing up to git_dir at worst empty directories. - # Cheap trick, but oldies are goodies. - ( - repo_dir="${repo}" - until [ "${repo_dir}" = "${destination}" ]; do - cd "${repo_dir}" > /dev/null 2>&1 - rmdir "${repo_dir}" > /dev/null 2>&1 - repo_dir=$(echo "${repo_dir}" | sed -e 's/\/[^\/]*$//g') - done - ) - echo "git clone of ${proto}://${repo} failed" + git ls-remote "${rrepo}" > /dev/null 2>&1 + if [ $? = 0 ]; then + mkdir -p "${repo}" + echo "git clone ${rrepo} ${repo}" + git clone "${rrepo}" "${repo}" + else + echo "${rrepo} doesn't look to be a git repository" fi fi [ -d "${repo}" ] && cd "${repo}"