public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [RFC][GSoC][PATCH] attr: use local repository state in read_attr
@ 2026-02-07 11:40 Ayush Jha
  2026-02-07 19:12 ` Tian Yuchen
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Ayush Jha @ 2026-02-07 11:40 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Christian Couder, Karthik Nayak, Justin Tobler,
	Ayush Chandekar, Siddharth Asthana, Lucas Seiki Oshiro, Ayush Jha

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-02-14  6:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-07 11:40 [PATCH] [RFC][GSoC][PATCH] attr: use local repository state in read_attr Ayush Jha
2026-02-07 19:12 ` Tian Yuchen
2026-02-07 21:02 ` Lucas Seiki Oshiro
2026-02-07 21:41   ` Junio C Hamano
2026-02-08  4:42 ` Tian Yuchen
2026-02-10 14:05   ` Ayush Jha
2026-02-14  0:04     ` Lucas Seiki Oshiro
2026-02-14  6:47       ` Ayush Jha
2026-02-10 23:37   ` Junio C Hamano
2026-02-11 16:43     ` Tian Yuchen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox