From 7d8a8f8bb58038aed32e6dcfb89f12df98e613a3 Mon Sep 17 00:00:00 2001 From: pgrmega Date: Thu, 24 Mar 2022 16:36:47 +0100 Subject: [PATCH] Fix error "fatal: cannot lock ref ... Not a directory" This fix for the issue : https://github.com/git-for-windows/git/issues/3727 Use case : Creation of a tag in the form "parent/child". Exemple : > git tag -a -m "my message" tagdir/mytag Context : $ git --version --build-options git version 2.35.1.windows.2 cpu: x86_64 built from commit: 5437f0fd368c7faf1a0b5e1fef048232c1f2a3e6 sizeof-long: 4 sizeof-size_t: 8 shell-path: /bin/sh feature: fsmonitor--daemon $ cmd.exe /c ver Microsoft Windows [Version 10.0.17763.2565] Error : fatal: cannot lock ref 'refs/tags/tagdir/mytag': unable to resolve reference 'refs/tags/tagdir/mytag': Not a directory Problem analysis: GetFileAttributesExW used in mingw_lstat function in git/compat/mingw.c can raise an error ERROR_PATH_NOT_FOUND. In this case, the has_valid_directory_prefix is used to check if the parent directory exists. So that, when the parent directory exists, mingw_lstat returns ENOTDIR. ENOTDIR is not managed by the caller code (files_read_raw_ref in git/refs/files-backend.c). It probably should. Conclusion This commit enables to take into account the case when ENOTDIR is returned by mingw_lstat. Signed-off-by: pgrmega --- refs/files-backend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 081512b9bbac89..a0332835837aad 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -381,7 +381,7 @@ static int read_ref_internal(struct ref_store *ref_store, const char *refname, if (lstat(path, &st) < 0) { int ignore_errno; myerr = errno; - if (myerr != ENOENT || skip_packed_refs) + if (((myerr != ENOENT) && (myerr != ENOTDIR)) || skip_packed_refs) goto out; if (refs_read_raw_ref(refs->packed_ref_store, refname, oid, referent, type, &ignore_errno)) {