diff options
-rw-r--r-- | subr.rtl/rtl_fetch_git.subr | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/subr.rtl/rtl_fetch_git.subr b/subr.rtl/rtl_fetch_git.subr index 9350b09c..d86db0de 100644 --- a/subr.rtl/rtl_fetch_git.subr +++ b/subr.rtl/rtl_fetch_git.subr @@ -3,16 +3,37 @@ # rtlp_fetch_url_git() { - local _cache_dname="${1}" _git_args="${2}" _git_branch="${3}" _mirrors="${4}" _pkg_name="${5}"\ - _subdir="${6}" _tgtdir="${7}" _url="${8}" _cache_dname_full="" _clonefl=0 _oldpwd="" _url_base=""; + local _cache_dname="${1}" _git_args="${2}" _git_branch="${3}" _mirrors="${4}" \ + _pkg_name="${5}" _subdir="${6}" _tgtdir="${7}" _url="${8}" _cache_dname_full="" \ + _clonefl=0 _git_pull_log_fname="" _oldpwd="" _url_base=""; _cache_dname_full="${_cache_dname}/${_subdir##*/}"; (set -o errexit -o noglob -o nounset; rtl_flock_acquire 4 || exit "${?}"; trap "rm -f \"${_cache_dname_full%%[/]}.fetching\"" EXIT; if [ -e "${_cache_dname_full}" ]; then - (rtl_fileop cd "${_cache_dname_full}" &&\ - git pull ${_git_args} origin "${_git_branch:-main}") || return 1; + (rtl_fileop cd "${_cache_dname_full}" || exit 1; + _git_pull_log_fname="$(mktemp)" || exit 1; + trap 'rm -f "${_git_pull_log_fname}" 2>/dev/null' EXIT HUP INT TERM USR1 USR2; + if ! git pull ${_git_args} origin "${_git_branch:-main}" >"${_git_pull_log_fname}" 2>&1; then + if grep -q '^fatal: refusing to merge unrelated histories$' "${_git_pull_log_fname}"; then + cat "${_git_pull_log_fname}"; printf "Detected forced push(es).\n"; + elif grep -q '^Automatic merge failed; fix conflicts and then commit the result.$' "${_git_pull_log_fname}"; then + cat "${_git_pull_log_fname}"; printf "Detected forced push(es).\n"; git merge --abort; + else + cat "${_git_pull_log_fname}"; exit 1; + fi; + while true; do + printf "Attempting git-reset(1) --hard HEAD^ and git-pull(1)...\n"; + if ! git reset --hard "HEAD^"; then + exit 1; + elif git pull ${_git_args} origin "${_git_branch:-main}"; then + exit 0; + fi; + done; + else + cat "${_git_pull_log_fname}"; exit 0; + fi;) || return 1; (rtl_fileop cd "${_cache_dname_full}" &&\ git submodule update) || return 1; else if git clone ${_git_args} -b "${_git_branch:-main}" "${_url}" "${_cache_dname_full}"; then |