Commit f0f27c1c2b2bf875a6d86c24f8564580732f55c6

Edward Thomson 2019-07-21T14:13:25

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.

diff --git a/include/git2/filter.h b/include/git2/filter.h
index a18f071..8860590 100644
--- a/include/git2/filter.h
+++ b/include/git2/filter.h
@@ -46,6 +46,9 @@ typedef enum {
 
 	/** Don't load `/etc/gitattributes` (or the system equivalent) */
 	GIT_FILTER_NO_SYSTEM_ATTRIBUTES = (1u << 1),
+
+	/** Load attributes from `.gitattributes` in the root of HEAD */
+	GIT_FILTER_ATTRIBUTES_FROM_HEAD = (1u << 2),
 } git_filter_flag_t;
 
 /**
diff --git a/src/filter.c b/src/filter.c
index c2f7603..7b7e7f1 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -438,6 +438,9 @@ static int filter_list_check_attributes(
 	if ((src->flags & GIT_FILTER_NO_SYSTEM_ATTRIBUTES) != 0)
 		flags |= GIT_ATTR_CHECK_NO_SYSTEM;
 
+	if ((src->flags & GIT_FILTER_ATTRIBUTES_FROM_HEAD) != 0)
+		flags |= GIT_ATTR_CHECK_INCLUDE_HEAD;
+
 	error = git_attr_get_many_with_session(
 		strs, repo, attr_session, flags, src->path, fdef->nattrs, fdef->attrs);