git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 16:11 UTC

[PATCH 3/4] repo: add the --format-path flag

From
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Date
Feb 28, 2026, 22:05 UTC
Message-ID
<20260228224252.72788-4-lucasseikioshiro@gmail.com>
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)
Previous: Lucas Seiki OshiroNext: Lucas Seiki Oshiro
Message 4 of 26 in “repo: add support for path-related fields”
  1. 0/4 repo: add support for path-related fieldsLucas Seiki Oshiro, Feb 28, 2026
  2. 1/4 rev-parse: prepend `path_` to path-related enumsLucas Seiki Oshiro, Feb 28, 2026
  3. 2/4 path: add new function strbuf_add_pathLucas Seiki Oshiro, Feb 28, 2026
  4. 3/4 repo: add the --format-path flagLucas Seiki Oshiro, Feb 28, 2026
  5. 4/4 repo: add the field path.toplevelLucas Seiki Oshiro, Feb 28, 2026
  6. JAYATHEERTH KMar 1, 2026
  7. Tian YuchenMar 1, 2026
  8. Ayush JhaMar 1, 2026
  9. JAYATHEERTH KMar 1, 2026
  10. Phillip WoodMar 1, 2026
  11. Lucas Seiki OshiroMar 1, 2026
  12. Lucas Seiki OshiroMar 1, 2026
  13. Lucas Seiki OshiroMar 1, 2026
  14. Lucas Seiki OshiroMar 1, 2026
  15. brian m. carlsonMar 1, 2026
  16. Tian YuchenMar 2, 2026
  17. Junio C HamanoMar 2, 2026
  18. Tian YuchenMar 2, 2026
  19. Junio C HamanoMar 2, 2026
  20. JAYATHEERTH KMar 3, 2026
  21. Ayush JhaMar 3, 2026
  22. Tian YuchenMar 3, 2026
  23. JAYATHEERTH KMar 3, 2026
  24. Tian YuchenMar 3, 2026
  25. JAYATHEERTH KMar 3, 2026
  26. Lucas Seiki OshiroMar 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.