Skip to content

Add a git section to the sidebar - #443

Open
pvitt72 wants to merge 1 commit into
cvfosammmm:masterfrom
pvitt72:git-section
Open

Add a git section to the sidebar#443
pvitt72 wants to merge 1 commit into
cvfosammmm:masterfrom
pvitt72:git-section

Conversation

@pvitt72

@pvitt72 pvitt72 commented Aug 3, 2026

Copy link
Copy Markdown

Adds a small git panel to the sidebar, between To-Dos and Document Stats.

This is a proposal rather than a request. I couldn't find any earlier discussion about version control in the issue tracker, so if it is out of scope for Setzer please just close this — no hard feelings, and I'm equally happy to rework the scope if you like the idea but not the shape.

What it does

The section only appears when git is installed and the current document lives in a repository, and hides itself otherwise. It shows the branch with its ahead/behind counts, the subject and date of the last commit and the number of changed files, plus two buttons:

  • Pull runs git pull --ff-only, so it can never leave the repository in a state the panel is unable to explain. On divergence it says so and points the user at a terminal.
  • Commit & Push first saves the open documents that live in the repository, then asks for a commit message and which files to include. Untracked files are unchecked by default, so .aux, .log and .pdf don't get committed by accident. It then runs git add -A -- <selected>, git commit -m … -- <selected> and a push (with --set-upstream origin <branch> when there is no upstream yet).

Deliberately left out: diffs, branch switching, a staging area, history. Anyone who needs those opens a terminal.

Implementation notes

  • Git runs through Gio.Subprocess on the main loop, so no threads and no locks are involved, unlike the build system.
  • Output is read as raw bytes rather than with communicate_utf8, which truncates at the first NUL byte — exactly what git status -z separates its records with.
  • The model / viewgtk / presenter / controller split follows the existing sidebar sections. git_client.py contains no GTK.
  • The state refreshes on document switch, on save, after each operation, and on a 10 second timer for changes made outside Setzer.

Credentials

Setzer stores no credentials itself. Operations run with GIT_TERMINAL_PROMPT=0; when one fails to authenticate, the user is asked once, the credentials are handed to git credential approve and the operation is retried. A credential that fails again is passed to git credential reject, so a stale password doesn't stay in a helper.

With Remember checked, approve reaches whichever helper the user has configured (libsecret, store, …). Without it, the operation runs with -c credential.helper= -c 'credential.helper=cache --timeout=900': an empty value resets the helper list, so the persistent helpers never see the password. SSH remotes never show the dialog at all.

Testing

Verified against a scratch repository with a local remote: repository detection, status parsing, saving before committing, untracked files staying out of the commit, the commit reaching the remote, and pull. The credential plumbing was checked separately in an isolated HOME: without Remember nothing is written to ~/.git-credentials and the credential comes back from the cache, with it the credential reaches the configured helper, and reject removes it again.

Not yet exercised: the credentials dialog against a real remote returning a 401.

Shows the branch with its ahead/behind counts, the last commit and the
number of changed files whenever the current document lives in a
repository, plus a pull and a commit & push button. The section hides
itself when git is missing or the document isn't under version control.

Git runs through Gio.Subprocess on the main loop, so no threads and no
locks are involved. Output is read as raw bytes because
communicate_utf8 would cut it at the first NUL byte, which is what
"git status -z" separates its records with.

Pull is --ff-only: it can never leave the repository in a state the
panel can't explain. Commit & push saves the open documents in the
repository first, then asks which files to include, with untracked
ones unchecked by default so build artifacts don't get committed by
accident.

Setzer never stores credentials itself. When an operation fails to
authenticate it asks once, hands them to "git credential approve" and
retries; a failing credential is rejected again so it doesn't stay in
a helper. Without "remember" the credentials only reach
git-credential-cache, because an empty credential.helper value resets
the helper list.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant