From 0f62d0677e6960f6804df71a49af81f3bf74fa2a Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Thu, 27 Aug 2020 12:13:49 +0200 Subject: [PATCH] TT#81700 bin/reorder_tests_tt2.sh helper tool to rename tt2 files when adding new messages Change-Id: I57b5ea25065be8743d2a4449c53e01da76ae5e76 --- bin/reorder_tests_tt2.sh | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 bin/reorder_tests_tt2.sh diff --git a/bin/reorder_tests_tt2.sh b/bin/reorder_tests_tt2.sh new file mode 100755 index 00000000..e8471287 --- /dev/null +++ b/bin/reorder_tests_tt2.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +die() +{ + echo "ERROR: $1" >&2 + exit "${2:-1}" +} + +log_info() +{ + echo "INFO: $*" +} + +INI=$1 +DISP=${2:-1} + +case $# in + 1|2) ;; + *) echo "Wrong number or arguments"; usage; exit 1;; +esac + +last_file=$(printf "%04d_test.yml.tt2" "${INI}") + +if ! [ -f "${last_file}" ] ; then + die "can't find ${last_file}" +fi + +find . -name '0*_test.yml.tt2' | sort -r | while read -r tfile ; do + [[ ${tfile} =~ /0*([0-9]+)_test\.yml\.tt2 ]] || die "wtf" + num=${BASH_REMATCH[1]} + if [[ ${num} -ge ${INI} ]]; then + (( next = "$num" + "$DISP" )) + next_file=$(printf "%04d_test.yml.tt2" $next) + if [ -f "${next_file}" ] ; then + die "file ${next_file} already exist" + fi + git mv "${tfile}" "${next_file}" + log_info "OK ${num} => $next" + else + log_info "nothing to do with ${tfile}" + fi +done