Skip to content

_git.py:remove_files does not react to git's fatal error if newsfragment is untracked by git #448

@fleetingbytes

Description

@fleetingbytes

I created some news fragments for towncrier to build me my new changelog and after that I inteded to commit the changes to the git repo. So the news fragments themselves were not tracked by git at the time of the changelog generation. When towncrier asked if it is ok to remove the news fragments I said yes and this was the result:

Is it okay if I remove those files? [Y/n]: y
fatal: pathspec '<REDACTED_PATH>\changelog.d\11.improved.md' did not match any files

This error should be expected and handled here

    if answer_yes or click.confirm("Is it okay if I remove those files?", default=True):
        call(["git", "rm", "--quiet"] + fragment_filenames)

it could look something like this:

    if answer_yes or click.confirm("Is it okay if I remove those files?", default=True):
        try:
            subprocess.run(["git", "rm", "--quiet"] + fragment_filenames, check=True)
        except subprocess.CalledProcessError as err:
            ... # handle git's errors here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions