-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-t3st-setup
executable file
·118 lines (107 loc) · 4.83 KB
/
git-t3st-setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh
set -ue
# Adds a git remote for `t3st`. Sets up a test dir.
_O_run=true _O_tdir= _O_fetch=true _O_hello= _O_reset=false _O_setup=true _O_t3st_branch=master
GCDIR=$(git rev-parse --git-common-dir) || { unset Not; : "${Not?in a git repo}"; }
echo 1>&2 'Configuring t3st in git config:'
git -c core.editor='echo' config -e 1>&2 2>/dev/null; echo 1>&2
cd "${GIT_PREFIX:-.}"; unset GIT_DIR # run from alias
# adapted min-template.sh (https://git@gitlab/kstr0k/bashaaparse)
__usage() { # args: <help-option> header footer
local vs=false; [ "$1" != '-?' ] || vs=true; shift
local flags p='/^_O_/!d;/[^[:alnum:]_]/d;h;s/_/-/g;s/^-O-/--/;s/$/=ARG/p'
! "$vs" || p=${p%';s'*}';G;s/\n/[='\''$/;s/$/'\'']/p'
flags=$(set | sed -n -e '/=/!d;s/=.*//' -e "$p") # posh fails: no =.*
printf '%s'${1:+'\n'} "${1:-}"
test -z "$flags" || { ! "$vs" || eval flags="\"$flags\""; printf '%s\n' "$flags"; }
printf '%s'${2:+'\n'} "${2:-}"
}
__parse_args() {
local k; test $# -gt 0 || set -- --
if ! __process_arg "$@"; then case "$1" in
-v) set -x ;;
-h|--help|--usage|-'?') __usage "$1" 'Options:'; exit 0 ;;
--*=*) k=${1%%=*}; k=_O_${k#--}
case "$k" in (*[![:alnum:]_-]*) unset Bad; : "${Bad?arg "$k"}";; esac
k=$k-; while :; do case "$k" in
*-) k=${k%%-*}_${k#*-} ;;
*) eval "${k%_}=\${1#--*=}"; break ;;
esac; done ;;
--exit) return 0 ;;
--no-?*) k=$1; shift; __parse_args "--${k#--no-}=false" "$@"; return ;;
--?*) k=$1; shift; __parse_args "$k=true" "$@"; return ;;
--) shift; __main "$@"; return $? ;;
*) __main "$@"; return $? ;;
esac; fi
shift; __parse_args "$@"
}
__process_arg() { return 1; }
setx() ( set -x; "$@" )
uninstall_git() (
set -x
git remote remove kstr0k-t3st
for u in t3st.tdir t3st.prove-shells alias.t3st-prove alias.t3st-setup; do
git config --unset "$u"
done
) # subshell function
copy_repo_file() {
local src f; src=$1 f=$2; shift 2
case "$src" in (*/|'') src=$src${f##*/} ;; esac
if [ -r "$_O_tdir"/"$f" ]; then
echo 1>&2 "# rm -f \"$_O_tdir/$f\" # exists; remove & re-run to update"
else
setx git show kstr0k-t3st/"$_O_t3st_branch":"$src" >"$_O_tdir"/"$f"
fi
}
setup_git() {
local f d
if git remote add kstr0k-t3st https://gitlab.com/kstr0k/t3st.git 2>/dev/null; then
#git config remote.kstr0k-t3st.fetch '+refs/tags/*:refs/tags/t3st/*'
: "${_O_hello:=true}"
git config remote.kstr0k-t3st.tagOpt --no-tags
git remote set-branches kstr0k-t3st "$_O_t3st_branch"
git remote set-url --push kstr0k-t3st ''
git fetch kstr0k-t3st
echo 1>&2 'Added t3st remote'; git remote -v 1>&2
else
! $_O_fetch || setx git fetch kstr0k-t3st
fi
[ "$_O_tdir" ] || { echo 1>&2 'Not setting up a t/ dir'; return 0; }
git config t3st.prove-shells >/dev/null ||
setx git config t3st.prove-shells 'sh,bash,busybox sh#,yash,mksh,dash,bash --posix,bash44,bash32,zsh,zsh --emulate sh,zsh --emulate ksh,posh'
setx git config alias.t3st-prove '!f(){ local tdir; tdir=$(git config t3st.tdir) && cd "$tdir" || exit 1; local shs sh; shs=$(git config t3st.prove-shells); shs=${shs%%#*}","; while [ "$shs" ] ; do sh=${shs%%,*}; shs=${shs#*,}; [ "$sh" ] || continue; eval "$sh -c exit" 2>/dev/null || continue; printf "\n# shell = %s\n\n" "$sh"; prove . -e "$sh" "$@"; done; }; f'
setx git config alias.t3st-setup '!f(){ git fetch --no-tags -v kstr0k-t3st || echo 1>&2 '\'''\''; git show kstr0k-t3st/'"$_O_t3st_branch"':git-t3st-setup | sh -s -- --no-fetch "$@"; }; f'
setx git config alias.t3st-new '!f(){ make -C "$(git config t3st.tdir)" -f t3st.mk new; }; f'
echo 1>&2 'Added git aliases t3st-*'
mkdir -p "$_O_tdir/t3st-lib"
for f in 't3st-lib/k9s0ke_t3st_lib.sh'= 't3st-hello.t'=t/ 't3st.mk'=t/ 't3st-lib/t3st-ttt0.sh'=t/t3st-lib/ 't3st-lib/t3st-new.t.0'=t/t3st-lib/ 't3st-lib/t3st-e.t.0'='t/t3st-e.t' ; do
case "$f" in (*/t3st-hello.t) [ "$_O_hello" ] || continue ;; esac
d=${f##*=}; f=${f%=*}
copy_repo_file "$d" "$f"
done
[ -r "$_O_tdir"/Makefile ] || ln -s t3st.mk "$_O_tdir"/Makefile
echo 1>&2 "$_O_tdir set up for t3st tests."
(chmod a+x "$_O_tdir"/*t3st*.t || :)
if [ -r "$_O_tdir"/t3st-hello.t ] && ${_O_hello:-false}; then
echo 1>&2 "Testing sample $_O_tdir/t3st-hello.t"
local prove; prove=$(command -v prove)
[ -z "$prove" ] ||
(set -x; prove -e /bin/sh -v "$_O_tdir"/t3st-hello.t :: --help)
fi
}
__set_defaults() {
[ "$_O_tdir" ] || _O_tdir=$(git config t3st.tdir) || _O_tdir=$PWD/t
[ "$_O_tdir" != false ] || _O_tdir=
if [ "$_O_tdir" ]; then
case "$_O_tdir" in /*) ;; *) _O_tdir=$(pwd -P)/$_O_tdir ;; esac
setx git config t3st.tdir "$_O_tdir"
fi
}
__main() {
$_O_run || exit 0
__set_defaults
[ $# -eq 0 ] || { unset Bad && : "${Bad?args "$*"}"; }
if $_O_reset; then uninstall_git; fi
if $_O_setup; then setup_git; fi
}
__parse_args "$@"