summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 192268c)
raw | patch | inline | side by side (parent: 192268c)
author | Junio C Hamano <junkio@cox.net> | |
Sun, 8 May 2005 07:05:18 +0000 (00:05 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sun, 8 May 2005 07:05:18 +0000 (00:05 -0700) |
When we used to have "path" as a file or a symlink, but now we
have "path/file" (or in general, have "path" as a directory), we
would want to remove "path" before adding "path/file". The
logic in add_file_to_cache() only runs lstat() and does not
detect this case and fails to allow removing it in this case.
In the opposite case of having "path/file" in the index and
having "path" on the filesystem as a file or a symlink we do
allow removal of "path/file", so to be symmetric we should allow
it as well, without forcing the user to say --force-remove.
Signed-off-by: Junio C Hamano <junkio@cox.net>
have "path/file" (or in general, have "path" as a directory), we
would want to remove "path" before adding "path/file". The
logic in add_file_to_cache() only runs lstat() and does not
detect this case and fails to allow removing it in this case.
In the opposite case of having "path/file" in the index and
having "path" on the filesystem as a file or a symlink we do
allow removal of "path/file", so to be symmetric we should allow
it as well, without forcing the user to say --force-remove.
Signed-off-by: Junio C Hamano <junkio@cox.net>
update-cache.c | patch | blob | history |
diff --git a/update-cache.c b/update-cache.c
index 1e4e62cc4c99e1372afa658198f504df28e53dd4..69b1afec94ef0a6716c85f128696c1da835433e9 100644 (file)
--- a/update-cache.c
+++ b/update-cache.c
static int add_file_to_cache(char *path)
{
- int size, namelen, option;
+ int size, namelen, option, status;
struct cache_entry *ce;
struct stat st;
int fd;
char *target;
- if (lstat(path, &st) < 0) {
- if (errno == ENOENT || errno == ENOTDIR) {
+ status = lstat(path, &st);
+ if (status < 0 || S_ISDIR(st.st_mode)) {
+ /* When we used to have "path" and now we want to add
+ * "path/file", we need a way to remove "path" before
+ * being able to add "path/file". However,
+ * "git-update-cache --remove path" would not work.
+ * --force-remove can be used but this is more user
+ * friendly, especially since we can do the opposite
+ * case just fine without --force-remove.
+ */
+ if (status == 0 || (errno == ENOENT || errno == ENOTDIR)) {
if (allow_remove)
return remove_file_from_cache(path);
}