git-rm: don't remove newly added file without -f
Given this set of commands: $ echo "newly added file" >new $ git add new $ git rm new the file "new" was previously removed from the working directory and the index. Because it was not in HEAD, it is available only by searching for unreachable objects. Instead, we now err on the safe side and refuse to remove a file which is not referenced by HEAD. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jeff King committed
Mar 26, 2007 at 14:55 UTC
e4d9516b2196623d927e232b4e8766269a837fe6
1 file changed
+4
-14
builtin-rm.c
+4
-14
@@ -89,20 +89,10 @@ static int check_local_mod(unsigned char *head)
89
if (ce_match_stat(ce, &st, 0))
90
errs = error("'%s' has local modifications "
91
"(hint: try -f)", ce->name);
92
- if (no_head)
93
- continue;
94
- /*
95
- * It is Ok to remove a newly added path, as long as
96
- * it is cache-clean.
97
- */
98
- if (get_tree_entry(head, name, sha1, &mode))
99
- continue;
100
- /*
101
- * Otherwise make sure the version from the HEAD
102
- * matches the index.
103
- */
104
- if (ce->ce_mode != create_ce_mode(mode) ||
105
- hashcmp(ce->sha1, sha1))
92
+ if (no_head
93
+ || get_tree_entry(head, name, sha1, &mode)
94
+ || ce->ce_mode != create_ce_mode(mode)
95
+ || hashcmp(ce->sha1, sha1))
96
errs = error("'%s' has changes staged in the index "
97
"(hint: try -f)", name);
98
}