+/*
+ * See if work tree has an entity that can be staged. Return 0 if so,
+ * return 1 if not and return -1 if error.
+ */
+static int check_work_tree_entity(const struct cache_entry *ce, struct stat *st, char *symcache)
+{
+ if (lstat(ce->name, st) < 0) {
+ if (errno != ENOENT && errno != ENOTDIR)
+ return -1;
+ return 1;
+ }
+ if (has_symlink_leading_path(ce->name, symcache))
+ return 1;
+ if (S_ISDIR(st->st_mode)) {
+ unsigned char sub[20];
+ if (resolve_gitlink_ref(ce->name, "HEAD", sub))
+ return 1;
+ }
+ return 0;
+}