repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

extensions/git-safe/README.md

Raw

git-safe

Hardened git clone tool for Pi.

Install / load

Loaded through the root pi-ext package. See ../../README.md.

Commands / tools / settings

Behavior

git_clone_safe clones a repository with checks around hook execution, symlinks, LFS filters, disk use, and credential prompts.

Operational behavior:

Demo

Tools suite

Markdown source
File outline
# git-safe

Hardened git clone tool for Pi.

## Install / load

Loaded through the root `pi-ext` package. See [../../README.md](../../README.md).

## Commands / tools / settings

- Commands: none
- Tools:
  - `git_clone_safe(url, path, branch?)`
    - `url`: Git repository URL
    - `path`: local target directory, absolute or relative to cwd
    - `branch`: optional branch name
- Hooks:
  - `session_start`
  - `tool_result` for `read`
- Settings: none

## Behavior

`git_clone_safe` clones a repository with checks around hook execution, symlinks, LFS filters, disk use, and credential prompts.

Operational behavior:

- rejects root, home, paths with depth less than 2, exact `/tmp`, `/var`, `/etc`, `/usr`, and paths starting with `/sys` or `/proc`
- refuses an existing target dir unless it contains `.pi-git-safe`
- removes and replaces prior `.pi-git-safe` clone dirs
- runs `git clone --no-checkout --depth 1 --single-branch -c core.symlinks=false`
- passes `--branch` when `branch` is provided
- disables credential prompts with `GIT_TERMINAL_PROMPT=0` and `GIT_TERMINAL_PROMPT_AUTOCHECK=0`
- sets repo-local `core.hooksPath` to an empty hooks dir
- sets repo-local `lfs.skipSmudge=true`
- writes `.git/info/attributes` with `* -filter`
- removes `.git/hooks`
- estimates checkout size with `git ls-tree -r -l HEAD`
- rejects content over 500 MB
- rejects trees over 10,000 files
- scans `git ls-files -s` for symlinks before checkout
- checks out with the empty hooks dir enforced
- kills clone after 60s and checkout after 30s
- writes `.pi-git-safe` marker after successful checkout
- returns canonical clone path, URL, optional branch, file count, total byte count, symlink count, symlink paths, and warnings
- recovers marked clone dirs on `session_start` by scanning cwd, temp dir, `~/.local/state/pi`, and home up to depth 4
- notifies UI when recovered clone dirs are found
- wraps text `read` results from tracked clone dirs in `<untrusted_external_data marker="...">` markers with a git-specific warning preamble
- warns when `.git/config` contains `include` or `includeIf`
- warns when symlinks are present; `core.symlinks=false` stores them as text files

## Demo

<!-- demo:tools_suite:start -->
![Tools suite](assets/tools_suite.gif)
<!-- demo:tools_suite:end -->