From: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
To: git@vger.kernel.org
Cc: sandals@crustytoothpaste.net, kumarayushjha123@gmail.com,
a3205153416@gmail.com, jayatheerthkulkarni2005@gmail.com,
valusoutrik@gmail.com, pushkarkumarsingh1970@gmail.com,
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Subject: [PATCH 3/4] repo: add the --format-path flag
Date: Sat, 28 Feb 2026 19:05:57 -0300 [thread overview]
Message-ID: <20260228224252.72788-4-lucasseikioshiro@gmail.com> (raw)
In-Reply-To: <20260228224252.72788-1-lucasseikioshiro@gmail.com>
Some paths handled by Git are better presented in their absolute format
and others are better presented relative to the current working
directory.
Add a `--format-path` flag to git-repo-info, allowing the user to force
the outputted paths to be either in the absolute or in the relative
format. This flag is similar to its homonymous in git-rev-parse, introduced in
fac60b8925 (rev-parse: add option for absolute or relative path
formatting, 2020-12-13).
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
Documentation/git-repo.adoc | 8 ++++++--
builtin/repo.c | 24 +++++++++++++++++++-----
t/t1900-repo-info.sh | 7 +++++++
3 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 5e2968b707..478737b8ff 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
SYNOPSIS
--------
[synopsis]
-git repo info [--format=(lines|nul) | -z] [--all | <key>...]
+git repo info [--format=(lines|nul) | -z] [--path-format=(absolute|relative)] [--all | <key>...]
git repo info --keys [--format=(lines|nul) | -z]
git repo structure [--format=(table|lines|nul) | -z]
@@ -20,7 +20,7 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
COMMANDS
--------
-`info [--format=(lines|nul) | -z] [--all | <key>...]`::
+`info [--format=(lines|nul) | -z] [--path-format=(absolute|relative)] [--all | <key>...]`::
Retrieve metadata-related information about the current repository. Only
the requested data will be returned based on their keys (see "INFO KEYS"
section below).
@@ -45,6 +45,10 @@ supported:
`lines`. Unlike in the `lines` format, the values are never quoted.
+
`-z` is an alias for `--format=nul`.
++
+By default, the path values may be in the absolute or relative path, depending
+on the requested keys. However, the format can be forced by using the flag
+`--path-format`.
`info --keys [--format=(lines|nul) | -z]`::
List all the available keys, one per line. The output format can be chosen
diff --git a/builtin/repo.c b/builtin/repo.c
index f943be7451..cff4c6db9b 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -7,17 +7,16 @@
#include "parse-options.h"
#include "path-walk.h"
#include "progress.h"
+#include "path.h"
#include "quote.h"
#include "ref-filter.h"
#include "refs.h"
#include "revision.h"
-#include "strbuf.h"
-#include "string-list.h"
#include "shallow.h"
#include "utf8.h"
static const char *const repo_usage[] = {
- "git repo info [--format=(lines|nul) | -z] [--all | <key>...]",
+ "git repo info [--format=(lines|nul) | -z] [--path-format=(absolute|relative)] [--all | <key>...]",
"git repo info --keys [--format=(lines|nul) | -z]",
"git repo structure [--format=(table|lines|nul) | -z]",
NULL
@@ -109,7 +108,8 @@ static void print_field(enum output_format format, const char *key,
static int print_fields(int argc, const char **argv,
struct repository *repo,
- enum output_format format)
+ enum output_format format,
+ enum path_format_type path_format UNUSED)
{
int ret = 0;
struct strbuf valbuf = STRBUF_INIT;
@@ -197,6 +197,9 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
enum output_format format = FORMAT_NEWLINE_TERMINATED;
int all_keys = 0;
int show_keys = 0;
+ const char *path_format_str = NULL;
+ enum path_format_type path_format = PATH_FORMAT_DEFAULT;
+
struct option options[] = {
OPT_CALLBACK_F(0, "format", &format, N_("format"),
N_("output format"),
@@ -207,6 +210,8 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
parse_format_cb),
OPT_BOOL(0, "all", &all_keys, N_("print all keys/values")),
OPT_BOOL(0, "keys", &show_keys, N_("show keys")),
+ OPT_STRING(0, "path-format", &path_format_str,
+ N_("path-format"), N_("path format")),
OPT_END()
};
@@ -221,13 +226,22 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
if (format != FORMAT_NEWLINE_TERMINATED && format != FORMAT_NUL_TERMINATED)
die(_("unsupported output format"));
+ if (path_format_str) {
+ if (!strcmp(path_format_str, "absolute"))
+ path_format = PATH_FORMAT_CANONICAL;
+ else if (!strcmp(path_format_str, "relative"))
+ path_format = PATH_FORMAT_RELATIVE;
+ else
+ die(_("invalid path format '%s'"), path_format_str);
+ }
+
if (all_keys && argc)
die(_("--all and <key> cannot be used together"));
if (all_keys)
return print_all_fields(repo, format);
else
- return print_fields(argc, argv, repo, format);
+ return print_fields(argc, argv, repo, format, path_format);
}
struct ref_stats {
diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
index a9eb07abe8..f5c76067cb 100755
--- a/t/t1900-repo-info.sh
+++ b/t/t1900-repo-info.sh
@@ -149,4 +149,11 @@ test_expect_success 'git repo info --keys uses lines as its default output forma
test_cmp expect actual
'
+test_expect_success 'git-repo-info aborts when requesting an invalid path format' '
+ test_when_finished "rm -f err expected" &&
+ echo "fatal: invalid path format '\'foo\''" >expected &&
+ test_must_fail git repo info --path-format=foo 2>err &&
+ test_cmp expected err
+'
+
test_done
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-02-28 22:44 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-28 22:05 [PATCH 0/4] repo: add support for path-related fields Lucas Seiki Oshiro
2026-02-28 22:05 ` [PATCH 1/4] rev-parse: prepend `path_` to path-related enums Lucas Seiki Oshiro
2026-02-28 22:05 ` [PATCH 2/4] path: add new function strbuf_add_path Lucas Seiki Oshiro
2026-02-28 22:05 ` Lucas Seiki Oshiro [this message]
2026-02-28 22:05 ` [PATCH 4/4] repo: add the field path.toplevel Lucas Seiki Oshiro
2026-03-01 4:24 ` Tian Yuchen
2026-03-01 20:21 ` Lucas Seiki Oshiro
2026-03-02 4:54 ` Tian Yuchen
2026-03-01 2:58 ` [PATCH 0/4] repo: add support for path-related fields JAYATHEERTH K
2026-03-01 5:45 ` Ayush Jha
2026-03-01 6:50 ` JAYATHEERTH K
2026-03-01 19:55 ` Lucas Seiki Oshiro
2026-03-03 3:27 ` Ayush Jha
2026-03-01 19:49 ` Lucas Seiki Oshiro
2026-03-01 10:44 ` Phillip Wood
2026-03-01 19:40 ` Lucas Seiki Oshiro
2026-03-01 21:25 ` brian m. carlson
2026-03-02 16:38 ` Junio C Hamano
2026-03-02 18:51 ` Tian Yuchen
2026-03-02 21:34 ` Junio C Hamano
2026-03-03 2:48 ` JAYATHEERTH K
2026-03-03 4:32 ` Tian Yuchen
2026-03-03 7:23 ` JAYATHEERTH K
2026-03-03 9:28 ` Tian Yuchen
2026-03-03 10:31 ` JAYATHEERTH K
2026-03-08 0:29 ` Lucas Seiki Oshiro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260228224252.72788-4-lucasseikioshiro@gmail.com \
--to=lucasseikioshiro@gmail.com \
--cc=a3205153416@gmail.com \
--cc=git@vger.kernel.org \
--cc=jayatheerthkulkarni2005@gmail.com \
--cc=kumarayushjha123@gmail.com \
--cc=pushkarkumarsingh1970@gmail.com \
--cc=sandals@crustytoothpaste.net \
--cc=valusoutrik@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox