Skip to content

feat: Add Co-authored-by attribution for AI commits #3789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 44 commits into
base: main
Choose a base branch
from

Conversation

ei-grad
Copy link

@ei-grad ei-grad commented Apr 12, 2025

This PR implements the proposal from issue #3788, adding support for attributing AI-generated commits using the Co-authored-by: Git trailer.

Changes:

  • Introduces the --attribute-co-authored-by command-line flag (and corresponding config option) to enable this feature. Defaults to False.
  • Updates aider/repo.py's commit method:
    • When aider_edits=True and --attribute-co-authored-by=True, a Co-authored-by: aider (<model_name>) <[email protected]> trailer is appended to the commit message.
    • Implements the following precedence rules for AI edits (aider_edits=True):
      • If --attribute-co-authored-by=True:
        • The trailer is added.
        • Author/Committer names are not modified by default.
        • If --attribute-author=True or --attribute-committer=True is explicitly set, the respective name is modified in addition to the trailer.
      • If --attribute-co-authored-by=False:
        • The trailer is not added.
        • Author/Committer names are modified by default (or based on explicit --attribute-author=False/--attribute-committer=False).
    • For user edits (aider_edits=False), --attribute-co-authored-by is ignored, and attribution follows the existing rules for --attribute-committer.
  • Adds the --attribute-co-authored-by argument definition and help text to aider/args.py.
  • Adds/updates tests in tests/basic/test_repo.py to cover the new flag and its interactions with existing attribution flags (test_commit_with_co_authored_by, test_commit_co_authored_by_with_explicit_name_modification, etc.).

Resolves: #3788

Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) [email protected]

ei-grad and others added 30 commits April 12, 2025 16:52
Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
ei-grad and others added 11 commits April 12, 2025 18:26
Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
Co-authored-by: aider (vertex_ai/gemini-2.0-flash-lite-001) <[email protected]>
Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
@CLAassistant
Copy link

CLAassistant commented Apr 12, 2025

CLA assistant check
All committers have signed the CLA.

@ei-grad
Copy link
Author

ei-grad commented Apr 12, 2025

/aider --model vertex_ai/gemini-2.5-pro-exp-03-25 aider/args.py aider/repo.py tests/basic/test_repo.py  
> Aider v0.81.3.dev38+gc56e836d.d20250412  
> Model: vertex_ai/gemini-2.5-pro-exp-03-25 with diff-fenced edit format  
> Git repo: .git with 649 files  
> Repo-map: using 4096 tokens, auto refresh  
> Added aider/args.py to the chat.  
> Added aider/repo.py to the chat.  
> Added tests/basic/test_repo.py to the chat.  

#### /web https://github.com/Aider-AI/aider/issues/3788  
> Scraping https://github.com/Aider-AI/aider/issues/3788...  
> For the best web scraping, install Playwright:

/home/ei-grad/repos/github.com/aider-ai/aider/.venv/bin/python3 -m playwright install --with-deps chromium

See https://aider.chat/docs/install/optional.html#enable-playwright for more info.  
> Install playwright? (Y)es/(N)o [Yes]: n  
> Unable to initialize playwright.  
> ... added to chat.  

Ensure that we have properly implemented the proposal from issue 3788. Provide me detailed chain of thought.

Okay, I will review the code and ensure it aligns with the proposal from issue #3788 regarding Git commit attribution, specifically the --attribute-co-authored-by flag and its interactions.

Chain of Thought:

  1. Understand the Goal: The primary goal of issue Proposal: Add attribute-co-authored-by Option to Fix Unexpected Author/Committer Modification #3788 was to introduce a Co-authored-by: trailer for AI-generated commits as an alternative attribution method, controlled by --attribute-co-authored-by. This new flag needs to interact correctly with the existing --attribute-author and --attribute-committer flags, establishing a clear precedence.
  2. Recall/Review the Precedence Rules:
    • AI Edits (aider_edits=True):
      • If --attribute-co-authored-by=True:
        • Add Co-authored-by: trailer.
        • Default: Do not modify Author/Committer names (trailer takes precedence).
        • Explicit Override: If --attribute-author=True or --attribute-committer=True is explicitly set, modify the respective name in addition to the trailer.
      • If --attribute-co-authored-by=False (or default):
        • Do not add trailer.
        • Default: Modify Author/Committer names (implicit True).
        • Explicit Override: If --attribute-author=False or --attribute-committer=False is explicitly set, do not modify the respective name.
    • User Edits (aider_edits=False):
      • --attribute-co-authored-by is ignored (no trailer).
      • Author name is never modified.
      • Committer name is modified by default (implicit True).
      • Explicit Override: If --attribute-committer=False is explicitly set, do not modify Committer name.
  3. Examine aider/args.py:
    • Verify the --attribute-co-authored-by argument exists.
    • Check its action (should be BooleanOptionalAction), default (should be False), and help text.
    • Finding: The argument exists with the correct action and default. The help text accurately describes the behavior and precedence: "...If True, this takes precedence over default --attribute-author and --attribute-committer behavior unless they are explicitly set to True." This matches the rules.
  4. Examine aider/repo.py (__init__):
    • Verify the attribute_co_authored_by parameter is accepted and stored in self.
    • Finding: The parameter is present and assigned to self.attribute_co_authored_by. Correct.
  5. Examine aider/repo.py (commit method):
    • Flag Retrieval: Check how attribute_co_authored_by, attribute_author, and attribute_committer are obtained (preferring coder.args if available).
    • Finding: The code correctly attempts to get these values from coder.args first, falling back to self attributes. Correct.
    • Trailer Logic: Check the condition for adding the commit_message_trailer.
    • Finding: The trailer is added if aider_edits and attribute_co_authored_by:. Correct.
    • Name Modification Logic: This is the core part. Analyze how use_attribute_author and use_attribute_committer are determined.
      • author_explicit = attribute_author is not None
      • committer_explicit = attribute_committer is not None
      • effective_author = True if attribute_author is None else attribute_author
      • effective_committer = True if attribute_committer is None else attribute_committer
      • use_attribute_author = ( aider_edits and effective_author and (not attribute_co_authored_by or author_explicit) )
      • use_attribute_committer = effective_committer and ( not (aider_edits and attribute_co_authored_by) or committer_explicit )
    • Finding: This logic correctly implements the precedence rules.
      • use_attribute_author: Is True only if it's an AI edit (aider_edits), the effective setting is True (effective_author), AND (co-authoring is off not attribute_co_authored_by OR the author flag was explicitly set author_explicit). This matches the rules.
      • use_attribute_committer: Is True only if the effective setting is True (effective_committer) AND (it's not an AI edit with co-authoring enabled not (aider_edits and attribute_co_authored_by) OR the committer flag was explicitly set committer_explicit). This also correctly covers both AI and user edits according to the rules.
    • Environment Setting: Check if set_git_env is called based on use_attribute_author and use_attribute_committer.
    • Finding: The with contextlib.ExitStack() as stack: block correctly uses these flags to conditionally set GIT_AUTHOR_NAME and GIT_COMMITTER_NAME. Correct.
    • Final Message: Check if the trailer is appended correctly.
    • Finding: full_commit_message = commit_message + commit_message_trailer. Correct.
  6. Examine tests/basic/test_repo.py:
    • Check for tests covering the interactions between aider_edits, attribute_co_authored_by, attribute_author, and attribute_committer.
    • test_commit_with_co_authored_by: Tests AI edit + co-author=True + default author/committer. Asserts trailer is present and names are not modified. Correct.
    • test_commit_co_authored_by_with_explicit_name_modification: Tests AI edit + co-author=True + explicit author/committer=True. Asserts trailer is present and names are modified. Correct.
    • test_commit_ai_edits_no_coauthor_explicit_false:
      • Case 1: Tests AI edit + co-author=False + explicit author=False + default committer. Asserts no trailer, author not modified, committer is modified. Correct.
      • Case 2: Tests AI edit + co-author=False + default author + explicit committer=False. Asserts no trailer, author is modified, committer not modified. Correct.
    • test_commit_with_custom_committer_name: Covers several base cases including user edits (aider_edits=False) with default and explicit committer settings, confirming author is never modified for user edits and committer behaves as expected. Correct.
    • Finding: The existing tests cover the crucial scenarios defined by the precedence rules.

Conclusion:

The implementation across aider/args.py, aider/repo.py, and the relevant tests in tests/basic/test_repo.py accurately reflects the proposal from issue #3788. The logic correctly handles the addition of the Co-authored-by: trailer and respects the defined precedence rules between --attribute-co-authored-by, --attribute-author, and --attribute-committer for both AI-generated and user-driven commits.

No code changes are required based on this review. The implementation appears correct.

Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
Co-authored-by: aider (vertex_ai/gemini-2.5-pro-exp-03-25) <[email protected]>
@ei-grad ei-grad changed the title Feat: Add Co-authored-by attribution for AI commits feat: Add Co-authored-by attribution for AI commits Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants