Gradle Grgit : push to a specific remote branch - java

I am trying to push the local changes on the master branch to the remote master branch using this library for gradle https://ajoberstar.org/grgit/main/grgit-push.html:
grgit.push(remote:"master",tag:true)
It complains and i get this exception org.eclipse.jgit.errors.NoRemoteRepositoryException master not found how is that possible as master branch does exist at remote.
I even tried the following:
grgit.push(remote:"refs/heads/master",tags:true)
grgit.push(remote:"refs/remotes/origin/master",tags:true)
with no luck and same exception occurred as above.
But when i try with:
grgit.push(branch:all,tags:true)
that works but it pushes to all the branches at remote but that what i don't want. My requirement is to push to the specific branch. Like just master branch only.

Ok i have achieved this by:
grgit.push(refsOrSpecs: ["refs/heads/master": "refs/heads/master" ],tags:true)
does the trick push to remote master branch only.

Related

The git-push command failed

I am facing this problem for a very long now.I am able to ssh clone the repo and commit to the same repo, but when try mvn clean release:clean release:prepare release:perform the build is failing as below.
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] username#github.someCompany.com: Permission denied (publickey).
[ERROR] fatal: Could not read from remote repository.
[ERROR]
[ERROR] Please make sure you have the correct access rights
[ERROR] and the repository exists.
The thing is when I try to mvn clean release:clean release:prepare release:perform it should use git#github.someCompany.com instead of username#github.someCompany.com. Can someone please help me resolve this ?
One workaround to test would be:
git config --global url.git#github.com:.insteadOf username#github.com:
(assuming an SSH URL using : in it)
That way, Git would be forced to use the right user in its SSH URL.
SSH keys let you authenticate with a Git repository without worrying about passwords. SSH is the same method of authentication that Linux servers use to allow remote access.
SSH keys rely on public-private key authentication. For this method of authentication to work, your Git server must be configured with a public key, and your local machine must have the corresponding private key.
Git clients like Atlassian and GitHub require that you upload your public key to their dashboards before you can use SSH authentication.
An Example Scenario
We’ve configured a local repository called ck-git. This repository contains one file: README.md.
We are going to link this repository to one on GitHub. To do this, we can use the git remote command:
git remote add origin git#github.com:career-karma-tutorials/ck-git.git
We have created a remote called “origin” to which we can push our code. To push our local repository to GitHub, we can use the git push command:
git push -u origin master
This command uploads our changes to the master branch on our “origin” remote server. Let’s see what happens when we run the command:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
We have encountered an error.
Solution #1:
Check that your key is used
Before we explore any other solutions, we should make sure that our key is being used to make an SSH connection. We can do this by using the ssh-add command:
eval "$(ssh-agent -s)"
ssh-add -l -E md5
The first command starts the SSH agent on your computer. The next command lists all of the SSH keys that are configured on your machine.
Now that you have this list of SSH keys, check to see if they match the one you’ve uploaded to GitHub, Bitbucket, or another version control system you use. If at least one of the keys on the list does not match, you need to add one of them to your version control system.
Solution #2
: Adding an SSH key
You may encounter this error if you have not yet added an SSH key to your version control account. The way in which you add an SSH key to a Git repository varies depending on the version control system you use.
For GitHub, you can use the following steps:
Note down your SSH key using the commands we discussed in Solution #1
Open GitHub, click on your avatar on the top-right corner and click “Settings”
Click “SSH and GPG keys” in the sidebar
Add an SSH key to your account
To add an SSH key to your account, you must first have a key. You can generate one using the following commands:
ssh-keygen -t rsa -b 4096 -C "email#email.com"
ssh-add -K ~/.ssh-/id_rsa
Substitute “id_rsa” for the name of your key if you changed it when you were prompted to choose a key name from the first command.
Then, run the following command to see your public key:
cat ~/.ssh/id_rsa.pub
This will give you the string you need to upload into your version control system.
Cause #3: Using the wrong method of authentication
We’ve configured our repository to use an SSH URL:
git remote add origin git#github.com:career-karma-tutorials/ck-git.git
Using this URL means we must use SSH authorized key pairs to authenticate with our repository.
This is only possible if we have set up SSH authentication. If you want to configure your repository with HTTP, which lets you use a username and password to authenticate, you must use an HTTP URL:
git remote add origin https://github.com/career-karma-tutorials/ck-git
When we push our code to our remote server, we’ll be asked for our Git username and password. This will give us a chance to authenticate using HTTP instead of SSH.
Conclusion
The “Permission denied (publickey). fatal: Could not read from remote repository” error is caused by an issue with the way in which you authenticate with a Git repository.
To solve this error, make sure your key is being used on your Git account. If it is not, add your key to Git. If you do not have a public key and want to use one to authenticate with Git, you’ll need to create one.
You may want to opt to authenticate using HTTP if you do not want to use SSH. You can do this by using a HTTP URL as the remote URL for your repository.
ref :https://git-scm.com/docs/git-push

Git index file corrupt

I have a project with a gitlab CI for my school project for around 3 months now and never had an issue. But, yesterday morning when I wanted to commit my new code changes and push it to my Gitlab. This worked completely fine, however my CI keeps failing:
In text:
1 Running with gitlab-runner 13.9.0 (2ebc4dc4)
2 on
3 Preparing the "shell" executor
4 Using Shell executor...
6 Preparing environment
7 Running on
9 Getting source from Git repository
10 Fetching changes with git depth set to 50...
11 Reinitialized existing Git repository in
12 Checking out 437a9a83 as master...
13 error: bad signature 0x00000000
14 fatal: index file corrupt
16 Cleaning up file based variables
18 ERROR: Job failed: exit status 1
didn't notice my branch failed so I also merged this with
I was working in a separate branch and didn't notice my branch failed, so I also merged this with my main branch so main isn't working as well.
This is mentioned in gitlab-org/gitlab-runner issue 3290
The Git index file got corrupted causing the build to fail and the runner is not able to recover.
It should be able to handle this by deleting the index file and resetting the repo
As in "How to resolve “Error: bad index – Fatal: index file corrupt” when using Git"
See if the issue persists in a second GitLab pipeline, created for testing, in order to force a new clone of the same repository.

Pull from a remote branch in Jgit with self certificate errors

I have the following code running in a script I am using.
Git git = Git.open(repoLocation);
Repository repo = git.getRepository();
git.checkout()
.setName("feature/test")
.setStartPoint("remotes/origin/feature/test")
.call();
git.pull()
.setRebase(true)
.call();
However, I am unable to pull from the remote feature branch called "test". How do I go about pulling from this remote branch via Jgit?
After stepping through my debugger, I decided to try and manually pull locally. When typing
git pull
in my bash terminal, I get the following error:
fatal: unable to access 'https://username#myCompany.com/path/to/repo.git/': SSL certificate problem: self signed certificate in certificate chain
I now think that this is the root of the error. How do I go about pulling the repo changes locally while still staying secure (the code runs in an applet that is distributed to others - most answers online say to disable SSL verification but I think that won't work).
This tech blog gives the following example on how to deal with branches in Jgit:
// Create a new branch
git.branchCreate().setName("newBranch").call();
// Checkout the new branch
git.checkout().setName("newBranch").call();
// List the existing branches
List<Ref> listRefsBranches = git.branchList().setListMode(ListMode.ALL).call();
for (Ref refBranch : listRefsBranches) {
System.out.println("Branch : " + refBranch.getName());
}
// Go back on "master" branch and remove the created one
git.checkout().setName("master");
git.branchDelete().setBranchNames("newBranch");
Try performing a git.fetch().setRemote("origin").call();, then a git.checkout().setName("newBranch").call(); before doing the git pull and it should work.
My Solution was to use RSA authentication when cloning the repository. It solved my issue. I followed this article on how to use RSA authentication, then adjusted what I needed from there.
Note, that I did use a different URL to clone the repo. Instead of using
https://username#myCompany.com/path/to/repo.git/
I used:
ssh://git#My.Company.Com/PATH/repo.git

heroku nodejs app - events.js:167 Error Unhandled 'error' event : spawn java ENOENT

I'm having a node-js app on Heroku using the pdfMerge.js library.
following the documentation I'm using the stream event mechanism as a callback to identify the end of the process
then an exception is thrown :
events.js:167 Error: spawn java ENOENT.
I'm almost sure it's happening because I'm messing required java installation as described here:
pdfmerger combines multiple PDF-files into a single PDF-file. It is a node module that utilizes the Apache PDFBox Library, which the required functionality are distributed along with this module. The only requirement for this module to run, is having Java 6 or higher in the path.
I'm Not familiar enough with Heroku installation/configuration process in order to make it work.
thanks in advance
You can add Java to your app by adding the heroku/jvm buildpack like this:
$ heroku buildpacks:add -i 1 heroku/jvm
Then redeploy with git commit --allow-empty and git push heroku master.

Error when push Liberty for Java application in IBM Bluemix

when I run sample IBM Bluemix Liberty for Java application https://github.com/ibmjstart/bluemix-java-postgresql-uploader.git following error:
-----> Downloaded app package (1.9M)
-----> Downloaded app buildpack cache (4.0K)
OK
/var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:101:in build_pack': Unable to detect a supported application type (RuntimeError) from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:74:inblock in compile_with_timeout'
from /usr/lib/ruby/1.9.1/timeout.rb:68:in timeout' from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:73:incompile_with_timeout'
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:54:in block in stage_application' from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:50:inchdir'
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:50:in stage_application' from /var/vcap/packages/dea_next/buildpacks/bin/run:10:in'
FAILED
Server error, status code: 400, error code: 170001, message: Staging error: cannot get instances since staging failed
TIP: use 'cf logs jpu-henryhan --recent' for more information
The top error looks like you left off the -p <path_to_war> parameter when doing a push. If you just push a directory containing a WAR file, it will not be detected by the Java buildpack.
The tip provided in the output of your cf push request is relevant.
TIP: use 'cf logs jpu-henryhan --recent' for more information
Running that command will tail the log files produced during the staging process and let you see what error may have been raised. Often, it can be a missing dependency or a transient failure of some sort.
I just successfully deployed the sample using the "deploy to Bluemix" button and manually via the cf command line tool. Unless you changed the code, it is most likely that this error is a transient failure.
Run following command:
$ cf push jpu- -b https://github.com/cloudfoundry/java-buildpack --no-manifest --no-start -p PostgreSQLUpload.war
add the parameter to set the buildpack "-b https://github.com/cloudfoundry/java-buildpack"

Categories