Skip to main content

git_tools

pipeline status version

A small, stdlib-only managed-clone GitOps client — clone / branch / commit / push for a long-lived working clone (typically on /data). Not a FastPluggy plugin, just a library you pip install and import.

Extracted and generalized from the proven git logic in fp-deployer/apps_repo.py (the careful bits: pull --rebase --autostash, no-change short-circuit, conflict-marker refusal, identity via -c, never force-push), adding clone-if-missing and feature-branch support for content-repo callers like the brain app committing KB captures.

Why not GitPython / the GitLab API

  • Subprocess git, no GitPython → consumers stay dependency-light (and it matches fp-deployer / ecosystem_status, which deliberately avoid the optional dep). It also lets you run the repo's own scripts against the clone (e.g. the KB's status.py / kb_checks.py).
  • The GitLab Commits API is the clone-free alternative (what brain/kb_capture.py uses today); it's fine for simple text commits but blind to repo state. git_tools is the clone-based path.

Usage

from git_tools import GitRepo

repo = GitRepo(
    path="/data/kb/fp-tmp-personal",
    remote_url="https://oauth2:<token>@gitlab.ggcorp.fr/JeJe/fp-tmp-personal.git",  # or git@… + key_path
    branch="main",
)

# One call: clone-if-needed → feature branch off main → write → commit → push (idempotent).
res = repo.commit_files(
    {"_raw/brain/2026-06-12_x_42/content.md": "...", "_raw/brain/2026-06-12_x_42/meta.yml": "source: brain\n"},
    "brain capture: x (share 42)",
    branch="brain-app", base="main",
)
# -> {"sha": "abc1234", "committed": True, "branch": "brain-app"}

Auth: embed a token in remote_url for HTTPS (https://oauth2:<token>@host/repo.git), or pass key_path= (+ optional known_hosts=) for an SSH remote. Serialize concurrent writers on one shared clone with with repo.lock(): ....

API

GitRepo(path, remote_url, branch, key_path, known_hosts, author_name, author_email, timeout) with: ensure_clone() · clone_or_refresh() · pull_rebase() · prepare_branch(branch, base) · write_files(files) · remove_files(paths) · move(src, dest) · commit(paths, message, *, stage=True) · push(branch) · commit_files(...) (high-level) · status() · lock(). Working-tree inspection: diff(paths=None, *, staged=None) · changed_files(paths=None) -> list[FileChange]. Failures raise GitError / Conflict (both subclass GitToolsError).

changed_files parses git status --porcelain into FileChange(path, status, staged) records — for a consumer that works on an already-checked-out repo (status/diff/move, no push), e.g. ecosystem_status' wip-ia-code/ flow. (Distinct from status(), which probes clone liveness / HEAD.)

for c in repo.changed_files(["wip-ia-code/"]):   # status --porcelain, scoped
    print(c.path, c.status, "staged" if c.staged else "unstaged")
print(repo.diff(["wip-ia-code/"]))               # combined worktree + cached diff
repo.move("wip-ia-code/a.md", "wip-ia-code/plans/a.md")  # git mv

Delete a subtree symmetrically with the write path — git rm stages the removal, so commit with stage=False (re-adding a now-absent path would fail):

repo.pull_rebase()
repo.remove_files(["myapp"])             # git rm -r -- myapp
res = repo.commit(["myapp"], "drop myapp", stage=False)
if res["committed"]:
    repo.push()

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastpluggy_git_tools-0.2.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastpluggy_git_tools-0.2.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file fastpluggy_git_tools-0.2.1.tar.gz.

File metadata

  • Download URL: fastpluggy_git_tools-0.2.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for fastpluggy_git_tools-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7ee5e6db7b2744e4e21a34ce542fd9f48e0123a4f54e2f5acdfcc814600310de
MD5 ce94f475f0320e6254664260a0d8b4d8
BLAKE2b-256 124a2b52e0f3348dc38b03de569ca788ce06e4a2c2a165232628a229f37957e2

See more details on using hashes here.

File details

Details for the file fastpluggy_git_tools-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fastpluggy_git_tools-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a89cd9ffcfbe4016611ac95ece5e5db698999e933e3d70435085fbaf9ace1956
MD5 78b18f191d0787f0a8bd9e0e172714c0
BLAKE2b-256 5deef6aa1164e792e0a6c1b25e6397fadebd54361c6e5d2d95266af57d26bcb1

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page