summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2020-11-24 16:17:01 +0100
committerKarel Kočí <cynerd@email.cz>2020-11-24 16:17:01 +0100
commita1d7dcb6d990343c3c689114531f2b49daa8bb04 (patch)
tree711367ccd6e8ce41fb7732c2e3a0f8c2f060a570 /scripts
parent0c431b64884b0665e3165d69e7537203fca03793 (diff)
downloadlaminar-cnf-a1d7dcb6d990343c3c689114531f2b49daa8bb04.tar.gz
laminar-cnf-a1d7dcb6d990343c3c689114531f2b49daa8bb04.tar.bz2
laminar-cnf-a1d7dcb6d990343c3c689114531f2b49daa8bb04.zip
scripts/utils: try to lock when hacking worktree
Diffstat (limited to 'scripts')
-rw-r--r--scripts/utils13
1 files 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