From ae98d9d18415f10ba65aeebdcd942d86f30ddb60 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 19 Jun 2017 16:41:26 -0700 Subject: [PATCH] helper/needs_update_check.sh: allow test scripts access Signed-off-by: Kyle J. McKay --- t/helper/.gitignore | 1 + t/helper/needs_update_check.sh | 98 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 t/helper/needs_update_check.sh diff --git a/t/helper/.gitignore b/t/helper/.gitignore index c77e5db..0990995 100644 --- a/t/helper/.gitignore +++ b/t/helper/.gitignore @@ -1,3 +1,4 @@ /branch_needs_update /navigate_deps +/needs_update_check /recurse_deps_internal diff --git a/t/helper/needs_update_check.sh b/t/helper/needs_update_check.sh new file mode 100644 index 0000000..9ab3dfd --- /dev/null +++ b/t/helper/needs_update_check.sh @@ -0,0 +1,98 @@ +#!/bin/sh +# TopGit needs_update_check test helper command +# Copyright (C) 2015,2017 Kyle J. McKay +# All rights reserved. +# License GPLv2 + +USAGE="\ +Usage: ${0##*/} [-C ] [-r ] [-u] [--no-cache] [--no-remotes] [--no-self] [--no-same] [--] " + +usage() +{ + if [ "${1:-0}" != 0 ]; then + printf '%s\n' "$USAGE" >&2 + else + printf '%s\n' "$USAGE" + fi + exit ${1:-0} +} + +fatal() +{ + printf 'fatal: %s\n' "$*" >&2 + exit 1 +} + +cmd_path() ( + { "unset" -f command unset unalias "$1"; } >/dev/null 2>&1 || : + { "unalias" -a || unalias -m "*"; } >/dev/null 2>&1 || : + command -v "$1" +) + +# unset that ignnores error code that shouldn't be produced according to POSIX +unset_() { + unset "$@" || : +} + +set -e + +tgbin="$(cmd_path tg)" && [ -n "$tgbin" ] && [ -x "$tgbin" ] && [ -r "$tgbin" ] || + fatal "tg not found in \$PATH or not executable or not readable" + +unset_ noremote nocache +while [ $# -gt 0 ]; do case "$1" in + -h|--help) + usage + ;; + -C) + shift + [ -n "$1" ] || fatal "option -C requires an argument" + cd "$1" + ;; + -u) + noremote=1 + ;; + -r) + shift + [ -n "$1" ] || fatal "option -r requires an argument" + base_remote="$1" + unset_ noremote + ;; + --no-cache) + nocache=1 + ;; + --no-remotes) + no_remotes=1 + ;; + --no-self) + needs_update_check_no_self=1 + ;; + --no-same) + needs_update_check_no_same=1 + ;; + --) + shift + break + ;; + -?*) + echo "Unknown option: $1" >&2 + usage 1 + ;; + *) + break + ;; +esac; shift; done + +tg__include=1 +# MUST do this AFTER changing the current directory since it sets $git_dir! +. "$tgbin" +[ -z "$noremote" ] || base_remote= + +[ -n "$nocache" ] || become_cacheable +[ $# -gt 0 ] || set -- $(navigate_deps -s=-1) +needs_update_check "$@" +printf '%s\n' \ + "${needs_update_processed:-:}" \ + "${needs_update_behind:-:}" \ + "${needs_update_ahead:-:}" \ + "${needs_update_partial:-:}" -- 2.11.4.GIT