Article View: linux.kernel.git
Article #2605[GSoC Patch v8 6/7] repo: add path.git-prefix
From: K Jayatheerth
Date: Sat, 07 Nov 2026 16:00
Date: Sat, 07 Nov 2026 16:00
100 lines
14237 bytes
14237 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.git-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 2240aae73e..c0d595cdc5 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -113,6 +113,11 @@ values that they return:
The path to the Git repository's common directory relative to
the current working directory.
+`path.git-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.gitdir.absolute`::
The canonical absolute path to the Git repository directory (the `.git` directory).
diff --git a/builtin/repo.c b/builtin/repo.c
index 859bd87617..0c63c0280f 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_git_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);
@@ -224,6 +234,7 @@ static const struct repo_info_field repo_info_field[] = {
{ "object.format", get_object_format },
{ "path.commondir.absolute", get_path_commondir_absolute },
{ "path.commondir.relative", get_path_commondir_relative },
+ { "path.git-prefix", get_path_git_prefix },
{ "path.gitdir.absolute", get_path_gitdir_absolute },
{ "path.gitdir.relative", get_path_gitdir_relative },
{ "path.hooks.absolute", get_path_hooks_absolute },
diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
index 140dfbe68a..b41fdeee77 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.git-prefix at repository root' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ echo "path.git-prefix=" >expect &&
+ git repo info path.git-prefix >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'path.git-prefix in subdirectory' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ mkdir -p repo/sub/dir &&
+ (
+ cd repo/sub/dir &&
+ echo "path.git-prefix=sub/dir/" >expect &&
+ git repo info path.git-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:
<20261107160100.122243-7-jayatheerthkulkarni2005@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74790-linux-kernel-git=dewy.ruReferences:
<20260716012138.6714-1-jayatheerthkulkarni2005@gmail.com> <20261107160100.122243-1-jayatheerthkulkarni2005@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74790-linux-kernel-git=dewy.ru
From: jayatheerthkulkarni2005@gmail.com (K Jayatheerth)
Newsgroups: linux.kernel.git
Subject: [GSoC Patch v8 6/7] repo: add path.git-prefix
Date: Sat, 7 Nov 2026 21:30:59 +0530
Organization: Usenet Network
Message-ID: <20261107160100.122243-7-jayatheerthkulkarni2005@gmail.com>
References: <20260716012138.6714-1-jayatheerthkulkarni2005@gmail.com>
<20261107160100.122243-1-jayatheerthkulkarni2005@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="4137826"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:l2ZfntRywWEzmB2bl+h2RdTjM80= sha256:IrLFN6Zx1URHasi94eXQ3+krHMrLzT3u0hXDYs0w/3Q=
sha1:EDsZxaIwya9Ny2CDXwk1UqC2BeI= sha256:GIGXVoUZaNP+1aXzUt88HuyQ8L8rzZrU4fa1f80G+8U=
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 3426411344D; Sat, 7 Nov 2026 19:11:44 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.148
X-Spam-Status: No, score=-3.148 tagged_above=-9999 required=6.31
tests=[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,
URIBL_BLOCKED=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 HqIYl0xgLqSf;
Sat, 7 Nov 2026 19:11:41 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-74790-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 34505113448; Sat, 7 Nov 2026 19:11:32 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id 06911640D1C; Sat, 7 Nov 2026 16:02:23 +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=1794067342;
b=ii985juvvGLhRoXwwwHulBRX2E7afcubUpCtAHRZycXcpJkipimNk9Mh8MmwUbclbnrn
r1tIevbdpszImknUNJgsTR70mf6ujvfn39BYnKtUmqCpRj2l2ji++iwnTcO3NRw8a6UmB
teY0WNgek2PB1HXXatHIByOIovonZEWbMvaK3s/UQ1NBl+jdBhjgHaeJwKAN1yKR26+ll
wR5sUoiX+sKgQqwlAaxl+t+BH1HGXKyXDIp5rRKsBJZGunSSqW88yHh0XXrqEaySDUEFS
43yzwhm3XSuS7Usni/bdDXim+RrVO1XFwgfzkuujnLTtH45doY5JtaPuoOkMXq7WCIQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794067342;
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=U+oXGv7Y+ed6sD9/D0FZxv5dUlrVnoj18y5q+Lqb9ZQ=;
b=fWKM3inhl9HgVTTaFgLSiAjGT89nxn0tHEzEhKbEfPIlx9QcZjpP2/TYWYAKlLD6ZTBL
YgF6c3yHoGCiGCCNwnHCXRguv/AmZIpSl+jOxQF8Cvg4MaI6i9yk1ynYUtgD74miFhvvT
XjCRsh1hlxN98X3FioGQXjV77B/om071KhokosgAE+xt/1HXj0jwHUwUNyMjALbQ4CINA
8k7ONs2fqNb2T2m8fNcncQcLtMj8Hu4wqgQuYss5lqvyk3fIb4NfzbHFY0PCrgSDjQw6t
7mcGA0AVU/r9PHEKRiB4ihpKV38FrVt/xO+uAgWrTgx7pbFjwWLEY8ZFk1lJep2nkDA==
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=lLXWpvsA;
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 0F6F2606A331;
Sat, 7 Nov 2026 16:02:22 +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=lLXWpvsA
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.50
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794067341;
b=hzWIe8vsFXkecXRuZuolLdzvamW4RkRLEgFgRvXuB3c/LF/mj4XyoVwP+ZecubQu5c7Y
1x383rVHdInb0L0y+qDJt98gcvIHvMkhhIYb33hSwn3HUUbT1WeRW4IvVBkHacKFpOu6d
siP3dbuCAFJKYYiJRMlz6y3aAuVIy8Acz8bg85E0Q14yCQgimbxQlHF6i/43qDf7K4k9y
y3RSXUhDU9cu8hk3qfnu2BThMABgrU6PWIE1oWli5QwaKpPaNdHMbhhPdIDOylodBQKZG
ZxlkrscRGS9GKsHDlLo1g1RwbMPT+3y3LDQeXislPMXaIvWfX6fYIz9DrRUn0hh+Nrw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794067341;
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=U+oXGv7Y+ed6sD9/D0FZxv5dUlrVnoj18y5q+Lqb9ZQ=;
b=J+eCdO9KPVCcwfnxvjD8ho2vv4siZM9rGbMnme1sKLTDwiPr663HAVz2iktoP+mDGd2+
H54Dhn6hu38rIvf9nkPt5moQSkh6cMseJhDp8PSSZ4rzRI06BLGmnzBteVNW+07DHN74D
CEg+y7SWs+ZHhU5P7j1jua+sLvm4Fo3N4g0W6NmQzpKXbO0hP4V7XG6YCC/GvpeFg/xAz
Yr3PWmwoM3Br2ZzP9sgkKKGbmlvNot6Um8EZT2gxdaDp1WNECz+tgORiZkITl06fCjLng
LWGx5Tqd5a4vbpYp53GozNfazLCF6zzu3iHp33g3dIKtux4J6xTZT7+UNWdfLNsUDyg==
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=lLXWpvsA;
arc=none smtp.remote-ip=74.125.82.50
X-Received: from mail-dl1-f50.google.com (mail-dl1-f50.google.com [74.125.82.50])
(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 D2F15606A326
for <git@vger.kernel.org>; Sat, 7 Nov 2026 16:02:20 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D2F15606A326
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-f50.google.com with SMTP id a92af1059eb24-1ae18eb9ad0so2042109c88.1
for <git@vger.kernel.org>; Sat, 07 Nov 2026 08:02:20 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794067340; x=1794672140; 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=U+oXGv7Y+ed6sD9/D0FZxv5dUlrVnoj18y5q+Lqb9ZQ=;
b=lLXWpvsAwBLq66jv6T2M3hj+rqZ8x1BfiXqVXoQjLIUPHh8q+iZpY9xvARgab6PVwU
HUo+xheuIwFNnjm1mdLX+yx8VOYoFNOt61BjSvQl4ZbGZjW5RuacHZxJxpATPCr54S3V
oebTieEKQpEvWbGD6lxHlTPw15/7rBLjtrmYhfl9EjiSnBqf2Pg6uQ2VH990YPzTygj6
d3yxH1sYWiEkeL3v0vnyK6yym18D97bdn/YaEhz8bDz5Co2TM5KotptJdbX1ZXiUggmr
efziCaitgbAxFN1czUoQFtRqHjM/9/MWtvCxwzAuH0pSB4wGQwGfvS/hKONkUgJRGqTF
b+qA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794067340; x=1794672140;
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=U+oXGv7Y+ed6sD9/D0FZxv5dUlrVnoj18y5q+Lqb9ZQ=;
b=vV5jIW/ZjUnfXzWmZmUK28awv9gA8iy2Snh5u+uOCbq9vLFGl9jh6ILTkCWXTFjjro
wDSTIAAabxn2IMNSrmW4W6/Iq17Erb6AnU73VliYxbrT1NgfUGcRQfYPEMCErLiDHWOR
SEXF0F8DaULTFUdHwh4EcotWIJvm+6xIjpKXpPxQ2DGQk/hCZPGBPf5I0K7gNoko0vWH
volB17cti0P/nZ1keruh/XLvgjem9R5v8Ord87SmQtT2l/MiEql5HP/1KBRYNPf7Upfw
jVp0Oz02PTTGBN1x0X0yfaei3Zc7186TtDs9j2tzj2/EJoi/VU/b9m2dBwdE9asaxSzv
D6AA==
X-Gm-Message-State: APuU4Z9NI70lhJXMaCQD2UimjHHufOK6XWsFW0EufuWxsTcSjzMx/bcr
+EuH9vs/BAlWHE25UW2pR+kWkETRYUstBKX/hszkCdgHJECYmvninMc6
X-Gm-Gg: AYBFou3Q9QQi4K6rQZSTOV26IHe9oN2eL6SrwpHCsLgF1xGlvRsZmjjcXiu3UQ3DYNa
BTFIWSnMUyZvnjCqim6OXZQjHnFxV01qg1TiWZPceMTmBTMwE3Hbtr9+B8h85XLSFVoscyDo5QZ
ABsMb3Qoj1O9EuxPvBwUzYzoEaxs87kQHi6+GHIdfKo+Co66q1uis3BXncMzf+0xMwfEclLyNdW
EX7FaEkFxCgfxbzO9xRdnYJUAHM7Mx37BHmll3zj59LTs7Oxo24Rep6keqqzT7l76UryLsQk+OJ
yyCCdNawjrPkhnmL5HMStCJILEI8UxvB9RS8OA87Y/lhaQZxZGWh++oDV9BJVRWF1cUL+7BTPOo
jCg5QiCCLSM7zpvgDtqrSrnV64V+Zn2kYKPfyEdQSOhvXvvfd8q1IOTIlLAWQ8JQ34WU/v/kAK9
6weWSahQCWf0MdNY2+w/fNqfiAGm4RKNSjVGK99kIvNWolDiyrkRKEwOZ+UAaqDHED4X/OlC/H9
XaXgeETVstzmSBQ/a3uzKmgrpiziWkbT6fqr9BlZD/qJDycxl1but28iQE67oTmTo/Eo3Pgvy/M
TAhfaDPeLVbo1QQM7d4gq2PWl8pvl/SdJoe4X5frN9b5VYNEEsmEsRMtrJhmZ9j4n4nxX63DNtr
21WWQEmZGN2UkWrBg21ulg2XkxK5clUnAdFgxRBlUfyzR6Gt7AdoIfRVI
X-Received: by 2002:a05:7023:a86:b0:1b2:557a:aa12 with SMTP id a92af1059eb24-1b25d315d44mr9390513c88.15.1794067339822;
Sat, 07 Nov 2026 08:02:19 -0800 (PST)
X-Received: from jayatheerth ([2405:201:c005:b959:7d42:d207:de10:1218])
by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b25e4a5628sm16264618c88.10.2026.11.07.08.02.17
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sat, 07 Nov 2026 08:02:19 -0800 (PST)
X-Cc: git@vger.kernel.org,
jltobler@gmail.com,
lucasseikioshiro@gmail.com
X-Mailer: git-send-email 2.56.0-rc2
X-In-Reply-To: <20261107160100.122243-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