diff options
author | Junio C Hamano <junkio@cox.net> | 2006-12-04 16:00:46 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-12-05 23:25:52 -0800 |
commit | f8a9d4287277ed15d3f0d61004f4510c59f1f392 (patch) | |
tree | b3a75baf61f97d601d2e4d7cf79c8399b902d9bf /unpack-trees.c | |
parent | 8ebe185bbf3f1f4f59bcc61e3d1849a76f6af983 (diff) | |
download | git-f8a9d4287277ed15d3f0d61004f4510c59f1f392.tar.gz |
read-tree: further loosen "working file will be lost" check.
This follows up commit ed93b449 where we removed overcautious
"working file will be lost" check.
A new option "--exclude-per-directory=.gitignore" can be used to
tell the "git-read-tree" command that the user does not mind
losing contents in untracked files in the working tree, if they
need to be overwritten by a merge (either a two-way "switch
branches" merge, or a three-way merge).
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'unpack-trees.c')
-rw-r--r-- | unpack-trees.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/unpack-trees.c b/unpack-trees.c index 7cfd628d8e..79d21e2e8d 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1,6 +1,7 @@ #include <signal.h> #include <sys/time.h> #include "cache.h" +#include "dir.h" #include "tree.h" #include "tree-walk.h" #include "cache-tree.h" @@ -77,6 +78,12 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len, { int baselen = strlen(base); int src_size = len + 1; + int i_stk = i_stk; + int retval = 0; + + if (o->dir) + i_stk = push_exclude_per_directory(o->dir, base, strlen(base)); + do { int i; const char *first; @@ -143,7 +150,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len, } /* No name means we're done */ if (!first) - return 0; + goto leave_directory; pathlen = strlen(first); ce_size = cache_entry_size(baselen + pathlen); @@ -240,13 +247,20 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len, newbase[baselen + pathlen] = '/'; newbase[baselen + pathlen + 1] = '\0'; if (unpack_trees_rec(subposns, len, newbase, o, - indpos, df_conflict_list)) - return -1; + indpos, df_conflict_list)) { + retval = -1; + goto leave_directory; + } free(newbase); } free(subposns); free(src); } while (1); + + leave_directory: + if (o->dir) + pop_exclude_per_directory(o->dir, i_stk); + return retval; } /* Unlink the last component and attempt to remove leading @@ -456,7 +470,7 @@ static void invalidate_ce_path(struct cache_entry *ce) /* * We do not want to remove or overwrite a working tree file that - * is not tracked. + * is not tracked, unless it is ignored. */ static void verify_absent(const char *path, const char *action, struct unpack_trees_options *o) @@ -465,7 +479,7 @@ static void verify_absent(const char *path, const char *action, if (o->index_only || o->reset || !o->update) return; - if (!lstat(path, &st)) + if (!lstat(path, &st) && !(o->dir && excluded(o->dir, path))) die("Untracked working tree file '%s' " "would be %s by merge.", path, action); } |