filter: add GIT_FILTER_NO_SYSTEM_ATTRIBUTES option Allow system-wide attributes (the ones specified in `/etc/gitattributes`) to be ignored if the flag `GIT_FILTER_NO_SYSTEM_ATTRIBUTES` is specified.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/include/git2/filter.h b/include/git2/filter.h
index b81b25e..a18f071 100644
--- a/include/git2/filter.h
+++ b/include/git2/filter.h
@@ -43,6 +43,9 @@ typedef enum {
/** Don't error for `safecrlf` violations, allow them to continue. */
GIT_FILTER_ALLOW_UNSAFE = (1u << 0),
+
+ /** Don't load `/etc/gitattributes` (or the system equivalent) */
+ GIT_FILTER_NO_SYSTEM_ATTRIBUTES = (1u << 1),
} git_filter_flag_t;
/**
diff --git a/src/filter.c b/src/filter.c
index 6c929c0..c2f7603 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -428,13 +428,18 @@ static int filter_list_check_attributes(
git_filter_def *fdef,
const git_filter_source *src)
{
- int error;
- size_t i;
const char **strs = git__calloc(fdef->nattrs, sizeof(const char *));
+ uint32_t flags = 0;
+ size_t i;
+ int error;
+
GIT_ERROR_CHECK_ALLOC(strs);
+ if ((src->flags & GIT_FILTER_NO_SYSTEM_ATTRIBUTES) != 0)
+ flags |= GIT_ATTR_CHECK_NO_SYSTEM;
+
error = git_attr_get_many_with_session(
- strs, repo, attr_session, 0, src->path, fdef->nattrs, fdef->attrs);
+ strs, repo, attr_session, flags, src->path, fdef->nattrs, fdef->attrs);
/* if no values were found but no matches are needed, it's okay! */
if (error == GIT_ENOTFOUND && !fdef->nmatches) {