diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-10-30 01:09:55 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-10-30 01:09:55 +0300 |
commit | 26dd307cfaabe3d3f0b01aad64969e76a317811a (patch) | |
tree | 7f7f48e785ab297fe1718c5b954f7c6be71d9653 /attr.c | |
parent | 8183b63ff6a9c7eec5555e51e127e712efb64704 (diff) | |
parent | 9f9c40cf34c29d4ad700d9869435d159056fa6fb (diff) |
Merge branch 'jc/attr-tree-config'
The attribute subsystem learned to honor `attr.tree` configuration
that specifies which tree to read the .gitattributes files from.
* jc/attr-tree-config:
attr: add attr.tree for setting the treeish to read attributes from
attr: read attributes from HEAD when bare repo
Diffstat (limited to 'attr.c')
-rw-r--r-- | attr.c | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -7,7 +7,7 @@ */ #include "git-compat-util.h" -#include "parse.h" +#include "config.h" #include "environment.h" #include "exec-cmd.h" #include "attr.h" @@ -24,6 +24,8 @@ #include "tree-walk.h" #include "object-name.h" +const char *git_attr_tree; + const char git_attr__true[] = "(builtin)true"; const char git_attr__false[] = "\0(builtin)false"; static const char git_attr__unknown[] = "(builtin)unknown"; @@ -1194,6 +1196,7 @@ static void collect_some_attrs(struct index_state *istate, } static const char *default_attr_source_tree_object_name; +static int ignore_bad_attr_tree; void set_git_attr_source(const char *tree_object_name) { @@ -1205,10 +1208,24 @@ static void compute_default_attr_source(struct object_id *attr_source) if (!default_attr_source_tree_object_name) default_attr_source_tree_object_name = getenv(GIT_ATTR_SOURCE_ENVIRONMENT); + if (!default_attr_source_tree_object_name && git_attr_tree) { + default_attr_source_tree_object_name = git_attr_tree; + ignore_bad_attr_tree = 1; + } + + if (!default_attr_source_tree_object_name && + startup_info->have_repository && + is_bare_repository()) { + default_attr_source_tree_object_name = "HEAD"; + ignore_bad_attr_tree = 1; + } + if (!default_attr_source_tree_object_name || !is_null_oid(attr_source)) return; - if (repo_get_oid_treeish(the_repository, default_attr_source_tree_object_name, attr_source)) + if (repo_get_oid_treeish(the_repository, + default_attr_source_tree_object_name, + attr_source) && !ignore_bad_attr_tree) die(_("bad --attr-source or GIT_ATTR_SOURCE")); } |