Skip to content

fix(util): preserve separators before relative path tokens - #2319

Merged
Byron merged 1 commit into
gitpython-developers:mainfrom
gavenren:fix/join-path-leading-separators
Oct 29, 2026
Merged

Byron merged 1 commit into
gitpython-developers:mainfrom
gavenren:fix/join-path-leading-separators

Conversation

@gavenren

Copy link
Copy Markdown
Contributor

The public join_path("parent", "/child") returns parentchild, and chaining slash-prefixed tokens loses each separator. Strip leading slashes from later tokens before the existing join logic. Later tokens still extend the accumulated prefix; they do not replace it. Document this contract and cover strings, PathLike input, chained tokens, roots, empty tokens and repeated leading slashes.

This preserves the relative-token intention explained in the earlier #119 discussion. That proposal replaced the accumulated prefix with an absolute token; this patch retains the prefix and fixes the missing seam.

Motivation: This work was pursued to build @gavenren's requested portfolio of tested open-source contributions. Inspecting GitPython's public path helpers exposed this reproducible case.

Validation (Linux, Python 3.12.14, Git 2.52.0, GixPython 0.3.0):

  • Five of the eleven new parameterized cases fail against unchanged main.
  • test/test_util.py, via test/run-local.py, with each of GIT_PYTHON_BACKEND=cli and gix: 128 passed, 39 skipped per backend.
  • Caller modules test_tree.py test_refs.py test_remote.py, through the same runner with both backends: 230 passed, seven failed per backend. The identical seven test_timeout_stalled_remote cases fail on an unchanged-base worktree with both backends (seven failed, two passed in the isolated timeout selection). These failures concern the test's three-second timeout-cleanup bound; their root cause has not been established here.
  • Repository pre-commit run --files git/util.py test/test_util.py: passed all applicable hooks, including Ruff check/format.
  • git diff --check: passed.
  • Full suites and other platforms were not run.

Agent identification: This PR, implementation, tests, commit and description were prepared autonomously by OpenAI Codex in ChatGPT Work Mode, communicating through @gavenren's account. The exact underlying model and reasoning setting are unavailable. No human review, approval or manual testing is claimed.

The public `join_path` helper drops the slash in `join_path("parent", "/child")`, yielding `parentchild`. Strip leading slashes from later tokens before the normal joining logic so they remain relative to the accumulated prefix and receive a separator. Document this retained relative-token contract and cover string/PathLike inputs, chained tokens, roots, empty tokens and repeated leading separators.

Five of eleven regression cases fail before this change. Afterward the complete utility module passes 128 tests with 39 skips on each CLI/Gix backend. Tree/reference/remote caller modules pass 230 tests with seven stalled-remote timeout failures per backend; the exact same seven failures reproduce on unchanged main. Repository pre-commit hooks pass. Tested on Linux with Python 3.12.14, Git 2.52.0 and GixPython 0.3.0; no other platform execution is claimed.

Assisted-by: OpenAI Codex (model: unknown, autonomous)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the join_path() prefix-preservation change.

No open issues 🎉

What changed in this PR

Fixes join_path() so slash-prefixed later tokens retain the accumulated prefix and are joined with the correct separator.

Changes:

  • Strip leading slashes from later tokens before applying the existing join logic.
  • Document that later tokens are treated as relative.
  • Add 11 regression cases covering strings, PathLike input, chained tokens, roots, empty tokens, and repeated leading slashes.
File Description
test/​test_util.py Adds parameterized coverage for relative-token joining.
git/​util.py Fixes separator handling and documents the joining contract.

Review effort: Balanced

@Byron
Byron merged commit 97f8882 into gitpython-developers:main Oct 29, 2026
94 of 95 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants