| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4440302 commit 47a668c
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,12 @@ fallbacks. | |||
| 45 | 45 | ||
| 46 | 46 | ## Index and object metadata lifecycle | |
| 47 | 47 | ||
| 48 | + `Repo(..., expand_vars=False)` remains accepted for callers such as sbxloop | ||
| 49 | + 2.1.36 that explicitly require literal paths. The default also keeps environment | ||
| 50 | + variables literal; `expand_vars=True` is unsupported. Callers wanting expansion | ||
| 51 | + must perform it before passing the path. Discovery still uses Gix/Git after | ||
| 52 | + ordinary input-path canonicalization. | ||
| 53 | + | ||
| 48 | 54 | `git.GitDB` and `git.db.GitDB` remain compatibility aliases for | |
| 49 | 55 | `GitCmdObjectDB`, so legacy `Repo(..., odbt=GitDB)` selectors use the same | |
| 50 | 56 | managed backend. Aider 0.86.2 uses that selector for every repository open. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -156,8 +156,10 @@ API changes | |||
| 156 | 156 | are removed; import from ``typing`` or the owning module. ``git.util`` now | |
| 157 | 157 | exposes the actual utility module. Abstract ``Traversable.traverse`` and | |
| 158 | 158 | ``list_traverse`` raise ``NotImplementedError``; use concrete implementations. | |
| 159 | - * Paths and URLs no longer expand ``$VAR``/``%VAR%`` automatically. Removed | ||
| 160 | - ``expand_vars`` switches from ``Repo``, ``Repo.init``, ``expand_path``, | ||
| 159 | + * Paths and URLs no longer expand ``$VAR``/``%VAR%`` automatically. ``Repo`` | ||
| 160 | + still accepts ``expand_vars=False`` for callers that explicitly select literal | ||
| 161 | + paths; ``True`` raises ``ValueError``. Removed ``expand_vars`` switches from | ||
| 162 | + ``Repo.init``, ``expand_path``, | ||
| 161 | 163 | ``cygpath`` and ``Git.polish_url``. Expand explicitly with | |
| 162 | 164 | ``os.path.expandvars`` if wanted; initial ``~`` expansion remains. | |
| 163 | 165 | ``HIDE_WINDOWS_KNOWN_ERRORS`` and ``HIDE_WINDOWS_FREEZE_ERRORS`` are removed. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -238,6 +238,7 @@ def __init__( | |||
| 238 | 238 | path: Optional[PathLike] = None, | |
| 239 | 239 | odbt: Type[GitCmdObjectDB] = GitCmdObjectDB, | |
| 240 | 240 | search_parent_directories: bool = False, | |
| 241 | + expand_vars: bool = False, | ||
| 241 | 242 | *, | |
| 242 | 243 | _env: Optional[Mapping[str, Optional[str]]] = None, | |
| 243 | 244 | ) -> None: | |
@@ -274,6 +275,11 @@ def __init__( | |||
| 274 | 275 | Please note that this was the default behaviour in older versions of | |
| 275 | 276 | GitPython, which is considered a bug though. | |
| 276 | 277 | ||
| 278 | + :param expand_vars: | ||
| 279 | + The legacy ``False`` option remains accepted to select literal paths. | ||
| 280 | + ``True`` is unsupported; expand environment variables explicitly | ||
| 281 | + before opening a repository. Initial ``~`` expansion remains enabled. | ||
| 282 | + | ||
| 277 | 283 | :raise git.exc.InvalidGitRepositoryError: | |
| 278 | 284 | ||
| 279 | 285 | :raise git.exc.NoSuchPathError: | |
@@ -286,6 +292,8 @@ def __init__( | |||
| 286 | 292 | # process environment. Apply these overrides to discovery and later calls. | |
| 287 | 293 | if not isinstance(odbt, type) or not issubclass(odbt, GitCmdObjectDB): | |
| 288 | 294 | raise ValueError("odbt must be GitCmdObjectDB or a subclass") | |
| 295 | + if expand_vars: | ||
| 296 | + raise ValueError("Environment variable expansion is unsupported; expand the path explicitly") | ||
| 289 | 297 | environment = dict(_env or {}) | |
| 290 | 298 | git_dir_env = environment.pop("GIT_DIR", os.getenv("GIT_DIR")) | |
| 291 | 299 | object_dir_env = environment.get("GIT_OBJECT_DIRECTORY", os.getenv("GIT_OBJECT_DIRECTORY")) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,22 @@ | |||
| 7 | 7 | import git | |
| 8 | 8 | import git.db | |
| 9 | 9 | ||
| 10 | - from test.lib.fixtures import fixture_repo | ||
| 10 | + from test.lib.fixtures import fixture_repo, read_only_fixture | ||
| 11 | + | ||
| 12 | + | ||
| 13 | + @pytest.mark.parametrize("object_format", ["sha1", "sha256"]) | ||
| 14 | + @pytest.mark.parametrize("ref_format", ["files", "reftable"]) | ||
| 15 | + def test_repo_accepts_explicit_literal_path_selection(object_format, ref_format, monkeypatch): | ||
| 16 | + root = read_only_fixture("downstream-literal-repo.sh", object_format, ref_format) | ||
| 17 | + monkeypatch.setenv("DOWNSTREAM_REPOSITORY", str(root / "expanded")) | ||
| 18 | + literal = root / "$DOWNSTREAM_REPOSITORY" | ||
| 19 | + for kwargs in ({}, {"expand_vars": False}): | ||
| 20 | + with git.Repo(literal, **kwargs) as repo: | ||
| 21 | + assert repo.head.commit.tree["tracked"].data_stream.read() == b"$DOWNSTREAM_REPOSITORY" | ||
| 22 | + with git.Repo(literal, git.GitCmdObjectDB, False, False) as repo: | ||
| 23 | + assert Path(repo.working_tree_dir) == literal | ||
| 24 | + with pytest.raises(ValueError, match="Environment variable expansion is unsupported"): | ||
| 25 | + git.Repo(literal, expand_vars=True) | ||
| 11 | 26 | ||
| 12 | 27 | ||
| 13 | 28 | @pytest.mark.parametrize("object_format", ["sha1", "sha256"]) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,10 @@ | |||
| 1 | + #!/usr/bin/env bash | ||
| 2 | + set -eu | ||
| 3 | + # Preserve the literal variable spelling to detect accidental expansion. | ||
| 4 | + # shellcheck disable=SC2016 | ||
| 5 | + for path in '$DOWNSTREAM_REPOSITORY' expanded; do | ||
| 6 | + git init -q --object-format="$1" --ref-format="$2" "$path" | ||
| 7 | + printf '%s' "$path" > "$path/tracked" | ||
| 8 | + git -C "$path" add tracked | ||
| 9 | + git -C "$path" commit -qm initial | ||
| 10 | + done | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments