diff options
Diffstat (limited to 'gh-clone.sh')
-rwxr-xr-x | gh-clone.sh | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/gh-clone.sh b/gh-clone.sh index 4f3fc64..1cefa32 100755 --- a/gh-clone.sh +++ b/gh-clone.sh @@ -8,15 +8,28 @@ cd /home/pymirrors/repos/ ORIG_REPO="$1" +# Argument can be both full URL as well as just owner/reponame string +if [[ "$ORIG_REPO" =~ "http" ]]; then + OR="${ORIG_REPO##*.com/}" + ORIG_REPO="${OR%%.git}" +fi + GH_TMP_DATA=$(mktemp /tmp/gh_data.XXXXXX.json) || exit 1 trap 'rm -f "${GH_TMP_DATA}"' EXIT +DIRNAME="$(basename "${ORIG_REPO}")" +NEW_REPO="${ORGANIZATION}/${DIRNAME}" + +# Repository has been already checked out +[ -d "$DIRNAME" ] && exit 0 + git clone "https://github.com/${ORIG_REPO}.git" -cd "$(basename ${ORIG_REPO})" +cd "${DIRNAME}" curl -s -u "${USERNAME}:${PASSWORD}" \ - --json "{ \"organization\": \"${ORGANIZATION}\" }" \ + --json "{ \"organization\": \"${ORGANIZATION}\" , \ + \"default_branch_only\": \"true\" }" \ "https://api.github.com/repos/${ORIG_REPO}/forks" >"${GH_TMP_DATA}" git remote add github \ "$(awk -F '"' '/clone_url/ {print $4 ; exit}' "${GH_TMP_DATA}")" |