From 755566ca73bfe3cc229fe90fcc0ba87d58325771 Mon Sep 17 00:00:00 2001 From: Russell Cloran Date: Fri, 6 Oct 2023 22:01:28 -0700 Subject: [PATCH] Check .git dir in clone migration check When the last part of the repository name is the same as the first part of it, the old -> new directory migration code is triggered, since a "top level" directory of the second part's name exists. In the least-bad case, where the `repos-dir` is separate from the znap or any other git repository, this triggers an unnecessary invocation of git, costing a few ms of startup time. However, the bad case is that some users seem to have set things up so that their `repos-dir` is a subdirectory of the znap repository. This causes the `git remote ...` call to succeed, triggering the full migration, and cloning the repository back into the same place. Instead of just checking for a directory's existence, we can check for a git repository's existence fairly cheaply by checking for the `git` directory. Fixes #257 --- functions/.znap.clone.task | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/.znap.clone.task b/functions/.znap.clone.task index ae6fbfd..388c37f 100644 --- a/functions/.znap.clone.task +++ b/functions/.znap.clone.task @@ -15,7 +15,7 @@ local gitdir='' local -P name=${${${url##git@*.*:}%%(|/).git}:t2} private new= old=$gitdir/${name:t} -if [[ -d $old ]]; then +if [[ -d ${old}/.git ]]; then if new=$gitdir/${${(M)$( git -C $old remote get-url origin 2> /dev/null )%%[^/:]##/[^/:]##}%.git}; then