summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-07-21 14:13:25 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2019-08-11 20:47:59 +0100
commitf0f27c1c2b2bf875a6d86c24f8564580732f55c6 (patch)
treec35450b025335342b281a64b697618aee4485f4c
parent4fd5748c4bbc0fba3db9fb2fb20e01261339b9d9 (diff)
downloadlibgit2-f0f27c1c2b2bf875a6d86c24f8564580732f55c6.tar.gz
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.
-rw-r--r--include/git2/filter.h3
-rw-r--r--src/filter.c3
2 files changed, 6 insertions, 0 deletions
diff --git a/include/git2/filter.h b/include/git2/filter.h
index a18f071ec..886059051 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 c2f76039e..7b7e7f172 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);