author | Junio C Hamano <junkio@cox.net> | |
Wed, 17 May 2006 22:54:39 +0000 (15:54 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 17 May 2006 22:54:39 +0000 (15:54 -0700) |
* jc/read-tree-safety:
read-tree -m -u: do not overwrite or remove untracked working tree files.
read-tree -m -u: do not overwrite or remove untracked working tree files.
1 | 2 | |||
---|---|---|---|---|
read-tree.c | patch | | diff1 | | diff2 | | blob | history |
diff --cc read-tree.c
index 675a59f8070b6ca5ce1789b823d85e881939c778,82e2a9a4d3663fad513f607e25fe84a8ccbf5460..a3ada55c1571e52fb3edf7c181ebfd000d7b8db6
--- 1/read-tree.c
--- 2/read-tree.c
+++ b/read-tree.c
die("Entry '%s' not uptodate. Cannot merge.", ce->name);
}
+static void invalidate_ce_path(struct cache_entry *ce)
+{
+ if (ce)
+ cache_tree_invalidate_path(active_cache_tree, ce->name);
+}
+
+ /*
+ * We do not want to remove or overwrite a working tree file that
+ * is not tracked.
+ */
+ static void verify_absent(const char *path, const char *action)
+ {
+ struct stat st;
+
+ if (index_only || reset || !update)
+ return;
+ if (!lstat(path, &st))
+ die("Untracked working tree file '%s' "
+ "would be %s by merge.", path, action);
+ }
+
static int merged_entry(struct cache_entry *merge, struct cache_entry *old)
{
merge->ce_flags |= htons(CE_UPDATE);
*merge = *old;
} else {
verify_uptodate(old);
+ invalidate_ce_path(old);
}
}
-- else
++ else {
+ verify_absent(merge->name, "overwritten");
+ invalidate_ce_path(merge);
++ }
+
merge->ce_flags &= ~htons(CE_STAGEMASK);
add_cache_entry(merge, ADD_CACHE_OK_TO_ADD);
return 1;
{
if (old)
verify_uptodate(old);
+ else
+ verify_absent(ce->name, "removed");
ce->ce_mode = 0;
add_cache_entry(ce, ADD_CACHE_OK_TO_ADD);
+ invalidate_ce_path(ce);
return 1;
}
return error("Cannot do a oneway merge of %d trees",
merge_size);
- if (!a)
+ if (!a) {
+ invalidate_ce_path(old);
- return deleted_entry(old, NULL);
+ return deleted_entry(old, old);
+ }
if (old && same(old, a)) {
if (reset) {
struct stat st;