Script 'game-add': take care about files before the removal of directory.
This commit is contained in:
parent
0cb7ece503
commit
a9baf909a4
19
game-add
19
game-add
@ -53,6 +53,8 @@ function version {
|
|||||||
function game_setup {
|
function game_setup {
|
||||||
date_re="[0-9?]{2}\.[0-9?]{2}\.[0-9?]{4}"
|
date_re="[0-9?]{2}\.[0-9?]{2}\.[0-9?]{4}"
|
||||||
: ${REPO_DIR:=`dirname "$0"`}
|
: ${REPO_DIR:=`dirname "$0"`}
|
||||||
|
# Synchronize the repository
|
||||||
|
git --git-dir=${REPO_DIR}/.git pull
|
||||||
|
|
||||||
# If no tournament given, set it to the last one
|
# If no tournament given, set it to the last one
|
||||||
if [[ -z $TOURNAMENT ]]; then
|
if [[ -z $TOURNAMENT ]]; then
|
||||||
@ -221,7 +223,9 @@ function game_store_pgns {
|
|||||||
game_dir=$(ls -1 -d 2>/dev/null \
|
game_dir=$(ls -1 -d 2>/dev/null \
|
||||||
${REPO_DIR}/${TOURNAMENT}/tours/${TOUR}/*-${white}-vs-${black})
|
${REPO_DIR}/${TOURNAMENT}/tours/${TOUR}/*-${white}-vs-${black})
|
||||||
if $CLEANUP_GAMES && [[ -n $game_dir ]]; then
|
if $CLEANUP_GAMES && [[ -n $game_dir ]]; then
|
||||||
rm -r "$game_dir"
|
git --git-dir=${REPO_DIR}/.git rm --ignore-unmatch ${game_dir}/*.pgn
|
||||||
|
local game_dir_old=
|
||||||
|
[[ -d $game_dir ]] && game_dir_old=$game_dir
|
||||||
game_dir=
|
game_dir=
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -237,6 +241,11 @@ function game_store_pgns {
|
|||||||
[[ -n $old_pgns ]] && pgn_index=$(wc -l <<< "$old_pgns")
|
[[ -n $old_pgns ]] && pgn_index=$(wc -l <<< "$old_pgns")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if $CLEANUP_GAMES && [[ -n $game_dir_old ]]; then
|
||||||
|
git --git-dir=${REPO_DIR}/.git mv ${game_dir_old}/* ${game_dir}
|
||||||
|
rm -r $game_dir_old
|
||||||
|
fi
|
||||||
|
|
||||||
for pgn in $TMP_PGN_FILES; do
|
for pgn in $TMP_PGN_FILES; do
|
||||||
(( pgn_index += 1 ))
|
(( pgn_index += 1 ))
|
||||||
echo "Storing file ${game_dir}/${pgn_index}.pgn..."
|
echo "Storing file ${game_dir}/${pgn_index}.pgn..."
|
||||||
@ -267,8 +276,11 @@ function game_update_info {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function game_git_commit {
|
function game_git_commit {
|
||||||
git --git-dir=${REPO_DIR}/.git add ${game_dir}/*.pgn $tour_info
|
git --git-dir=${REPO_DIR}/.git add ${game_dir} $tour_info
|
||||||
git --git-dir=${REPO_DIR}/.git commit -m "Tour ${TOUR#0}: ${white} vs. ${black}."
|
local title=$(awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}' \
|
||||||
|
<<< ${TOURNAMENT##*-})
|
||||||
|
git --git-dir=${REPO_DIR}/.git commit -m \
|
||||||
|
"Tournament ${title}, tour ${TOUR#0}: ${white} vs. ${black}."
|
||||||
git --git-dir=${REPO_DIR}/.git push
|
git --git-dir=${REPO_DIR}/.git push
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +316,6 @@ shift $(($OPTIND - 1))
|
|||||||
$ADD_GAMES && $CLEANUP_GAMES && usage 1
|
$ADD_GAMES && $CLEANUP_GAMES && usage 1
|
||||||
|
|
||||||
game_setup
|
game_setup
|
||||||
git --git-dir=${REPO_DIR}/.git pull # synchronize the repository
|
|
||||||
game_tmp_pgns $@
|
game_tmp_pgns $@
|
||||||
game_get_info
|
game_get_info
|
||||||
game_store_pgns
|
game_store_pgns
|
||||||
|
Loading…
Reference in New Issue
Block a user