Skip to content
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

object not found and KeyError when scanning commits #949

Closed
yindaheng98 opened this issue Oct 20, 2019 · 5 comments
Closed

object not found and KeyError when scanning commits #949

yindaheng98 opened this issue Oct 20, 2019 · 5 comments
Labels

Comments

@yindaheng98
Copy link

Hi there, I'm using a python 3.7.2 and pygit2 in TravisCI for building and deploying my github pages. The python script is used to scan all the commit and find the latest commit time for every file. But now I got an error in TravisCI when building, just like this:

Traceback (most recent call last):
  File "travisPorcess.py", line 1, in <module>
    from meta import meta_data, path
  File "/home/travis/build/yindaheng98/My-docs/meta.py", line 5, in <module>
    from getDate import data
  File "/home/travis/build/yindaheng98/My-docs/getDate.py", line 71, in <module>
    for commit in commits:
KeyError: 'object not found - no match for id (c170b110850200770e9c0d1b35b2616dfe18614d)'

And this error was throw from:

repo = pygit2.Repository('./')
commits=repo.walk(repo.head.target,GIT_SORT_TOPOLOGICAL|GIT_SORT_REVERSE)

last_tree=None
for commit in commits:#<<<<<<<<-throw from here
    date=time.gmtime(commit.commit_time)
    date=time.strftime('%Y-%m-%d %H:%M:%S',date)
    print("scanning commit %s at %s"%(commit.message,date))

    tree=commit.tree
    if last_tree is None:
        last_tree=tree
        continue

    diff=tree.diff_to_tree(last_tree)
    updateData(date,diff)
    last_tree=tree

This error is only appear in TravisCI, it can done its work properly in my Notebook.

Is this error caused by bugs? Or just my improper usage?

PS: The complete python scripts is here

@ghost
Copy link

ghost commented Jan 15, 2020

I have encountered the same issue (but running in GitLab)

@dbolkensteyn
Copy link

dbolkensteyn commented Feb 17, 2020

This might be the same issue as dotnet/Nerdbank.GitVersioning#174: walking all commits require a full clone of the repository, not a shallow one.

In Travis CI, the shallow clone is disabled with the following YAML configuration:

git:
  depth: false

@ghost
Copy link

ghost commented Feb 18, 2020

However, in my case the code is literally this:

        for commit in git.walk(git.head.target, GIT_SORT_TOPOLOGICAL):
            return commit.message

Is there any other way I could get the message of the latest commit on the current branch?

@dbolkensteyn
Copy link

I am not familiar with the Python bindings of libgit2, but you should be able to peel the head reference to a commit, without having to walk the history. Something like this:

return git.head.peel(pygit2.Commit).message

@jdavid jdavid added the support label Mar 7, 2020
@jdavid
Copy link
Member

jdavid commented Mar 7, 2020

To get the commit's time or message you need to load the object, if the object is not in the database it will fail. This may happen for example with shallow clones and with submodules (see issue #967).

This works as well:

repo.head.peel().commit_time
repo.head.peel().message

In any case be sure to use the latest version of pygit2 1.1.1, or at least 1.0.3

@jdavid jdavid closed this as completed Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants