Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 14, 2025

Fixes the fatal error that occurs when running conventional-changelog on a repository with no tags.

Problem

When no tags exist in the repository, Repository::getLastTag() returns '0.0.0' as a default value. This value is then used in git log commands like git log --pretty=format:'...' 0.0.0...HEAD, which fails with:

fatal: ambiguous argument '0.0.0...HEAD': unknown revision or path not in the working tree.

Solution

Modified src/Changelog.php to detect when version is '0.0.0' (indicating no tags were found) and replace it with the first commit hash when building git revision ranges. Since the first commit hash is a valid git reference, git commands succeed.

Changes Made

  • Added check for '0.0.0' in history mode with autoCommit (line 194)
  • Added check for '0.0.0' in normal mode (line 215)
  • Added check for '0.0.0' in tag range mode (line 236)

Testing

  • ✅ Repository with no tags - works correctly
  • --first-release flag - works correctly
  • --history flag - works correctly
  • ✅ All existing tests pass (2/2)

The changes are minimal and surgical (9 insertions, 3 deletions), affecting only the specific case where no tags exist while maintaining all existing functionality.

Fixes #71

Original prompt

This section details on the original issue you should resolve

<issue_title>fatal: ambiguous argument '0.0.0...HEAD': unknown revision or path not in the working tree.</issue_title>
<issue_description>Hey,

first off thank you for making and maintaining this!

When I run composer changelog I get the following output:

> conventional-changelog

conventional-changelog 1.17.0
=============================

Checking environment requirements
 ✓ Commands executions enabled
 ✓ Git detected correctly
 ✓ Git version detected: 2.43.0
 ✓ Valid git worktree directory: /path/to/grandeljay/modified-consistent-flags
 ✓ Valid git remote repository url: https://github.com/grandeljay/modified-consistent-flags

Generating changelog

Summary
-------

 [OK] Changelog generated!

 > Changelog file: CHANGELOG.md
fatal: ambiguous argument '0.0.0...HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Is it due to my tags not starting with a v? I am using some more external tools and one them requires my git tags to be just numbers and dots. I already have 10 tags set.

Any ideas?</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #71


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@marcocesarato
Copy link
Owner

@copilot continue

Copy link
Contributor Author

Copilot AI commented Oct 14, 2025

@copilot continue

The fix has been completed and tested. All tests pass (2/2) and the issue is resolved.

Changes made (commit 0917fe2):

  • Fixed the ambiguous argument error by checking if lastVersion or fromTag equals '0.0.0' (the default when no tags exist) and replacing it with the first commit hash in git revision ranges
  • Applied the fix in three locations: history mode with autoCommit, normal mode, and tag range mode

Testing:
✅ Repository with no tags - works correctly
--first-release flag - works correctly
--history flag - works correctly
✅ All existing tests pass

The PR is ready for review and merge.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/BrainMaestro/composer-git-hooks/zipball/ffed8803690ac12214082120eee3441b00aa390e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/d48755372a113bddb99f749e34805d83f3acfe04
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/composer/pcre/zipball/4bff79ddd77851fe3cdd11616ed3f92841ba5bd2
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/composer/semver/zipball/3953f23262f2bff1919fc82183ad9acb13ff62c9
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/composer/xdebug-handler/zipball/ced299686f41dce890debac69273b47ffe98a40c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/doctrine/annotations/zipball/e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/doctrine/lexer/zipball/84a527db05647743d50373e0ec53a152f2cde568
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/php-fig/event-dispatcher/zipball/dbefd12671e8a14ec7f180cab83036ed26714bb0
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/php-fig/log/zipball/ef29f6d262798707a9edd554e2b82517ef3a9376
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/php-mock/php-mock/zipball/6f71999665d27fbdf684c1639981e96eff540b5f
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/console/zipball/ea59bb0edfaf9f28d18d8791410ee0355f317669
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/deprecation-contracts/zipball/e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/0ad3b6f1e4e2da5690fefe075cd53a238646d8dd
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/event-dispatcher/zipball/404b307de426c1c488e5afad64403e5f145e82a5
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/filesystem/zipball/82b6c62b959f642d000456f08c6d219d749215b3
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/finder/zipball/20808dc6631aecafbe67c186af5dcb370be3a0eb
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/options-resolver/zipball/aa0e85b53bbb2b4951960efd61d295907eacd629
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/511a08c03c1960e08a883f4cffcacd219b758354
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/19bd1e4fcd5b91116f14d8533c57831ed00571b6
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-php73/zipball/9e8ecb5f92152187c4799efd3c96b78ccab18ff9
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-php80/zipball/7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-php81/zipball/707403074c8ea6e2edaf8794b0157a0bfa52157a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/process/zipball/680e8a2ea6b3f87aecc07a6a65a203ae573d1902
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/service-contracts/zipball/a8c9cedf55f314f3a186041d19537303766df09a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/stopwatch/zipball/f3adc98c1061875dd2edcd45e5b04e63d0e29f8f
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/string/zipball/823f143370880efcbdfa2dbca946b3358c4707e5
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/HbzSPk /usr/bin/composer install --no-interaction (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI changed the title [WIP] Fix ambiguous argument error when generating changelog Fix ambiguous argument error when generating changelog Oct 14, 2025
Copilot finished work on behalf of marcocesarato October 14, 2025 19:11
@marcocesarato marcocesarato marked this pull request as ready for review October 14, 2025 19:16
@marcocesarato marcocesarato merged commit 70b4a67 into main Oct 14, 2025
2 checks passed
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.

fatal: ambiguous argument '0.0.0...HEAD': unknown revision or path not in the working tree.

2 participants