Skip to content

Commit

Permalink
attr: be careful about sparse directories
Browse files Browse the repository at this point in the history
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee committed Aug 24, 2021
1 parent 347410c commit 4537233
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "utf8.h"
#include "quote.h"
#include "thread-utils.h"
#include "dir.h"

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

/*
* The .gitattributes file only applies to files within its
* parent directory. In the case of cone-mode sparse-checkout,
* the .gitattributes file is sparse if and only if all paths
* within that directory are also sparse. Thus, don't load the
* .gitattributes file since it will not matter.
*
* In the case of a sparse index, it is critical that we don't go
* looking for a .gitattributes file, as the index will expand.
*/
if (!path_in_cone_modesparse_checkout(path, istate))
return NULL;

buf = read_blob_data_from_index(istate, path, NULL);
if (!buf)
return NULL;
Expand Down

0 comments on commit 4537233

Please sign in to comment.