#214 rpmautospec fails if no GIT repo (i.e. when creating a new spec outside of a repo)
Closed: Fixed a year ago by nphilipp. Opened 2 years ago by eclipseo.

When creating a SPEC file from scratch with rpmautospec's %autorelease and %autochangelog, fedpkg --srpm fails with:

$ fedpkg --release f35 srpm
Could not execute srpm: 'NoneType' object has no attribute 'head'

Similarly:

fedpkg  --release f35 scratch-build --srpm --fail-fast
sources file doesn't exist. Source files download skipped.
Failed to get repository name from Git url or pushurl
Could not execute scratch_build: 'NoneType' object has no attribute 'head'

This is caused by the fact that there is no GIT repo for rpmautospec to gather its history.

In pkg_history.py, there is a try except which allows self.repo to be None;

        try:
            if hasattr(pygit2, "GIT_REPOSITORY_OPEN_NO_SEARCH"):
                kwargs = {"flags": pygit2.GIT_REPOSITORY_OPEN_NO_SEARCH}
            else:
                # pygit2 < 1.4.0
                kwargs = {}
            # pygit2 < 1.2.0 can't cope with pathlib.Path objects
            self.repo = pygit2.Repository(str(self.path), **kwargs)
        except pygit2.GitError:
            self.repo = None

but it is assumed later that repo is not None:

       if not head:
            head = self.repo[self.repo.head.target]
            diff_to_head = self.repo.diff(head)
            reflect_worktree = diff_to_head.stats.files_changed > 0
        elif isinstance(head, str):
            head = self.repo[head]

If the repo is non existent, there should be a method to avoid the history logic, and either set the release to 1 or determine it only from the changelog file entries.


Metadata Update from @nphilipp:
- Issue assigned to nphilipp

a year ago

Metadata Update from @nphilipp:
- Issue set to the milestone: So you call this production ready?

a year ago

I may have been hit with this bug when trying to use rpmautospec
after this commit
https://github.com/Iolaum/fcust/tree/9a2ae8d25abc8e9864bee9759f46f370329f8f15
but it could be that I m doing something wrong with the spec file entries.

Login to comment on this ticket.

Metadata