Thread (82 messages) 82 messages, 6 authors, 3d ago
WARM3d

[GSoC Patch v5 0/4] teach git repo info to handle path keys

From: K Jayatheerth <hidden>
Date: 2026-06-16 04:50:53

Hi!

This series teaches `git repo info` to handle `path.*`
keys, allowing scripts to reliably discover core
repository paths without resorting to `git rev-parse`.

The patches are structured as follows:

1. path: Extract the localized path-formatting logic
   out of `rev-parse` and expose it globally via
   `path.h` using clear append semantics.

2. rev-parse: Refactor the command to leverage the
   newly shared path engine.

3. repo: Introduce `path.commondir.absolute` and
   `path.commondir.relative` alongside a robust,
   isolated test helper.

4. repo: Introduce `path.gitdir.absolute` and
   `path.gitdir.relative` using the same standardized
   formatting rules.

changes since v4:
* Simplified the `test_repo_info_path` helper by dropping the `repo_name` 
  argument and utilizing `test_when_finished "rm -rf repo"` to handle 
  repository setup/teardown inline. This ensures perfect test isolation.
* Condensed the redundant `expect_absolute_suffix` and `expect_relative` 
  test helper arguments into a single `expected_dir` argument, reducing 
  the helper signature to 4 arguments (Justin).
* Added a contextual comment in `builtin/rev-parse.c`'s `print_path()` 
  explaining why `PATH_FORMAT_DEFAULT` is intercepted and overridden with 
  a path-specific fallback (Justin).
* Trimmed the verbose test helper explanations from the commit messages 
  in patches 3 and 4.

K Jayatheerth (4):
  path: introduce append_formatted_path() for shared path formatting
  rev-parse: use append_formatted_path() for path formatting
  repo: add path.commondir with absolute and relative suffix formatting
  repo: add path.gitdir with absolute and relative suffix formatting

 Documentation/git-repo.adoc |  15 ++++++
 builtin/repo.c              |  50 +++++++++++++++++
 builtin/rev-parse.c         | 104 +++++++++---------------------------
 path.c                      |  70 ++++++++++++++++++++++++
 path.h                      |  36 +++++++++++++
 t/t1900-repo-info.sh        |  58 ++++++++++++++++++++
 6 files changed, 253 insertions(+), 80 deletions(-)

Range-diff against v4:
1:  a396b4f8e6 = 1:  a396b4f8e6 path: introduce append_formatted_path() for shared path formatting
2:  16198f96d1 ! 2:  16b42a51d2 rev-parse: use append_formatted_path() for path formatting
    @@ builtin/rev-parse.c: static void handle_ref_opt(const char *pattern, const char
     -	}
     -	free(cwd);
     +	struct strbuf sb = STRBUF_INIT;
    ++	/* If the user didn't explicitly specify a format, fallback to the path-specific default. */
     +	enum path_format fmt = (arg_path_format != PATH_FORMAT_DEFAULT) ? arg_path_format : def_format;
     +
     +	append_formatted_path(&sb, path, prefix, fmt);
3:  b45c6f0d12 ! 3:  38b733ea64 repo: add path.commondir with absolute and relative suffix formatting
    @@ Commit message
         Exposing explicit format variants rather than a single key with a
         default avoids ambiguity for scripts that require predictable output.
     
    -    Add a test helper test_repo_info_path that creates isolated
    -    repositories per test case to prevent state leaks, captures the repo
    -    root before changing directories to avoid eval, and accepts an optional
    -    init_command to cover environment variable overrides such as
    -    GIT_COMMON_DIR and GIT_DIR.
    -
         Mentored-by: Justin Tobler [off-list ref]
         Mentored-by: Lucas Seiki Oshiro [off-list ref]
         Signed-off-by: K Jayatheerth [off-list ref]
    @@ t/t1900-repo-info.sh: test_expect_success 'git repo info -h shows only repo info
     +# Helper function to test path keys in both absolute and relative formats.
     +# $1: label for the test
     +# $2: field_name (e.g., commondir)
    -+# $3: unique repo name for isolation
    -+# $4: expect_absolute (suffix appended to repo root)
    -+# $5: expect_relative (the relative path string expected)
    -+# $6: init_command (extra setup like exporting env vars)
    ++# $3: expected_dir (the directory name, e.g., .git or custom-common)
    ++# $4: init_command (extra setup like exporting env vars)
     +test_repo_info_path () {
     +	label=$1
     +	field_name=$2
    -+	repo_name=$3
    -+	expect_absolute_suffix=$4
    -+	expect_relative=$5
    -+	init_command=$6
    -+
    -+	absolute_root="$repo_name-absolute"
    -+	relative_root="$repo_name-relative"
    -+
    -+	test_expect_success "setup: $label" '
    -+		git init "$absolute_root" &&
    -+		git init "$relative_root" &&
    -+		mkdir -p "$absolute_root/sub" "$relative_root/sub"
    -+	'
    ++	expected_dir=$3
    ++	init_command=$4
     +
     +	test_expect_success "absolute: $label" '
    ++		test_when_finished "rm -rf repo" &&
    ++		git init repo &&
     +		(
    -+			cd "$absolute_root/sub" &&
    ++			mkdir -p repo/sub &&
    ++			cd repo/sub &&
     +			ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
     +			eval "$init_command" &&
    -+			expect_path="$ROOT${expect_absolute_suffix:+/$expect_absolute_suffix}" &&
    -+			echo "path.$field_name.absolute=$expect_path" >expect &&
    ++			echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect &&
     +			git repo info "path.$field_name.absolute" >actual &&
     +			test_cmp expect actual
     +		)
     +	'
     +
     +	test_expect_success "relative: $label" '
    ++		test_when_finished "rm -rf repo" &&
    ++		git init repo &&
     +		(
    -+			cd "$relative_root/sub" &&
    ++			mkdir -p repo/sub &&
    ++			cd repo/sub &&
     +			ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
     +			eval "$init_command" &&
    -+			echo "path.$field_name.relative=$expect_relative" >expect &&
    ++			echo "path.$field_name.relative=../$expected_dir" >expect &&
     +			git repo info "path.$field_name.relative" >actual &&
     +			test_cmp expect actual
     +		)
     +	'
     +}
     +
    -+test_repo_info_path 'commondir standard' 'commondir' 'commondir-std' \
    -+	'.git' '../.git'
    ++test_repo_info_path 'commondir standard' 'commondir' '.git'
     +
     +test_repo_info_path 'commondir with GIT_COMMON_DIR and GIT_DIR' 'commondir' \
    -+	'commondir-envs' 'custom-common' '../custom-common' \
    ++	'custom-common' \
     +	'GIT_COMMON_DIR="$ROOT/custom-common" && export GIT_COMMON_DIR &&
     +	 GIT_DIR="../.git" && export GIT_DIR &&
     +	 git init --bare "$ROOT/custom-common"'
     +
     +test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \
    -+	'commondir-only-gitdir' '.git' '../.git' \
    ++	'.git' \
     +	'GIT_DIR="../.git" && export GIT_DIR'
     +
      test_done
4:  b5234ffe3e ! 4:  ead1117332 repo: add path.gitdir with absolute and relative suffix formatting
    @@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
     
      ## t/t1900-repo-info.sh ##
     @@ t/t1900-repo-info.sh: test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \
    - 	'commondir-only-gitdir' '.git' '../.git' \
    + 	'.git' \
      	'GIT_DIR="../.git" && export GIT_DIR'
      
    -+test_repo_info_path 'gitdir standard' 'gitdir' 'gitdir-std' \
    -+	'.git' '../.git'
    ++test_repo_info_path 'gitdir standard' 'gitdir' '.git'
     +
     +test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
    -+	'gitdir-env' '.git' '../.git' \
    ++	'.git' \
     +	'GIT_DIR="../.git" && export GIT_DIR'
     +
      test_done
-- 
2.54.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help