Skip to content

Commit

Permalink
Check .git dir in clone migration check
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rcloran authored and marlonrichert committed Dec 14, 2023
1 parent 0425bfb commit 755566c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion functions/.znap.clone.task
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 755566c

Please sign in to comment.