gerrit query - get latest commit hash for repo - gerrit

I am using automation to pull always ref/master from the project
Is there an option to query gerrit to have information about last merged commit (getting only HASG also acceptable) ?
Using git log is not an option

Related

Difference between lightweight checkout and shallow clone in Jenkins

In the pipeline SCM configuration of Jenkins job builder, we have two options- lightweight checkout and shallow clone. What is the difference between these options and when do we use each option?
From the documentation:
Shallow clone.
Perform a shallow clone, so that git will not download the history of the project, saving time and disk space when you just want to access the latest version of a repository.
Lightweight checkout.
If selected, try to obtain the Pipeline script contents directly from the SCM without performing a full checkout. The advantage of this mode is its efficiency; however, you will not get any changelogs or polling based on the SCM. (If you use checkout scm during the build, this will populate the changelog and initialize polling.) Also build parameters will not be substituted into SCM configuration in this mode. Only selected SCM plugins support this mode.
To sum up:
Shallow Clone is the Git feature that lets you pull down just the latest commits, not the entire repo history. So if your project has years of history, or history from thousands of commits, you can select a particular depth to pull.
Lightweight checkout is a Jenkins capability that enables to pull a specific file from the repo, as opposed to the entire repo. So it is useful for example when fetching the Jenkinsfile from a repo because you you need only the specific file and Don't care about other SCM information.

Trying to pull updates from remote repo is failling for recently created branch

At work we have to use Bitbucket and to create the new branches we have to use the webpage.
When I do this and try to update my local repo using git pull I can see all the code, commits and even branches created by other users are pulled from remote except for the branch I recently created.
Then I have to keep trying git pull and see the message Already up to date. for 15 or 20 minutes until suddenly the branch is updated.
I was using https to clone the repos and I realized that using SSH started to avoid this issue, but a few weeks later I'm starting to see this issue again with SSH as well.
I'm assuming the issue is related to Bitbucket but I haven't found any info.
Is there a way to avoid this? or maybe a way to force the update?
Try first a git fetch, or even a git ls-remote
The goal for the ls-remote command is to check (right after creating/pushing a new branch) if:
said new branch is immediately listed in the remote tracking branches listed by ls-remote
the associated HEAD SHA1 for that branch is the right commit (the latest pushed on that branch)

Jenkins git plugin query

With Jenkins git plugin, you have options for branch, url and credentials. How do I pass the revision (SHA1), in order to checkout a particular revision of the branch?
https://wiki.jenkins.io/display/JENKINS/Git+Plugin
Thanks.
In general, you can't. The plugin will always fetch and check out references, not commits.
Fetching specific commits by SHA1 is a relatively new feature (see Retrieve specific commit from a remote Git repository); it is not even support by all repository servers.
If you're sure that the SHA1 exists on the branch that has been fetched, then you're free to git reset the working copy in a build step. However, you'd mess with a git clone that's maintained by the git plugin -- so I recommend to take care of the entire clone/fetch/checkout step yourself, not using the git plugin.

How to fetch branches and commits of Git Repo using LibGit2Sharp from network path without a local repository?

Using LibGit2Sharp, how can I fetch the list of all Remote Branches given the repo url ?
I do not have a clone of the repo on the local disk. What's the simplest way to get the list of Branches and once I get the list of branches, I'd like to get the list of Commit Id's in a branch of my choice.
I do see a way to do all this if I have a Git Repo cloned on my local disk but, I don't want to clone it for obtaining this info.
Using LibGit2Sharp, how can I fetch the list of all Remote Branches given the repo url ?
I do not have a clone of the repo on the local disk. What's the simplest way to get the list of Branches
Through LibGit2Sharp, one can read information about the references (mostly branches and tags) of a remote repository, without cloning it. This will retrieve the name of those references and the sha of the commit each one points to.
This can be done through the IEnumerable<Reference> ListRemoteReferences(string url) static method. This is the equivalent of the git ls-remote CLI command.
once I get the list of branches, I'd like to get the list of Commit Id's in a branch of my choice.
Unfortunately, ListRemoteReferences() will only return the tip of each branch. Would you need to enumerate the other commits referenced by this branch, only using LibGit2Sharp, you'll have to locally clone the remote repository.
As an alternative, rather than cloning, once you've got the SHAs of the tips, you could leverage the Commit GitHub API and for each commit, retrieve its parent(s), reapplying recursively the API invocation for each of them. Note that this last option will be far less performant (network I/O, API rate limitting, ...).

Git-Tfs: Pull a TFS changeset into existing git repository

I've got a git repository that was migrated from a TFS repository. There is currently no link between the repositories.
If I use git tfs list-remote-branches {http://...TFSRepo}, I can see the branches in TFS.
What I want to do is be able to pull a TFS changeset into my current git repository -- preferably as a commit, but I'd take just pulling the changes into the current branch.
quick-clone doesn't do what I need as it creates a new git repository (buried in my existing git repository...)
Is is possible to perform a pull of a single TFS changeset using the git-tfs extensions?
There is no way to pull only one changeset in an existing git repository that is not a git-tfs repository.
But you've got 2 possibilities to achieve your goal...
The first is to do a quick-clone in a new repository and then add this repository has a remote and fetch the commit you want.
The second is more tricky, less sure to work because you must understand how git-tfs works.
Amend the last commit to add at the end of the commit message something like that:
git-tfs-id: [https://tfs.codeplex.com:443/tfs/TFS16]$/valtechgittfs/BugMerge;C31467
with :
git-tfs-id: [https://url.tfs.server:/tfs/TeamCollection]$/ProjectName/BranchName;CchangesetId
where you specify as the changeset id, the one of the last changeset before the one you want to fetch. Then, if you have at least the v0.20 of git-tfs, then, fetch changesets...

Resources