Re: [PATCH 2/2] git clone: don't clone into non-empty directory
- From
Ben <ben@wijen.net>
- Date
- Jul 2, 2020, 07:50 UTC
- Message-ID
- <fe053a22-16a1-a071-520c-9bb5be7dc09f@wijen.net>
- In-Reply-To
- <CAPig+cTEpajuD98RH5xepJ+rK2f75SROrTvgjzKnyfjxbuA1AQ@mail.gmail.com>
On 01-07-2020 18:10, Eric Sunshine wrote:
Show 10 quoted lines
> On Wed, Jul 1, 2020 at 5:46 AM Ben Wijen <ben@wijen.net> wrote: > > "git init --separate-git-dir=" checks only whether the path exists, > and errors out if it does; it doesn't care whether the directory is > empty or not. I'm wondering, therefore, if this check should be > tightened to more closely align the behavior of the two commands. > (Using the tighter semantic now doesn't prohibit loosening it in the > future, whereas it's harder to tighten behavior which started out > loose.) >
About `git init`, I did take a look at it, but saw 'exist_ok' is always true when called from 'cmd_init_db' (see builtin/init_db.c:654) This means `git init` always allows when git_dir/real_git_dir already exists, which I understand for the worktree, but I doubt if one wants this for the repository. (when --separate-git-dir is used)
Also, because 'exist_ok' is always true for `git init` and - with this patch - `git clone` checks the git_dir/real_git_dir before the 'init_db' call I'm wondering if the code in 'init_db' (builtin/init-db.c:394-400) can be removed.
Then, even if we do take that route (no 'is_empty_dir', only 'path_exists') we must also address junk_git_dir_flags, as REMOVE_DIR_KEEP_TOPLEVEL would invalidate a second git clone.
So, as this patch only fixes the problem at hand, IMHO separate patch-sets should be created for mentioned issues.
Ben...