Skip to content

Commit f0f27c1

Browse files
committed
filter: optionally read attributes from repository
When `GIT_FILTER_ATTRIBUTES_FROM_HEAD` is specified, configure the filter to read filter attributes from `gitattributes` files that are checked in to the repository at the HEAD revision. This passes the flag `GIT_ATTR_CHECK_INCLUDE_HEAD` to the attribute reading functions.
1 parent 4fd5748 commit f0f27c1

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

include/git2/filter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ typedef enum {
4646

4747
/** Don't load `/etc/gitattributes` (or the system equivalent) */
4848
GIT_FILTER_NO_SYSTEM_ATTRIBUTES = (1u << 1),
49+
50+
/** Load attributes from `.gitattributes` in the root of HEAD */
51+
GIT_FILTER_ATTRIBUTES_FROM_HEAD = (1u << 2),
4952
} git_filter_flag_t;
5053

5154
/**

src/filter.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ static int filter_list_check_attributes(
438438
if ((src->flags & GIT_FILTER_NO_SYSTEM_ATTRIBUTES) != 0)
439439
flags |= GIT_ATTR_CHECK_NO_SYSTEM;
440440

441+
if ((src->flags & GIT_FILTER_ATTRIBUTES_FROM_HEAD) != 0)
442+
flags |= GIT_ATTR_CHECK_INCLUDE_HEAD;
443+
441444
error = git_attr_get_many_with_session(
442445
strs, repo, attr_session, flags, src->path, fdef->nattrs, fdef->attrs);
443446

0 commit comments

Comments
 (0)