Code

git-fetch.sh printed protocol fix
[git.git] / refs.c
diff --git a/refs.c b/refs.c
index aab14fc107353099756403c1bf08a0786e184d98..98327d798375d2bc966f877af227a03070ce5d1b 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -42,6 +42,12 @@ const char *resolve_ref(const char *path, unsigned char *sha1, int reading)
                        }
                }
 
+               /* Is it a directory? */
+               if (S_ISDIR(st.st_mode)) {
+                       errno = EISDIR;
+                       return NULL;
+               }
+
                /*
                 * Anything else, just open it and try to use it as
                 * a ref
@@ -313,8 +319,8 @@ static struct ref_lock *lock_ref_sha1_basic(const char *path,
        }
        lock->lk = xcalloc(1, sizeof(struct lock_file));
 
-       lock->ref_file = strdup(path);
-       lock->log_file = strdup(git_path("logs/%s", lock->ref_file + plen));
+       lock->ref_file = xstrdup(path);
+       lock->log_file = xstrdup(git_path("logs/%s", lock->ref_file + plen));
        lock->force_write = lstat(lock->ref_file, &st) && errno == ENOENT;
 
        if (safe_create_leading_directories(lock->ref_file))