diff --git a/src/index.c b/src/index.c index e1b52610b..afd9cfccd 100644 --- a/src/index.c +++ b/src/index.c @@ -138,6 +138,15 @@ int unmerged_cmp(const void *a, const void *b) return strcmp(info_a->path, info_b->path); } +unsigned int index_create_mode(unsigned int mode) +{ + if (S_ISLNK(mode)) + return S_IFLNK; + if (S_ISDIR(mode) || (mode & S_IFMT) == 0160000) + return 0160000; + return S_IFREG | ((mode & 0100) ? 0755 : 0644); +} + static int index_initialize(git_index **index_out, git_repository *owner, const char *index_path) { git_index *index; @@ -419,7 +428,7 @@ static int index_init_entry(git_index_entry *entry, git_index *index, const char /* entry.ctime.nanoseconds = st.st_ctimensec; */ entry->dev= st.st_rdev; entry->ino = st.st_ino; - entry->mode = st.st_mode; + entry->mode = index_create_mode(st.st_mode); entry->uid = st.st_uid; entry->gid = st.st_gid; entry->file_size = st.st_size;