Skip to content

blame doesn't preserve multi-line commit messages #485

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

Closed
ajaska opened this issue Jul 12, 2016 · 4 comments
Closed

blame doesn't preserve multi-line commit messages #485

ajaska opened this issue Jul 12, 2016 · 4 comments

Comments

@ajaska
Copy link

ajaska commented Jul 12, 2016

The Commit objects returned by blame and blame_incremental only contain the first line of the commit message (the summary).

Obviously, it is harder to return the full commit message because git blame -p only returns the summary.

@Byron
Copy link
Member

Byron commented Jul 13, 2016

When blaming, you will receive BlameEntry objects, which provide you with the Commit object via its .commit field. You should be able to obtain the message via blame_entry.commit.message.
Considering the existence of a suitable workaround, I believe it's ok to close this issue right away. However, if there is anything else, please feel free to comment and possibly get the ticket re-opened (maybe there is a problem I didn't see).

@Byron Byron closed this as completed Jul 13, 2016
@ajaska
Copy link
Author

ajaska commented Jul 13, 2016

Yes, I am referring to those .commit objects.

Here, I made some easy scripts to run to reproduce this. Run the first to set up the git env (in a new directory) and then run the second to see that only the first line of the commit message is displayed.

#!/bin/bash

rm ./some-file
rm -rf ./.git/

git init

echo "this is" >> some-file
echo "some text" >> some-file
git add some-file
git commit -m "Initial commit"

echo "some more text" >> some-file
git add some-file
git commit -m "Commit two summary

More detailed text here
Could be really detailed :)

Blah blah blah"
import git

repo = git.Repo("./")


def get_incremental():
    for blame_entry in repo.blame_incremental('HEAD', 'some-file'):
        if 3 in blame_entry.linenos:
            return blame_entry


def get_non_incremental():
    for commit, lines in repo.blame('HEAD', 'some-file'):
        if 'some more text' in lines:
            return commit


print(get_incremental().commit.message)

print(get_non_incremental().message)

@ajaska
Copy link
Author

ajaska commented Jul 13, 2016

You can see here where Commit objects are being created with code that looks like message = summary :)

message=safe_decode(props[b'summary']))

message=info['summary'])

@Byron Byron reopened this Jul 17, 2016
@Byron Byron added this to the v2.0.8 - Bugfixes milestone Jul 17, 2016
@Byron
Copy link
Member

Byron commented Jul 17, 2016

Thanks for the feedback ! It's clear to me now why this indeed doesn't work as expected.
The Commit object fooled me, and might do so with many others using this API.
The most straightforward solution seems to simply not fill in the summary, as the commit will then lazily fetch the data when queried.

@Byron Byron closed this as completed in 2ff3a3e Jul 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants