pygit2 icon indicating copy to clipboard operation
pygit2 copied to clipboard

Add commit to recipes

Open techtonik opened this issue 7 years ago • 8 comments

The recipes section doesn't contain commit example. It would be nice to see "empty commit" example and example with some payload there.

https://github.com/sdg-mit/gitless/issues/176

techtonik avatar May 12 '18 23:05 techtonik

Something like: http://www.pygit2.org/objects.html#creating-commits ?

pypingou avatar May 14 '18 10:05 pypingou

Like, but with explanations. If both author and committer are obligatory? What is tree and can I omit that for empty commit? What is this name of reference and can I again skip it?

techtonik avatar May 16 '18 02:05 techtonik

author and committer are mandatory tree is required, just don't change it if you want to do an empty commit (taking a guess here, not tested) the reference is the branch where the commit is, it's mandatory

pypingou avatar May 16 '18 10:05 pypingou

I'm also stuck on the amazingly simple task of making a commit and it's shocking to me that it's not one of the first "recipies."

I've followed that section under creating-commits and as far as I can tell it hasn't actually fully committed my change, so in addition to it not being explained clearly as a recipe, it's also not complete or even correct.

FISHMANPET avatar Sep 30 '19 01:09 FISHMANPET

Something like: http://www.pygit2.org/objects.html#creating-commits ?

sadly, not quite enough. this example results in KeyError or _pygit2.GitError being raised, "the requested type does not match the type in the ODB" or, "failed to create commit: current tip is not the first parent", etc. most of the google results for "pygit2 create commit" are years old and the code doesn't work the same now and prior attempts are often The Wrong Way and result in corrupted repos. further, nearly all of these examples do all the work on the main/master branch and nearly all of them refer to a virgin repository.

how about a few examples reflecting these situations:

totally new, the virgin repository

  1. git init
  2. create branch hotfix/foobar1
  3. create commit
  4. push
  5. checkout main
  6. merge hotfix/foobar

existing repo, new branch

  1. git clone (or pull) (main branch)
  2. create branch hotfix/foobar2
  3. checkout branch hotfix/foobar2
  4. create commit
  5. push
  6. checkout main
  7. merge hotfix/foobar2

existing repo, existing branch with prior commits

  1. git clone (or pull) (main branch)
  2. checkout existing branch (hotfix/foobar3)
  3. git pull
  4. create commit
  5. push
  6. checkout main
  7. merge hotfix/foobar3

FirefighterBlu3 avatar Apr 28 '22 21:04 FirefighterBlu3

I see this recipe was created this February, though I've long since moved on from what I was working on that I needed this so I can't validate if it works, but at least it makes sense as I read it. https://www.pygit2.org/recipes/git-commit.html#

FISHMANPET avatar Apr 29 '22 16:04 FISHMANPET

unfortunately, those recipes don't work except for the starting new repo

FirefighterBlu3 avatar Apr 29 '22 22:04 FirefighterBlu3

commit is added to examples https://www.pygit2.org/recipes/git-commit.html by @skieffer in #1125.

@FirefighterBlu3 do you mean that these recipes don't work with existing repositories? What error do you get? Or what specifically doesn't work for you?

techtonik avatar Dec 11 '22 08:12 techtonik