git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] [RFC][GSoC][PATCH] attr: use local repository state in read_attr

From
AJAyush Jha <kumarayushjha123@gmail.com>
Date
Feb 7, 2026, 11:40 UTC
Message-ID
<20260207114007.40-1-kumarayushjha123@gmail.com>

read_attr() currently relies on is_bare_repository(), which implicitly depends on the global the_repository.

As attr.c is a reusable library component used by multiple commands, this prevents correct behavior when operating on secondary repositories (e.g. submodules or in-process repos) whose bareness may differ from the_repository.

Update read_attr() to determine bareness using the repository associated with istate->repo, based on repository configuration and worktree presence, instead of relying on global state.

No functional change is intended for the primary repository case.
Signed-off-by: Ayush Jha <kumarayushjha123@gmail.com>
---
 attr.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/attr.c b/attr.c
index 4999b7e09d..f2d25b1863 100644
--- a/attr.c
+++ b/attr.c
@@ -848,21 +848,29 @@ static struct attr_stack *read_attr(struct index_state *istate,
 		res = read_attr_from_index(istate, path, flags);
 	} else if (tree_oid) {
 		res = read_attr_from_blob(istate, tree_oid, path, flags);
-	} else if (!is_bare_repository()) {
-		if (direction == GIT_ATTR_CHECKOUT) {
-			res = read_attr_from_index(istate, path, flags);
-			if (!res)
-				res = read_attr_from_file(path, flags);
-		} else if (direction == GIT_ATTR_CHECKIN) {
-			res = read_attr_from_file(path, flags);
-			if (!res)
-				/*
-				 * There is no checked out .gitattributes file
-				 * there, but we might have it in the index.
-				 * We allow operation in a sparsely checked out
-				 * work tree, so read from it.
-				 */
+	} else {
+		int is_bare;
+		int is_bare_cfg = -1;
+
+		repo_config_get_bool(istate->repo, "core.bare", &is_bare_cfg);
+		is_bare = is_bare_cfg && !repo_get_work_tree(istate->repo);
+
+		if (!is_bare) {
+			if (direction == GIT_ATTR_CHECKOUT) {
 				res = read_attr_from_index(istate, path, flags);
+				if (!res)
+					res = read_attr_from_file(path, flags);
+			} else if (direction == GIT_ATTR_CHECKIN) {
+				res = read_attr_from_file(path, flags);
+				if (!res)
+					/*
+					 * There is no checked out .gitattributes file
+					 * there, but we might have it in the index.
+					 * We allow operation in a sparsely checked out
+					 * work tree, so read from it.
+					 */
+					res = read_attr_from_index(istate, path, flags);
+			}
 		}
 	}
 
-- 
2.53.0.windows.1
Next: Tian Yuchen
Message 1 of 10 in “attr: use local repository state in read_attr”
  1. [RFC][GSoC][PATCH] attr: use local repository state in read_attrAyush Jha, Feb 7, 2026
  2. Tian YuchenFeb 7, 2026
  3. Lucas Seiki OshiroFeb 7, 2026
  4. Junio C HamanoFeb 7, 2026
  5. Tian YuchenFeb 8, 2026
  6. Ayush JhaFeb 10, 2026
  7. Lucas Seiki OshiroFeb 14, 2026
  8. Ayush JhaFeb 14, 2026
  9. Junio C HamanoFeb 10, 2026
  10. Tian YuchenFeb 11, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.