Skip to content

Add git-cherry-pick recipe #493

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
wants to merge 0 commits into from
Closed

Add git-cherry-pick recipe #493

wants to merge 0 commits into from

Conversation

rmoehn
Copy link
Contributor

@rmoehn rmoehn commented Feb 14, 2015

Add the way that worked for me. Not sure if it is idiomatic.

@jdavid
Copy link
Member

jdavid commented Feb 14, 2015

just merged PR #492 which adds Repository.cherrypick()

@rmoehn
Copy link
Contributor Author

rmoehn commented Feb 15, 2015

Haha, well, that makes it easier then. Does my recipe still have a place somewhere? I mean, it allows for more finegrained control (cherry-pick without checkout) and demonstrates how one could use merge_trees().

@jdavid
Copy link
Member

jdavid commented Feb 15, 2015

Best thing would be to show first the higher level interface, and last the advanced usage.

@carlosmn
Copy link
Member

Note that what you're doing here isn't a cherry-pick but a straight merge. Cherry-pick should have the commit's parent as the merge-base.

@rmoehn
Copy link
Contributor Author

rmoehn commented Feb 16, 2015

Ah ok, good to know. But which commit's parent? The cherry's or the basket's?

So maybe I'll write a section about how to use the new cherry-pick facility, then what I wrote with the merge-base fixed and possibly a note that you can do other strange things. I don't have time for that right now, but will do it next weekend, I guess. So don't delete the pull request yet. :-)

@carlosmn
Copy link
Member

A cherry-pick means applying a commit's (implicit) diff on top the current commit, so you have to get the cherry and its parents to create the diff. It's not too different from git show <cherry> | git apply - (if they accepted the same format).

@rmoehn
Copy link
Contributor Author

rmoehn commented Feb 21, 2015

Hmm, I didn't want to close this. Apparently I messed up things again by force-pushing or something. It would be cool if one could fork one's own repos to try what effects various actions have on pull requests. I could open another account for that…

Anyway, I wrote a recipe with both ways of cherry-picking, but when I try this, my repo remains in cherry-picking mode afterwards:

basket = repo.lookup_branch('basket')
repo.checkout(basket)

cherry = repo.get('17513e5954')
repo.cherrypick(cherry.oid)

if repo.index.conflicts is None:
    tree_id = repo.index.write_tree()

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

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

Am I failing to do something I should do, but which the docs on Repository.cherrypick() don't tell me about?

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.

3 participants