#!/usr/bin/env build build_fetch_git() { build_fetch_git_uri="$(build-url --base "${1}")" build_fetch_git_uri="${build_fetch_git_uri#git://}" build_fetch_git_uri="${build_fetch_git_uri%%\?*}" build_fetch_git_tag= build_fetch_git_commit= build_fetch_git_var= for arg in $(build-url --arg "${1}"); do case "${arg}" in (archive=*) build_fetch_git_var="${arg##*=}";; (commit=*) build_fetch_git_commit="${arg##*=}";; (*) build_fetch_git_tag="${arg}";; esac done if [ -z "${build_fetch_git_var}" ]; then die "do not know how to store source from '${1}'" fi # We want to avoid avoid copying the repository and all of its history # in order to perform a single build, unfortunately git does not give a # clear-cut approach to checkout out a specific tag or the head of a # specific branch, instead we have to jump through some hoops. build_fetch_git_dir="${build_fetch_git_var%%.t*}" build_fetch_git_tmp="$(mktemp -d "${BUILDER_TMPDIR}/${build_fetch_git_dir}.XXXXXX")" cd "${build_fetch_git_tmp}" BUILD_FETCH_CLEAN="${BUILD_FETCH_CLEAN} ${build_fetch_git_tmp}" case "${build_fetch_git_uri}" in (*:[0-9]*) build_fetch_git_uri="git://${build_fetch_git_uri}";; (*:*) build_fetch_new_uri="${build_fetch_git_uri##*:}" build_fetch_new_uri="${build_fetch_new_uri#/}" build_fetch_git_uri="ssh://${build_fetch_git_uri%%:*}/${build_fetch_new_uri}" unset build_fetch_new_uri;; (*) build_fetch_git_uri="git://${build_fetch_git_uri}";; esac if [ ! -z "${build_fetch_git_tag}" ]; then case "${build_fetch_git_tag}" in (tags/*) if ! git clone --depth 1 "${build_fetch_git_uri}" "${build_fetch_git_dir}"; then die "failed to clone git source at '${build_fetch_git_uri}'" fi if ! cd "${build_fetch_git_dir}"; then die "failed to change working directory to '${build_fetch_git_dir}'" fi if ! git fetch --tags --depth 1 "${build_fetch_git_uri}" "${build_fetch_git_tag}"; then die "failed to fetch git branch/tag '${build_fetch_git_tag}'" fi if ! git checkout "${build_fetch_git_tag}"; then die "failed to checkout git branch/tag '${build_fetch_git_tag}'" fi ;; (*) if ! git clone --depth 1 --branch "${build_fetch_git_tag}" "${build_fetch_git_uri}" "${build_fetch_git_dir}"; then die "failed to clone git source at '${build_fetch_git_uri}'" fi ;; esac elif [ ! -z "${build_fetch_git_commit}" ]; then if ! git clone "${build_fetch_git_uri}" "${build_fetch_git_dir}"; then die "failed to clone git source at '${build_fetch_git_uri}'" fi if ! cd "${build_fetch_git_dir}"; then die "failed to change working directory to '${build_fetch_git_dir}'" fi if ! git checkout "${build_fetch_git_commit}"; then die "failed to checkout git commit '${build_fetch_git_commit}'" fi else if ! git clone --depth 1 "${build_fetch_git_uri}" "${build_fetch_git_dir}"; then die "failed to clone git source at '${build_fetch_git_uri}'" fi fi cd "${build_fetch_git_tmp}" case "${build_fetch_git_var}" in (*tar.Z|*tz) tar cZf "${build_fetch_git_var}" "${build_fetch_git_dir}";; (*tgz|*tar.gz) tar czf "${build_fetch_git_var}" "${build_fetch_git_dir}";; (*tar.bz2) tar cjf "${build_fetch_git_var}" "${build_fetch_git_dir}";; (*) tar caf "${build_fetch_git_var}" "${build_fetch_git_dir}";; esac if [ ! -d "${BUILDER_SRCDIR}" ]; then mkdir -p "${BUILDER_SRCDIR}" fi mv "${build_fetch_git_var}" "${BUILDER_SRCDIR}/${build_fetch_git_var}" if [ -d "${build_fetch_git_tmp}" ]; then rm -rf "${build_fetch_git_tmp}" fi unset build_fetch_git_tmp unset build_fetch_git_var unset build_fetch_git_dir unset build_fetch_git_uri unset build_fetch_git_tag } if test "${BUILDER_CALL_STACK}" = '__main__'; then simple_usage 'fetch-git' '' "$@" build_fetch_git "${1}" fi # vim: filetype=sh