Add a git section to the sidebar - #443
Open
pvitt72 wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
gitis 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: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..aux,.logand.pdfdon't get committed by accident. It then runsgit 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
Gio.Subprocesson the main loop, so no threads and no locks are involved, unlike the build system.communicate_utf8, which truncates at the first NUL byte — exactly whatgit status -zseparates its records with.git_client.pycontains no GTK.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 togit credential approveand the operation is retried. A credential that fails again is passed togit credential reject, so a stale password doesn't stay in a helper.With Remember checked,
approvereaches 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-credentialsand the credential comes back from the cache, with it the credential reaches the configured helper, andrejectremoves it again.Not yet exercised: the credentials dialog against a real remote returning a 401.