Skip to content

Commit 567087a

Browse files
committed
Fix error "fatal: cannot lock ref ... Not a directory"
This fix for the issue : #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: 5437f0f 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: Pierre Garnier <[email protected]>
1 parent 158a30d commit 567087a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

refs/files-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static int files_read_raw_ref(struct ref_store *ref_store, const char *refname,
382382
if (lstat(path, &st) < 0) {
383383
int ignore_errno;
384384
myerr = errno;
385-
if (myerr != ENOENT)
385+
if (myerr != ENOENT && myerr != ENOTDIR)
386386
goto out;
387387
if (refs_read_raw_ref(refs->packed_ref_store, refname, oid,
388388
referent, type, &ignore_errno)) {

0 commit comments

Comments
 (0)