Skip to content

Commit

Permalink
Fix error "fatal: cannot lock ref ... Not a directory"
Browse files Browse the repository at this point in the history
This fix for the issue : git-for-windows#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.
  • Loading branch information
pgrmega authored Mar 24, 2022
1 parent 158a30d commit f4d3b26
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion refs/files-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ static int files_read_raw_ref(struct ref_store *ref_store, const char *refname,
if (lstat(path, &st) < 0) {
int ignore_errno;
myerr = errno;
if (myerr != ENOENT)
if (myerr != ENOENT && myerr != ENOTDIR)
goto out;
if (refs_read_raw_ref(refs->packed_ref_store, refname, oid,
referent, type, &ignore_errno)) {
Expand Down

0 comments on commit f4d3b26

Please sign in to comment.