added check-tree command

This commit is contained in:
Lucas Frérot 2024-12-31 14:01:49 +01:00
parent 68683c9c97
commit af3784ba24
No known key found for this signature in database
GPG Key ID: 03B54A50E3FBA7E8
2 changed files with 39 additions and 20 deletions

36
rtenets
View File

@ -282,6 +282,41 @@ create_tenet_file_tree() {
script_stub make_all_figures "Generating figures..."
}
# Check tree structure
check-tree() {
local directory="$1"
local check_failed=0
pushd "${directory}" >/dev/null
# Test directory is a git repo
if ! \git status > /dev/null 2>&1; then
warning "git failed: $PWD is not a repo"
check_failed=1
fi
# Test config values
if ! ( [[ "$(\git config user.name)" != "" ]] \
&& [[ "$(\git config user.email)" != "" ]] ); then
warning "git config failed"
check_failed=1
fi
# Test file structure
mandatory_files=("README.md~"
"AUTHORS"
"COPYING"
"make_all_figures"
"tests/run_all_tests")
for file in ${mandatory_files[*]}; do
if ! [[ -f "${file}" ]]; then
warning "file ${file} is missig"
check_failed=1
fi
done
popd >/dev/null
return ${check_failed}
}
# ----------------- Gitea commands -----------------------
get_gitea_owner() {
@ -440,6 +475,7 @@ main() {
[init-gitea]=init-gitea
[init-workflow]=init-workflow
[create]=create
[check-tree]=check-tree
)
"${COMMANDS[${command:-default}]:-${COMMANDS[default]}}" "${other_args}"

View File

@ -6,26 +6,9 @@ source ../rtenets
test_init-tree() {
info "running test_init-tree"
init-tree .
# Test directory is a git repo
\git status > /dev/null 2>&1 \
|| ( echo "git failed: $PWD is not a repo"; exit 1 )
# Test config values
[[ "$(\git config user.name)" != "" ]] \
&& [[ "$(\git config user.email)" != "" ]] \
|| ( echo "git config failed"; exit 1 )
# Test file structure
mandatory_files=("README.md~"
"AUTHORS"
"COPYING"
"make_all_figures"
"tests/run_all_tests")
for file in ${mandatory_files[*]}; do
[[ -f "${file}" ]] || ( echo "file ${file} is missig"; exit 1 )
done
info "finished test_init-tree"
check-tree . \
&& info "[✅] passed test_init-tree" \
|| warning "[❌] failed test_init-tree"
}