diff options
author | Junio C Hamano <junkio@cox.net> | 2006-05-17 01:17:46 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-05-17 01:52:48 -0700 |
commit | fcc387db9bc453dc7e07a262873481af2ee9e5c8 (patch) | |
tree | a3853842dc72ee181a0f548aa2a9ba0105464fd5 /read-tree.c | |
parent | 63dffdf03da65ddf1a02c3215ad15ba109189d42 (diff) | |
download | git-fcc387db9bc453dc7e07a262873481af2ee9e5c8.tar.gz |
read-tree -m -u: do not overwrite or remove untracked working tree files.
When a merge results in a creation of a path that did not exist
in HEAD, and if you already have that path on the working tree,
because the index has not been told about the working tree file,
read-tree happily removes it. The issue was brought up by Santi
BĂ©jar on the list.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'read-tree.c')
-rw-r--r-- | read-tree.c | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/read-tree.c b/read-tree.c index e16e91b173..82e2a9a4d3 100644 --- a/read-tree.c +++ b/read-tree.c @@ -408,7 +408,7 @@ static void verify_uptodate(struct cache_entry *ce) { struct stat st; - if (index_only) + if (index_only || reset) return; if (!lstat(ce->name, &st)) { @@ -426,6 +426,21 @@ static void verify_uptodate(struct cache_entry *ce) die("Entry '%s' not uptodate. Cannot merge.", 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); @@ -443,6 +458,9 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old) verify_uptodate(old); } } + else + verify_absent(merge->name, "overwritten"); + merge->ce_flags &= ~htons(CE_STAGEMASK); add_cache_entry(merge, ADD_CACHE_OK_TO_ADD); return 1; @@ -452,6 +470,8 @@ static int deleted_entry(struct cache_entry *ce, struct cache_entry *old) { if (old) verify_uptodate(old); + else + verify_absent(ce->name, "removed"); ce->ce_mode = 0; add_cache_entry(ce, ADD_CACHE_OK_TO_ADD); return 1; @@ -487,6 +507,7 @@ static int threeway_merge(struct cache_entry **stages) int count; int head_match = 0; int remote_match = 0; + const char *path = NULL; int df_conflict_head = 0; int df_conflict_remote = 0; @@ -498,8 +519,11 @@ static int threeway_merge(struct cache_entry **stages) for (i = 1; i < head_idx; i++) { if (!stages[i]) any_anc_missing = 1; - else + else { + if (!path) + path = stages[i]->name; no_anc_exists = 0; + } } index = stages[0]; @@ -515,8 +539,15 @@ static int threeway_merge(struct cache_entry **stages) remote = NULL; } + if (!path && index) + path = index->name; + if (!path && head) + path = head->name; + if (!path && remote) + path = remote->name; + /* First, if there's a #16 situation, note that to prevent #13 - * and #14. + * and #14. */ if (!same(remote, head)) { for (i = 1; i < head_idx; i++) { @@ -575,6 +606,8 @@ static int threeway_merge(struct cache_entry **stages) (remote_deleted && head && head_match)) { if (index) return deleted_entry(index, index); + else if (path) + verify_absent(path, "removed"); return 0; } /* @@ -592,6 +625,8 @@ static int threeway_merge(struct cache_entry **stages) if (index) { verify_uptodate(index); } + else if (path) + verify_absent(path, "overwritten"); nontrivial_merge = 1; @@ -689,7 +724,7 @@ static int oneway_merge(struct cache_entry **src) merge_size); if (!a) - return deleted_entry(old, NULL); + return deleted_entry(old, old); if (old && same(old, a)) { if (reset) { struct stat st; @@ -699,7 +734,7 @@ static int oneway_merge(struct cache_entry **src) } return keep_entry(old); } - return merged_entry(a, NULL); + return merged_entry(a, old); } static int read_cache_unmerged(void) |