Skip to content

Improve lock file handling in commit message generation #2

@mickr

Description

@mickr

Problem

Currently, the application completely ignores lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, etc.) when generating commit messages, as seen in src/services/git.ts:31-43. While this prevents verbose, unhelpful diffs from being included in the AI analysis, it also means that important dependency updates are completely omitted from commit messages.

Current Behavior

The shouldIgnore function in src/services/git.ts:18-50 filters out:

  • package-lock.json
  • pnpm-lock.yaml
  • yarn.lock
  • composer.lock
  • Cargo.lock
  • Gemfile.lock
  • poetry.lock

This means when dependencies are updated, the generated commit message won't mention these changes at all.

Proposed Solution

Instead of completely ignoring lock files, we should:

  1. Detect lock file changes but handle them differently from regular code changes

  2. Generate meaningful summaries for lock file changes, such as:

    • "Updated dependencies" (for general updates)
    • "Added new dependencies: [list]" (when new deps are added)
    • "Removed dependencies: [list]" (when deps are removed)
    • "Updated [package] from X.X.X to Y.Y.Y" (for specific important updates)
  3. Use package manager tools to extract meaningful information:

    • For npm/yarn/pnpm: Parse the diff to identify added/removed/updated packages
    • Use git diff --name-status to detect if lock files changed
    • Run commands like npm ls --depth=0 --json to get dependency info if needed

Implementation Suggestions

  1. Modify shouldIgnore() to return an object instead of boolean:

    type IgnoreResult = {
      ignore: boolean;
      type?: 'lockfile' | 'generated' | 'vendor';
    };
  2. Add a new function summarizeLockFileChanges() that:

    • Parses lock file diffs to extract package changes
    • Returns a concise summary instead of the full diff
  3. Update getStagedDiff() to:

    • Include lock files but mark them with a special flag
    • Generate summaries for lock files instead of full diffs
  4. Modify the commit message generation to:

    • Include lock file summaries in the context
    • Generate appropriate commit messages like "chore(deps): update dependencies"

Benefits

  • More accurate commit messages that reflect all changes
  • Better tracking of dependency updates in commit history
  • Maintains performance by not sending huge lock file diffs to AI
  • Provides meaningful context about dependency changes

Files Affected

  • src/services/git.ts - Main implementation
  • src/services/__tests__/git.test.ts - Update tests
  • src/commands/generateCommitMessage.ts - Handle lock file summaries
  • src/types/git.ts - May need new types for lock file handling

Additional Considerations

  • Should be configurable via .commity.yaml to allow users to customize behavior
  • Consider caching dependency analysis for performance
  • Handle cases where both package.json and lock files change together

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions