Article View: linux.kernel.git
Article #3135[GSoC Patch v9 5/5] repo: add path.prefix
From: K Jayatheerth
Date: Sat, 14 Nov 2026 16:37
Date: Sat, 14 Nov 2026 16:37
100 lines
14369 bytes
14369 bytes
Scripts sometimes need the path from the repository's working tree root
to the current working directory. While this information can be derived
through existing Git commands, `git repo info` does not currently expose
it as a scriptable key.
Introduce the `path.prefix` key to `git repo info`. The key returns
the path from the working tree root to the current working directory,
returning the empty string when invoked from the working tree root.
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 | 5 +++++
builtin/repo.c | 11 +++++++++++
t/t1900-repo-info.sh | 23 +++++++++++++++++++++++
3 files changed, 39 insertions(+)
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index c515e9372f..17992c7a67 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -131,6 +131,11 @@ values that they return:
Returns the configured index path even if the repository is bare or the
file does not exist.
+`path.prefix`::
+ The path from the root of the working tree to the current working
+ directory. Returns the empty string when the current working directory
+ is the root of the working tree.
+
`path.superprojectworkingtree.absolute`::
The canonical absolute path to the working tree root of the superproject
if the current repository is an initialized submodule. Outputs an empty
diff --git a/builtin/repo.c b/builtin/repo.c
index eeaee98c75..87c5743246 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -100,6 +100,16 @@ static int get_path_commondir_relative(struct repository *repo, struct strbuf *b
return 0;
}
+static int get_path_prefix(struct repository *repo, struct strbuf *buf)
+{
+ /*
+ * repo->prefix is NULL when the current working directory is
+ * the worktree root.
+ */
+ strbuf_addstr(buf, repo->prefix ? repo->prefix : "");
+ return 0;
+}
+
static int get_path_gitdir_absolute(struct repository *repo, struct strbuf *buf)
{
const char *git_dir = repo_get_git_dir(repo);
@@ -200,6 +210,7 @@ static const struct repo_info_field repo_info_field[] = {
{ "path.gitdir.relative", get_path_gitdir_relative },
{ "path.index.absolute", get_path_index_absolute },
{ "path.index.relative", get_path_index_relative },
+ { "path.prefix", get_path_prefix },
{ "path.superprojectworkingtree.absolute", get_path_superprojectworkingtree_absolute },
{ "path.superprojectworkingtree.relative", get_path_superprojectworkingtree_relative },
{ "path.workingtree.absolute", get_path_workingtree_absolute },
diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
index 46c92d4e43..d0631a8f3b 100755
--- a/t/t1900-repo-info.sh
+++ b/t/t1900-repo-info.sh
@@ -207,6 +207,29 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \
'.git' \
'GIT_DIR="../.git" && export GIT_DIR'
+test_expect_success 'path.prefix at repository root' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ echo "path.prefix=" >expect &&
+ git repo info path.prefix >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'path.prefix in subdirectory' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ mkdir -p repo/sub/dir &&
+ (
+ cd repo/sub/dir &&
+ echo "path.prefix=sub/dir/" >expect &&
+ git repo info path.prefix >actual &&
+ test_cmp expect actual
+ )
+'
+
test_repo_info_path 'gitdir standard' 'gitdir' '.git'
test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
--
2.56.0-rc2
Technical Details
Message-ID:
<20261114163715.257705-6-jayatheerthkulkarni2005@gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-75456-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!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-75456-linux-kernel-git=dewy.ru
From: jayatheerthkulkarni2005@gmail.com (K Jayatheerth)
Newsgroups: linux.kernel.git
Subject: [GSoC Patch v9 5/5] repo: add path.prefix
Date: Sat, 14 Nov 2026 22:07:15 +0530
Organization: Usenet Network
Message-ID: <20261114163715.257705-6-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="1613285"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Ljld7WpEsilPSC/OzzX2J8IFr04= sha256:nJa2tVuRF9b6K9WCpHFsA556hiLzSC35H5fZoTYbt30=
sha1:wPZXrecURprN1G85cexsX22VNWM= sha256:DZ59O7+EBbNVvmBtLodS5DoIzUX+74KE7fpRydMC/qY=
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 ACD8B114876; Sat, 14 Nov 2026 19:38:38 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[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 gyitH-x6YKgs;
Sat, 14 Nov 2026 19:38:29 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-75456-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 137E3114870; Sat, 14 Nov 2026 19:38:21 +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 590E438D18; Sat, 14 Nov 2026 16:38:16 +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=1794674295;
b=U/xoFj3zb671qz5uU/tPnxHtSk1BB/UBQRa65xgW4LDEe99ifL+yu6RICZttmQemyqQv
lAR9PHW42u+WsHYFZHuWv40i0bA3Zb2/jNCENElM5NthnRlkjOMcJc9or+tHasvxIrSNt
9UcwwE1/3Qlex9DbUlKQFB9eu5Ic1Yl31XhI9zuuVL8zQm4EAahpbocCefdp/afU3joiZ
tkXCZizFsq9KbAwud62r40HnY4TmCkeDstYWHEf/8cQ3GoRcLLY/mRe7zdS/I+QcDCwe9
4CDtdABnPRcONdR9MLLqZxI6dWvXEBS/Z64zIUuBzpuIcLhkEmC/+zXPyMvi19HJaJw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794674295;
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=fEMbYxerSEurGLTd07nUesnyH9LDtbvpW3haxy5h8+g=;
b=x3kyWxvdMrip496+eTDIVrV4OC5ToyQXawYc7ntDBWSu27sYSKmFyPacSeFaSyoMp/Rt
9MdUta8MKEACv8gnuKqhWT1RWZnEHgzTdlQpLPhk+Moq+IKPmd//rwQubdkttz30n1V6k
Xl5+dTXjp46IpsGcUzk530I2HRBCADHbMwdQnpygBz9Xe8BrWnd51H0oOsIkyU49lSSaJ
Gbo1+KU2jf/C1IRqdAdViWOznA6zLqHQjTqwl/+9MGsfBQPszXrFLam8kZKFr0aR6QUnz
IQ1huh0TFcJfrQVqa5Kye26vCcn74S3y+GHpNx6TL5iJqKdwyheAsop5dyjxgR940jA==
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=Xm4UbrQM;
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 9B670606A32D;
Sat, 14 Nov 2026 16:38:15 +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=Xm4UbrQM
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.51
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794674294;
b=hOFkNcv1Bb62ehrzuus8OmPiV8/JgINoFFILWeIHSz4f3+KBO32aVsnB++rC7fj8SB09
57UxtDdvz7lslSvpwmU77qyz7urTWp+F4zJkeoV+WdA9+M+g8KRoUmrDvcwJJDhtt6wRL
32C06FisSWOSzkJIi/y1hMeuZJH7S57S7EhC34ZD50g5s78Pvk11+8sMpJhLlPq8z2KbL
4NdUjiMp7CsqjhPgX8RvKw81i2mMHa90RhrdhqsH2l1Bh3VesUbXpGjvHLox7IVM/aRoF
PQMSeQVskwqJnjS1u1mJ0meNyCXKC2fNGB/Q7+EQQ/HAphRWChA6onY4pSLY37xEkDw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794674294;
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=fEMbYxerSEurGLTd07nUesnyH9LDtbvpW3haxy5h8+g=;
b=4Fg+zpHD3OZC24OFMISEXf2HIfYnH8oOoB+x15qZBMSR3vV9n2pR3XsKkCZdQsMc2RPx
usNIEidWT8nd4o4wBWfheJmvF2pGEJGyhxiJ5JCSclBv5Cott5SV7dYBT0Th4Hm2ijvh3
j2cSZ1VU5KCQZJqgfv5LHLBRpBgAeWNbdtIdKQXMLWzkbriSpJPSxq6E27vktT3snqUAh
8Nrh/0pcitzYX+pvJDM1rlfAn40sgd0v8htPixIWuqIa17qLTTMmZHxyLPQyuMEPmlwwB
Grf/SSUBikTu2WClIzbbYEdvmaY9S1ggBuSTdGbMp09iPqwsDOhWxHINRfqxG9VpPBQ==
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=Xm4UbrQM;
arc=none smtp.remote-ip=74.125.82.51
X-Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51])
(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 6C13C606A32E
for <git@vger.kernel.org>; Sat, 14 Nov 2026 16:38:14 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6C13C606A32E
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-f51.google.com with SMTP id a92af1059eb24-1b3acec6677so2702135c88.1
for <git@vger.kernel.org>; Sat, 14 Nov 2026 08:38:14 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794674294; x=1795279094; 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=fEMbYxerSEurGLTd07nUesnyH9LDtbvpW3haxy5h8+g=;
b=Xm4UbrQM0BKAOKHYjzG7dFOEKx923uTWYJU++VeyKW9qkUN7aHfreVW2Zt3X/NGpdA
+1bP+EWVIs/TiF8gzv/CQdz99blZTaDn3E5I8WFs1Gns+PFgGK9nCr31ElPN9FrACDpE
QbxUfhhWRyisqoPSjYlRayDEi2snhVkyY9PMeuNpPl2J3C/r8DfBJCcrEhnN6EvPAYvk
InofSNsfrJDFdxHQ8izVXhP8IyoKmReRUH20FnNPfeLRXXgL3UFA1vaNejzd7NHdMBxW
is+ABVadqm+XSFkpcUxQR3lblnFpgrX7i186viCHv7fK/vf79Ehbg2u3iWQB8pVU5PGy
8EcQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794674294; x=1795279094;
h=content-transfer-encoding:mime-version:references:in-reply-to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0qqzpq3PHxTYMPXySZ1fEmt2ioz1oUkQBwI9Pc/r/pTvM9TlPRxUNJMYVRrCNQcI1
erAfkhWEa7sb64r3g/kUXT8izlOgtB80P/LgNk6fh8kbIh7sd+g71ODwq95zzpN6aNYr4K8bQPd
J8vGALF6xAOp6BFNPqC4eIqxCo/10mg8OyKd8pjjAPrctGHc33LziXK1x59/FoS9XXFxaEbxCTr
Y3vxPKNwEj+QK7ThkZFKDvLYlGlNoHmuQua0=
X-Received: by 2002:a05:7022:371a:b0:144:fd7c:84fe with SMTP id a92af1059eb24-1b50313d82fmr5942003c88.35.1794674293541;
Sat, 14 Nov 2026 08:38:13 -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.38.10
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sat, 14 Nov 2026 08:38:13 -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