Is it possible to apply a patch using libgit2sharp - libgit2sharp

Is it possible to apply a patch using libgit2sharp. I am looking for an equivalent of
git apply --check fix_empty_poster.patch

No, there is not yet a way to apply a patch in LibGit2Sharp.
Some work has begun for patch application in libgit2, but it is not yet complete. Once that gets merged, then the same mechanism can be exposed in LibGit2Sharp.

Related

Delete Patch Set in Gerrit

Is there a way to delete a patch set in Gerrit? I accidentally pushed a file with a password in it to my change. I removed the file in another patch set but the file is still visible in the patch set history. I attempted to find a way to delete that particular patch set but the only thing I could find on how to do this was the following documentation...
https://gerrit-documentation.storage.googleapis.com/Documentation/2.8/cmd-review.html
which shows a delete option but that option is no longer available in later versions.
I ended up just checking out the latest patch set, creating a new branch, deleting the current change in gerrit and pushing the change from the new branch which removes the old patch sets but it seems a bit cumbersome.
No, you can't delete a patch set in Gerrit, but it's possible to delete the whole change. If you do not see the "Delete change" option, it's because you don't have permission to do that.
There are two permissions to control this, see the Gerrit documentation:
Delete Own Changes
Delete Changes
Last but not least, in these cases, it's better to simply change the password instead of trying to remove it from the repository. It's better safe than sorry.

pre-commit check or Remote-run missing with Github setup & Jenkins

Just to quote as an example one can submit a remote-run with some tool like TeamCity (similar to Jenkins) where it will apply delta/patch on what user is trying to commit & produces result whether changes is good from set-of configured checks for that project.
With Github & Jenkins, can such validation be achieved with any plugins out there?, which will avoid breaking a build?
I know with pull-request & status check one can achieve similar end-result. But without commit/push to remote repo of Git - is there a way Jenkins can handle this validation & produce initial result ??
It isn't possible to have GitHub perform checks on data it doesn't have, so if you don't push the data to the remote server, GitHub won't know anything about it and therefore will do nothing.
Jenkins does have a REST API that you could use to do this, provided you equipped each developer with appropriate credentials. However, this is not a common situation and wouldn't be a recommended configuration.
You'd be better off with a script in the repository that users could install as a hook or invoke from a hook that would perform the testing you want. If your CI jobs run a script in your repository, then sharing code between them should be easy.
Note that you shouldn't mandate pre-commit hooks, since they can interfere with advanced users (who may make intentionally incomplete temporary commits) and they can be disabled by users. Any sort of required checks should be done as part of CI, where policy can be enforced appropriately.

Upload patch set preserving existing reviews

We use Jenkins to verify patch sets. Sometimes Jenkins needs do some changes on the patch set. So it commit --amend the changes and then uploads the new patch set.
It work nicely besides the fact, that all manual reviews made to the original patch set get erased.
How can I push a new patch set (from Jenkins) without loosing all existing reviews/votes?
Be aware that, in the situation you have described, you have a new patchset and, excluding in special situations, you don't want votes of the old patchset copied forward to the new patchset. For example: if someone have approved the patchset1 and Jenkins pushes the patchset2, probably he/she doesn't want to have his/her vote automatically copied to patchset2.
Said that: you can control how votes will/won't be copied forward to new patchset setting the label.LABEL-NAME.copyXXXXX options of the project. See more info in Gerrit documentation here.

jenkins plugin to validate patches?

I have seen a few open source projects validate patches before commiting. They would have checks like "does this patch add tests?". I am having a hard time finding a plugin that would let me test a new git patch and validate that it adds what we require to a patch.
What jenkins plugins will let me validate patches before they go into a build?
The best way to do this is to start using Gerrit code review. This together with the Gerrit plugin for Jenkins will make it a breeze to do what you want.

Revert to older patch set version via the Gerrit UI?

If I have multiple patch set versions for one change in Gerrit, it seems like I can only submit the latest patch set version (because only that one has the necessary button). Is there an easy way to instead submit one of the old patch set versions of the same change, using only my web browser on that Gerrit instance?
I know that I can fetch the wanted version of the patch set from my git client and push it as yet another new patch set version on top, but I would like to avoid having identical patch set versions multiple times in the review and discussion around it.
No, sorry, this is not currently possible. The design assumes that the most recent patch set is the one developers will review and test, and as such older patch sets can not be submitted. They also can not be reviewed/verified. If you want to use an older version of a patch set, you must re-submit it to make it the most recent patch set. To avoid no new changes error do git commit --amend and git will create a new sha1, which will be happily accepted by Gerrit as a new patch set.
There is no proper way to do this using only Gerrit UI. Cherry-pick the specific "patch set" of the "change list" (e.g. if there are 15 patch sets in a Change List and want to revert back to patch set #8). Get the cherry-pick command from Gerrit UI for the required patch set.
Run that cherry-pick command, and use git commit --amend, then push your change. It will generate new patch set (for above example #16).
The only way I could do this was as follows (from the change refspec assuming you are in Gerrit revision "<change-no>/3" and want to go back to "<change-no>/1").
git review -d <change no>,1
git commit --amend # modify something in the commit message
git review # resubmit the changes, will submit to rev 1

Resources