Skip to content

Commit 4537233

Browse files
committed
attr: be careful about sparse directories
Signed-off-by: Derrick Stolee <[email protected]>
1 parent 347410c commit 4537233

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

attr.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "utf8.h"
1515
#include "quote.h"
1616
#include "thread-utils.h"
17+
#include "dir.h"
1718

1819
const char git_attr__true[] = "(builtin)true";
1920
const char git_attr__false[] = "\0(builtin)false";
@@ -744,6 +745,19 @@ static struct attr_stack *read_attr_from_index(struct index_state *istate,
744745
if (!istate)
745746
return NULL;
746747

748+
/*
749+
* The .gitattributes file only applies to files within its
750+
* parent directory. In the case of cone-mode sparse-checkout,
751+
* the .gitattributes file is sparse if and only if all paths
752+
* within that directory are also sparse. Thus, don't load the
753+
* .gitattributes file since it will not matter.
754+
*
755+
* In the case of a sparse index, it is critical that we don't go
756+
* looking for a .gitattributes file, as the index will expand.
757+
*/
758+
if (!path_in_cone_modesparse_checkout(path, istate))
759+
return NULL;
760+
747761
buf = read_blob_data_from_index(istate, path, NULL);
748762
if (!buf)
749763
return NULL;

0 commit comments

Comments
 (0)