From a1d7dcb6d990343c3c689114531f2b49daa8bb04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 24 Nov 2020 16:17:01 +0100 Subject: scripts/utils: try to lock when hacking worktree --- scripts/utils | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/utils b/scripts/utils index c17e37f..e05f10d 100644 --- a/scripts/utils +++ b/scripts/utils @@ -25,12 +25,19 @@ echo_fail() { } ## GIT ########################################################################## +# Locked git +lgit() { + local gitdir="$1" + shift + flock --exclusive "$gitdir" git --git-dir="$gitdir" "$@" +} + # Fetch bare git repository # First argument has to be a source URL # Second argument is path to directory to which will be repository cloned to. git_fetch_bare() { if [ -d "$2" ]; then - git --git-dir="$2" --bare remote update --prune + lgit "$2" --bare remote update --prune else git clone --mirror "$1" "$2" fi @@ -42,8 +49,8 @@ _git_fetch() { local branch="$3" [ -n "$branch" ] || branch=master git_fetch_bare "$1" "$4/$2" - git --git-dir="$4/$2" --bare worktree prune # remove old work trees - git --git-dir="$4/$2" --bare worktree add --force --detach "$2" "$branch" + lgit "$4/$2" --bare worktree prune # remove old work trees + lgit "$4/$2" --bare worktree add --force --detach "$2" "$branch" } # Fetch git repository with mirror -- cgit v1.2.3