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

Fix git-cherry-pick.rst example. #1268

Merged
merged 1 commit into from
Jan 11, 2024
Merged

Fix git-cherry-pick.rst example. #1268

merged 1 commit into from
Jan 11, 2024

Conversation

herrerog
Copy link
Contributor

Using the parent of the cherry-picked commit as ancestor is not correct sometimes. That looks to be an issue because base was not used at all in the example whereas it should be used as ancestor.

Using the parent of the cherry-picked commit as ancestor is not correct sometimes. That looks to be an issue because `base` was not used at all in the example whereas it should be used as ancestor.
@jdavid jdavid merged commit 3cbf20d into libgit2:master Jan 11, 2024
4 of 6 checks passed
@herrerog
Copy link
Contributor Author

Sorry I got that one wrong actually @jdavid
We should use cherry.parents[0].tree as ancestor otherwise the resulting merge may be wrong.
Here what needs to be used:

repo = pygit2.Repository('/path/to/repo')

cherry = repo.revparse_single('9e044d03c')
basket = repo.branches.get('basket')

base_tree = cherry.parents[0].tree

index = repo.merge_trees(base_tree, basket, cherry)
tree_id = index.write_tree(repo)

author    = cherry.author
committer = pygit2.Signature('Archimedes', '[email protected]')

repo.create_commit(basket.name, author, committer, cherry.message,
                   tree_id, [basket.target])
del None # outdated, prevent from accidentally using it

Let me know if I should send another pull request.

@jdavid
Copy link
Member

jdavid commented Jan 16, 2024

@herrerog Yes please

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.

2 participants