Read attributes from the index that is being checked out

Traditionally we used .gitattributes file from the work tree if exists,
and otherwise read from the index as a fallback.  When switching to a
branch that has an updated .gitattributes file, and entries in it give
different attributes to other paths being checked out, we should instead
read from the .gitattributes in the index.

This breaks a use case of fixing incorrect entries in the .gitattributes
in the work tree (without adding it to the index) and checking other paths
out, though.

    $ edit .gitattributes ;# mark foo.dat as binary
    $ rm foo.dat
    $ git checkout foo.dat

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano
2009-03-13 21:24:08 -07:00
parent 924189d6a2
commit 06f33c1735
3 changed files with 64 additions and 18 deletions

View File

@ -7,6 +7,7 @@
#include "unpack-trees.h"
#include "progress.h"
#include "refs.h"
#include "attr.h"
/*
* Error messages expected by scripts out of plumbing commands such as
@ -105,6 +106,7 @@ static int check_updates(struct unpack_trees_options *o)
cnt = 0;
}
git_attr_set_direction(GIT_ATTR_CHECKOUT, &o->result);
for (i = 0; i < index->cache_nr; i++) {
struct cache_entry *ce = index->cache[i];
@ -130,6 +132,7 @@ static int check_updates(struct unpack_trees_options *o)
}
}
stop_progress(&progress);
git_attr_set_direction(GIT_ATTR_CHECKIN, NULL);
return errs != 0;
}