Skip to content

Feature/enhanced source control#138

Open
theepicsaxguy wants to merge 17 commits intochriswritescode-dev:mainfrom
theepicsaxguy:feature/enhanced-source-control
Open

Feature/enhanced source control#138
theepicsaxguy wants to merge 17 commits intochriswritescode-dev:mainfrom
theepicsaxguy:feature/enhanced-source-control

Conversation

@theepicsaxguy
Copy link
Contributor

Summary

I added first‑class support for inspecting commits and safely discarding local changes, end to end. The main gap was that the UI could list commits but not explain what was inside them, and users couldn’t easily undo local changes without dropping to the terminal. That made code review and recovery workflows slower and error‑prone.

I chose to expose explicit backend endpoints for commit details, per‑file commit diffs, and discard operations instead of reusing existing status/diff APIs. Those APIs are fundamentally about the working tree, and overloading them would have mixed concepts and produced fragile edge cases. Keeping commit inspection and working‑tree operations separate keeps the mental model clear and avoids accidental data loss.

On the backend, I rely on native git commands (show, numstat, restore, clean) rather than re‑implementing logic in code. This keeps behavior aligned with git itself and limits surface area for bugs. Large diffs are truncated defensively to avoid blowing up responses or the UI.

On the frontend, I reused the existing diff viewer and file list instead of introducing new components, extending them just enough to support commit context and read‑only mode. This minimizes new UI concepts while making commit browsing feel consistent with local changes.

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation

Checklist

  • Code follows project style (no comments, named imports)
  • TypeScript types are properly defined
  • Tests added/updated (80% coverage target)
  • pnpm lint passes locally
  • pnpm typecheck passes locally

- Add discard changes functionality with confirmation dialog
- Implement commit detail view with file list and diffs
- Update commit badges: blue for unpushed (local), purple for pushed (remote)
- Display current branch in commits header
- Reuse existing components (DeleteDialog, FileDiffView, GitFlatFileList)
- Add proper error handling and toast notifications
- Extend backend API with /discard and /commit/:hash endpoints
- Update types to include CommitDetails and CommitFile interfaces

Backend:
- Add discardChanges() method to GitService
- Add getCommitDetails() and getCommitDiff() methods
- Add POST /:id/git/discard endpoint
- Add GET /:id/git/commit/:hash and /:id/git/commit/:hash/diff endpoints

Frontend:
- Add discard button (rotate-left icon) to file items
- Add gitDiscardFiles API function and useGit mutation
- Create CommitDetailView component
- Update CommitsTab with color coding and branch display
- Extend SourceControlPanel for commit detail navigation
- Add confirmation dialog using DeleteDialog pattern

Tests:
- Backend tests passing with 77% line coverage
- Linting passes for all modified files
- Type safety maintained throughout

BREAKING CHANGES: None
- Fix syntax error in GitService.ts (missing closing brace for getCommitDiff)
- Make AUTH_SECRET mandatory in crypto.ts to prevent weak encryption fallback
- Fix race condition in PassphraseHandler by using unique request IDs
- Add error logging to ssh-key-manager catch blocks
- Add type guards (isGitCredential, filterGitCredentials) to replace unsafe assertions
- Fix TypeScript errors and variable shadowing in GitService and settings
- Remove unused variable in sshHostKeyHandler
- Update GitService tests with proper mock data structure

All changes verified: lint passes, typecheck passes, 102/103 tests pass
- Fix git restore command syntax (--source=HEAD → --source HEAD)
- Use crypto.randomBytes for secure requestId generation
- Add requestId to SSH host key broadcast for frontend compatibility
- Add missing onDiscard prop to GitFlatFileList
- Remove dead code (187 unreachable lines) in ChangesTab
- Fix regex alternation bug in commit stat parsing
- Optimize getCommitDetails with --numstat (N+1 → 1 git call)
- Optimize unpushed commit check to use merge-base instead of full list
- Remove useless conditional in handleDiscard
- Fix type contract violation in CommitDetailView onSelect
Resolved conflicts:
- backend/src/services/git-auth.ts: Combined imports from both branches
- backend/src/services/git/GitService.ts: Preserved new CommitDetails types and filterGitCredentials
- backend/test/services/git/GitService.test.ts: Added filterGitCredentials to mock and used main's mockRepo format

Preserved feature functionality:
- discardChanges(), getCommitDetails(), getCommitDiff() methods
- CommitDetails and CommitFile types
- New git routes: /discard, /commit/:hash, /commit/:hash/diff
- Frontend commit detail view and discard functionality

Integrated main improvements:
- SSH host key handling with normalizeSSHUrl
- filterGitCredentials type validation
- Crypto module AUTH_SECRET validation
- Add missing handleDiscard function in ChangesTab.tsx
- Fix duplicate requestId property in sshHostKeyHandler.ts
- Remove unnecessary type assertion in settings.ts
…ixes

- Add readOnly mode to GitFlatFileList to hide stage/unstage buttons in commit view
- Fix commit file diff display by using correct git show command syntax
- Add line stats display (+additions/-deletions) for each file in commit view
- Show total commit stats in header (Changed Files N +X -Y)
- Fix commit file list parsing to use --name-status and --numstat
- Add 500KB diff size limit with truncation warning
- Fix discard changes for untracked files by deleting them directly
- Update Dockerfile to copy backend/node_modules correctly
- Fix TypeScript error in CommitDetailView onFileSelect call
…ments, and duplicates

- Remove shared handleApiError import from OAuth and restore local pattern

- Fix isCommitUnpushed to use getUnpushedCommitHashes for correct upstream detection

- Remove inline comments from ssh-key-manager.ts (style violation)

- Remove duplicate fetchCommitDiff function

- Add missing getErrorMessage import to repo-git.ts
…ity; add discardChanges functionality and enhance commit details retrieval
…nd enhance error handling in handleGitAction
Copilot AI review requested due to automatic review settings February 16, 2026 16:11
@gitguardian
Copy link

gitguardian bot commented Feb 16, 2026

⚠️ GitGuardian has uncovered 5 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
26955332 Triggered OpenSSH Private Key 5b718a1 backend/test/integration/ssh-integration.test.ts View secret
26955333 Triggered OpenSSH Private Key 5b718a1 backend/test/utils/ssh-key-manager.test.ts View secret
26955334 Triggered OpenSSH Private Key 5b718a1 backend/test/services/git-auth.test.ts View secret
26955335 Triggered OpenSSH Private Key 5b718a1 backend/test/services/git-auth.test.ts View secret
26955336 Triggered OpenSSH Private Key 5b718a1 backend/test/services/git-auth.test.ts View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds first-class support for commit inspection and discarding local changes in the source control panel. The implementation exposes three new backend endpoints for fetching commit details, per-file commit diffs, and discarding changes, with corresponding frontend UI components for browsing commits and viewing their contents.

Changes:

  • Added backend services and routes for commit inspection (details, file lists, diffs) and discard operations
  • Extended frontend UI with commit detail view, file discard functionality, and additions/deletions display
  • Added comprehensive backend unit tests for new GitService methods (discardChanges, getCommitDetails, getCommitDiff, parseDiffOutput)

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
backend/src/services/git/GitService.ts Added discardChanges, getCommitDetails, getCommitDiff methods with parsing logic for commit files and diff truncation
backend/src/routes/repo-git.ts Added three new endpoints: POST /discard, GET /commit/:hash, GET /commit/:hash/diff
backend/src/types/git.ts Added CommitFile and CommitDetails interfaces, truncated field to FileDiffResponse
backend/test/services/git/GitService.test.ts Added 163 test cases covering discard operations, commit details parsing, commit diff retrieval, and diff output parsing
frontend/src/types/git.ts Added CommitFile and CommitDetails interfaces, additions/deletions to GitFileStatus
frontend/src/api/git.ts Added API functions and hooks for commit details, commit file diff, and discard operations
frontend/src/hooks/useGit.ts Added discardFiles mutation with error handling
frontend/src/components/source-control/SourceControlPanel.tsx Added view state management for commit detail view and navigation between tabs and commit details
frontend/src/components/source-control/CommitsTab.tsx Added branch display header and badge for pushed commits
frontend/src/components/source-control/CommitDetailView.tsx New component for displaying commit metadata, file list, and per-file diffs
frontend/src/components/source-control/ChangesTab.tsx Added discard functionality integration
frontend/src/components/source-control/GitFlatFileList.tsx Added readOnly mode and discard all button
frontend/src/components/source-control/GitFlatFileItem.tsx Added additions/deletions display and per-file discard button
frontend/src/components/file-browser/FileDiffView.tsx Added support for viewing commit diffs via commitHash prop
frontend/src/lib/git-status-styles.ts Changed unpushed badge color from amber to blue, added purple for pushed commits

@chriswritescode-dev
Copy link
Owner

I did a ton of patch up work over the weekend. Standardize some of the usage. Improved errors inside of the sourcecontrol component.

  • removed toasts and replaced with component level extracted messages.
  • fixed some minor issues
  • sse streaming and message and tool call parts are now handled properly with the last release
  • re-render is vastly improved along with input area.

@theepicsaxguy
Copy link
Contributor Author

I did a ton of patch up work over the weekend. Standardize some of the usage. Improved errors inside of the sourcecontrol component.

  • removed toasts and replaced with component level extracted messages.
  • fixed some minor issues
  • sse streaming and message and tool call parts are now handled properly with the last release
  • re-render is vastly improved along with input area.

I noticed. Solid work! I'll clean up the requested changes when I get around to it 🙌

@theepicsaxguy
Copy link
Contributor Author

@chriswritescode-dev I aligned the PR with your sourcecontrol changes (no toasts; component‑level errors). The commit detail + discard UI should be cleaner now, and revert flows are integrated. Let me know if you want anything adjusted.

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.

2 participants