Article View: linux.kernel.git
Article #3131[GSoC Patch v9 1/5] repo: add path.workingtree with absolute and relative suffix formatting
From: K Jayatheerth
Date: Sat, 14 Nov 2026 16:37
Date: Sat, 14 Nov 2026 16:37
131 lines
15261 bytes
15261 bytes
Scripts frequently need to find the root directory of a repository's
working tree. Currently, this requires using `git rev-parse --show-toplevel`
or inferring it from other repository information.
Introduce `path.workingtree.absolute` and `path.workingtree.relative` keys
to `git repo info`. This allows scripts to retrieve the top-level
working tree path in a predictable, strictly formatted manner without
relying on `rev-parse`.
If requested in a bare repository where no working tree exists, the
command returns an empty string.
Mentored-by: Justin Tobler <jltobler@gmail.com>
Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
---
Documentation/git-repo.adoc | 10 ++++++++++
builtin/repo.c | 24 ++++++++++++++++++++++++
t/t1900-repo-info.sh | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 69 insertions(+)
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index ed7d80c690..82bcd8ad2e 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -119,6 +119,16 @@ values that they return:
`path.gitdir.relative`::
The path to the Git repository directory relative to the current working directory.
+`path.workingtree.absolute`::
+ The canonical absolute path to the top-level directory of the
+ repository's working tree. Outputs an empty string if the repository
+ is bare.
+
+`path.workingtree.relative`::
+ The path to the top-level directory of the repository's working
+ tree relative to the current working directory. Outputs an empty
+ string if the repository is bare.
+
`references.format`::
The reference storage format. The valid values are:
+
diff --git a/builtin/repo.c b/builtin/repo.c
index 84e012f83f..9ec8623a8e 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -121,6 +121,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)
return 0;
}
+static int get_path_workingtree_absolute(struct repository *repo, struct strbuf *buf)
+{
+ const char *work_tree = repo_get_work_tree(repo);
+
+ if (!work_tree)
+ return 0;
+
+ format_path(buf, work_tree, "", PATH_FORMAT_CANONICAL);
+ return 0;
+}
+
+static int get_path_workingtree_relative(struct repository *repo, struct strbuf *buf)
+{
+ const char *work_tree = repo_get_work_tree(repo);
+
+ if (!work_tree)
+ return 0;
+
+ format_path(buf, work_tree, repo->prefix, PATH_FORMAT_RELATIVE);
+ return 0;
+}
+
static int get_references_format(struct repository *repo, struct strbuf *buf)
{
strbuf_addstr(buf,
@@ -137,6 +159,8 @@ static const struct repo_info_field repo_info_field[] = {
{ "path.commondir.relative", get_path_commondir_relative },
{ "path.gitdir.absolute", get_path_gitdir_absolute },
{ "path.gitdir.relative", get_path_gitdir_relative },
+ { "path.workingtree.absolute", get_path_workingtree_absolute },
+ { "path.workingtree.relative", get_path_workingtree_relative },
{ "references.format", get_references_format },
};
diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
index c85d390f43..3225fc8583 100755
--- a/t/t1900-repo-info.sh
+++ b/t/t1900-repo-info.sh
@@ -213,4 +213,39 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
'.git' \
'GIT_DIR="../.git" && export GIT_DIR'
+test_expect_success 'path.workingtree absolute and relative' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ mkdir -p repo/sub &&
+ cd repo/sub &&
+
+ ROOT="$(test-tool path-utils real_path ..)" &&
+
+ echo "path.workingtree.absolute=$ROOT" >expect.abs &&
+ git repo info path.workingtree.absolute >actual.abs &&
+ test_cmp expect.abs actual.abs &&
+
+ echo "path.workingtree.relative=../" >expect.rel &&
+ git repo info path.workingtree.relative >actual.rel &&
+ test_cmp expect.rel actual.rel
+ )
+'
+
+test_expect_success 'path.workingtree absolute and relative in a bare repository' '
+ test_when_finished "rm -rf bare.git" &&
+ git init --bare bare.git &&
+ (
+ cd bare.git &&
+
+ echo "path.workingtree.absolute=" >expect.abs &&
+ git repo info path.workingtree.absolute >actual.abs &&
+ test_cmp expect.abs actual.abs &&
+
+ echo "path.workingtree.relative=" >expect.rel &&
+ git repo info path.workingtree.relative >actual.rel &&
+ test_cmp expect.rel actual.rel
+ )
+'
+
test_done
--
2.56.0-rc2
Technical Details
Message-ID:
<20261114163715.257705-2-jayatheerthkulkarni2005@gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-75452-linux-kernel-git=dewy.ruReferences:
<20260716012138.6714-1-jayatheerthkulkarni2005@gmail.com> <20261114163715.257705-1-jayatheerthkulkarni2005@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-75452-linux-kernel-git=dewy.ru
From: jayatheerthkulkarni2005@gmail.com (K Jayatheerth)
Newsgroups: linux.kernel.git
Subject: [GSoC Patch v9 1/5] repo: add path.workingtree with absolute and relative suffix formatting
Date: Sat, 14 Nov 2026 22:07:11 +0530
Organization: Usenet Network
Message-ID: <20261114163715.257705-2-jayatheerthkulkarni2005@gmail.com>
References: <20260716012138.6714-1-jayatheerthkulkarni2005@gmail.com>
<20261114163715.257705-1-jayatheerthkulkarni2005@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1613073"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:InGNt3YOlta+ndrCaA0PuEOe8Pw= sha256:LwuHfC8H/jEzsUBGXc09N+XRMXQOtkjGiQ0INUgxMuY=
sha1:5yQfzqUg06USGjVE749qK+pj0q8= sha256:IfECkXu6W8FiaatlVxwl7tgvtvxvQsuYTBVm9b9TcU8=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 58ECC114864; Sat, 14 Nov 2026 19:38:14 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.949
X-Spam-Status: No, score=-1.949 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 19csymJxMGSR;
Sat, 14 Nov 2026 19:38:11 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-75452-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id EC08F114870; Sat, 14 Nov 2026 19:38:00 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 1C4DD37F2C; Sat, 14 Nov 2026 16:37:57 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1794674275;
b=QV7hYH2ui/kFP++Hy9TY/EO2Smr5WKOYynAdqu9BAw3MvwnHDv35Iz5TH9nHFgmhNipT
ZzCeVIfoyOEG/VNNj2DghAIZsSoUIBmwJXAVo1Kzv3Ae/wyz00TTNVGU54ZxHRTl3iRs/
iiHdwPHsZO8toNm4RJoAt1Dx9S4Xfkc+fohktqaSXesrqZXOi/plgZr/CQd14+cyJSCOo
RNv8zRoTDg7GdLa7Pnp6W1tTw1HD1NY1Ve9fKtak9SgLydEO03Kyu354vcaywSH7nTMY9
X3noxJVVxNtjgjvSRtluL82H965v17N/x6+2C13N9ULP1T239tRXs2umjlrlzwcLL4Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794674275;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=x3j9JMRpQurM5MvB+O1Aa7WTVd97ug0p67PX7hXrmjo=;
b=HLNGXbJdp1tCF/2XFqbcsPstEJyKp2IYvUR1+hQHvfvjTTlUg/aP+KgJzGnVlj+EIXye
TSWchdLpmtm6eV4uU52h1T6wVNPVekGTTbn36oTnPjA5eVJDGgTNFU8QFGXb3TB3n/ZYv
xMhBRX0gPYzkHNruSIh5nraBPDptTqdw5o/jmdgJtNGDedxWgl3PiCbBkAhRmYeMaT/nR
UkdRureKaunbJUorThHI1HSEiBkWACjpXeH6Xg3XlPdJIZvEX0ppbf2P1uToaSG6z27EP
wZ7B0pON+NTOIjRF9012eGNS11/zbp7qsLXWxCL7JUXYK8MtVD3l/OPPyndKxXlVT8Q==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="iU/91DII";
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id BE8DF606A334;
Sat, 14 Nov 2026 16:37:55 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=iU/91DII
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.43
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794674274;
b=T77w4uTTWts+a9bzm2fEKgSsjl3wBBE9+vjx+vQJbUxAOjs69+w72/bbnUfTfQYroq0r
0jkfEFPNYbQHK32Eg2jvAlg/xkUiqZULliJaxNHYK9axptFwVDhw9pabc4HaUbKpjzz4l
JDbBkN+v58G7PHpPA7rlxJXH1oa3NU5RQmUma4chf/oECKfqQvY6vRw5+LTjwco6v6FQx
j6RlKEq7zCTgcQwzpQdHzY9bQ6FuhBEhPnQ58JASATykoIyX1lyfgdwqVzLAENRY5GyPa
uHSd0wlCFUOEngnTXMC1CXWSsnZpHIeNcBnlgPfD2uSa4yMfK9LR2BqBD5KluA91nng==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794674274;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
Content-Transfer-Encoding;
bh=x3j9JMRpQurM5MvB+O1Aa7WTVd97ug0p67PX7hXrmjo=;
b=xVFpaC8H71GMouVfJ1maDE+VIxdVe4/pwEUcYjY4g4GIIhnCgn5S8xkR1ZBnpUdQfqDB
bzTPomISYhoKnzbKMMmyTOcDtvdZ1JmfWV4TSxzmbmoOEQXVoJZgl48f0tDazapNKE0ao
OjIgkogdnWn9eIikYCTeAo3Py6it53Cvfnv2ylJYvTGqLhuTxPytEB/LIrI7ObOgAWXm5
n8YIjBySRtPmD7tfii4vlInuj+0rBJgIjx9KuGiTa/cWGXDYs52Dx8E9BqS1H9XqyQg2C
0OREL5ga35QaUvLKiV9rJJecDdwwGMhgiCqfIqsF0ArF5/uuqLh8NtEN+VPYTzIGWnA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="iU/91DII";
arc=none smtp.remote-ip=74.125.82.43
X-Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92F9C606A32D
for <git@vger.kernel.org>; Sat, 14 Nov 2026 16:37:54 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 92F9C606A32D
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-1aefd1bf74aso1514463c88.1
for <git@vger.kernel.org>; Sat, 14 Nov 2026 08:37:54 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794674274; x=1795279074; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=x3j9JMRpQurM5MvB+O1Aa7WTVd97ug0p67PX7hXrmjo=;
b=iU/91DIIO+dzeFGHC/O54NNnO3bgtvWj0u4xFaFiFmSL8NjACyHqAuimIAN87pnXJo
hna2e8YIaSBgZRuIIRb4vHU1cF3bPMeTVW3lhtTJotDiwg0gB+E2MD+vdXZksSRiueZC
wRKUNUNQvsunLGGLPDlZzQj+03P7TDTEi1fsqPJjDvwBIWo69MAtVdD3yijow8PfoB/x
VCTkVbFaSOP/dOVEc69RLiUI2FTaAMDtCHnVDVXBv2EkhcmMcFyiVrQaUXYOhsQ4h7Sp
Ww+1569dRL4rG+tLzkKz5+YjKEYru9Tmx1XsAKOajY6rjboJMheje756i9d1JEJUcD3T
NXKw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794674274; x=1795279074;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=x3j9JMRpQurM5MvB+O1Aa7WTVd97ug0p67PX7hXrmjo=;
b=BrtVB09QdTgWbI7UHLlR8eJlqkCMPmSMQfCfooDZX14xEaqUNm32RRyk7kWYxKG9vo
j8O2g9BsbJvUrTAhGn0KUVW5yzG/itokJwOaIt+ctup3S2gbcOGMtjDf4yak/kM40tRc
WFQ+3np3ovNpJmQVWBBvAYK1y6TnbOOUQFvci+a+LB7i+F0jVZblDx9FIOmHq2GuqQdw
EJ4QXumgtb+onuYMxCsdHdVsRcj5WoqWeRaO82MR3VSKtPsnPAPFNNng7pjOAfascZC1
wDl1k9nndw+iinu9enUW17w4UyzPlrwOqBgyA4H8mcIaXolw/qJZci5n+Hfpl6H4n4tN
uj5Q==
X-Gm-Message-State: APuU4Z8nGljhl+unVgQ2yQ1gqejszUnrLMPQdX6YGlMMEvSj2+FV1SJh
iZgTnCx8b4jqZ7xksVqBbXqv+v86LeS62D/IIW6BBe+SoR1k47C2K1Qt
X-Gm-Gg: AYBFou1lQeAufFGVyzE7X/tNtm3SOtc3/R4RfZjZ+53H6Zl7GRKXHW4wsj+Gov8igMu
ce/Smq5GlSViuE5pLQM5l/aO7CIKdJj4t/wk9JucD0Sj4nW8YzAno6qxn2er4Z6aH42cSP1dwuZ
WGgzpxSmKLYzm/q3coNT9OLHmFZsKga2OGnTs2bKXlQP4J8Tn+CgD9tw2XMbjqwVpt9Mrvh5ORL
de3Sty9kvxEODWQy6ZqoyqX+eID+YijBJCOMnA6f/qKhl/THKIKBEKX548tgLQ+jAm6ovfjnAPm
p+j0ep/jEUwzH8zQCZrZZgISrRpFibvdBx0njCx8iGnNoHcSzBgqaEr1eAp1zQqYwNV7CRiyVvg
IFoKH2gqjMtEnjBXXftKZeE+fI02+rF/02I6WxHXGceeVpPPbVPHJFTSy5+BWbFf4rhS8NIkjXP
FNVWiYMi2LU6EkRSWIJQLHzk1elqpCjq59BV3nqUHfRSOztM3pVXP8gp7Bx4u+MRQN5jgTa9X1L
DxTCzQSg+X6EsUX88BCSqB+XyB6bjAgifrhMCZLX7sy6jiRcBECRQ1kwLZZHZKgfn8mZDGE8HJh
3a0A4KE/FKMVnFVpzAvio7MQBYpgqh8ZeXUPPeUdeEeMaNOeQaA2iM2GKhvGUNOOo9W6EugBaXH
bZEOxYvrmPjzCvw0cmvZIjrqOgXdwCWvzm+y+ZYx8/JapC2C+2rBP7Oku
X-Received: by 2002:a05:7022:1182:b0:190:716:4822 with SMTP id a92af1059eb24-1b50308a4a0mr5060393c88.8.1794674273495;
Sat, 14 Nov 2026 08:37:53 -0800 (PST)
X-Received: from jayatheerth ([2405:201:c005:b959:7d42:d207:de10:1218])
by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5031b98e5sm18093657c88.14.2026.11.14.08.37.50
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sat, 14 Nov 2026 08:37:53 -0800 (PST)
X-Cc: git@vger.kernel.org,
jltobler@gmail.com,
lucasseikioshiro@gmail.com,
gitster@pobox.com,
phillip.wood@dunelm.org.uk
X-Mailer: git-send-email 2.56.0-rc2
X-In-Reply-To: <20261114163715.257705-1-jayatheerthkulkarni2005@gmail.com>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list