Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Unable to push file to a remote repository
Unable to push file to a remote repository [message #1779293] Fri, 05 January 2018 01:09 Go to next message
kelly wood is currently offline kelly woodFriend
Messages: 4
Registered: January 2018
Junior Member
I have been following the tutorial getting-started-with-jgit at codeaffine below to create a simple program to push a new file to a remote repository.

The code snippet looks like the ones below. It runs fine without any errors. I can see the file created locally after the file.createNewFile() line. However after the code finishes, the local file disappears, and the remote repo only has a commit message, but not the actual file. I am wondering what I am doing wrong?

String remoteURI = ....;
String localPath = ....;
String localFilePath = localPath + File.seperator + "testfile.txt";
Git git = Git.cloneRepository().setURI( remoteURI ).setDirectory( localPath ).call();
File file = new File(localFilePath);
file.createNewFile();
git.add().addFilePattern( localFilePath ).call();
git.commit().setMessage( "Create readme file" ).call();
git.push().call();
git.close();
Re: Unable to push file to a remote repository [message #1779397 is a reply to message #1779293] Sat, 06 January 2018 04:30 Go to previous messageGo to next message
kelly wood is currently offline kelly woodFriend
Messages: 4
Registered: January 2018
Junior Member
I did some more research and made the following changes to the code, but the file that I m trying to push to the remote repo is still not showing up. I m not sure why it doesn't help. Any tips on how to trouble shoot are appreciated.
...
git.commit().setAll(true).setMessage( "Create readme file" ).call();
git.remoteAdd().setName("origin").setUri(new URIish(remoteURI ).call();
git.push().call();
git.close();
Re: Unable to push file to a remote repository [message #1779415 is a reply to message #1779397] Sat, 06 January 2018 20:28 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1027
Registered: July 2009
Senior Member
Did you check if the commit you created looks ok in your local repository ?

try this:

git.push().setRemote("origin").setRefSpecs(new RefSpec("refs/heads/master:refs/heads/master")).call();
Re: Unable to push file to a remote repository [message #1779463 is a reply to message #1779415] Mon, 08 January 2018 10:24 Go to previous messageGo to next message
Aparna Argade is currently offline Aparna ArgadeFriend
Messages: 43
Registered: October 2010
Member
Today I tried multiple times, but I am also not able to push through egit. Is the same issue getting discussed here?
I'm using ssh. I was able to push my earlier patch set through this workspace, but today, I'm getting this error.
"Session.connect: java.net.SocketException: Connection reset".
'Configure Push->Dry-Run' also gives the same error after showing the progress dialog for 'Trying pushing to remote repositories'.
.log file of workspace reports exception as:
org.eclipse.jgit.errors.TransportException: ssh://user@git.eclipse.org:29418/swtbot/org.eclipse.swtbot: Session.connect: java.net.SocketException: Connection reset
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:172)
at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:137)
at org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init>(TransportGitSsh.java:336)
at org.eclipse.jgit.transport.TransportGitSsh.openPush(TransportGitSsh.java:174)
at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:160)
at org.eclipse.jgit.transport.Transport.push(Transport.java:1310)
at org.eclipse.egit.core.op.PushOperation.run(PushOperation.java:189)
at org.eclipse.egit.ui.internal.push.PushOperationUI.execute(PushOperationUI.java:166)
at org.eclipse.egit.ui.internal.push.SimpleConfigurePushDialog.dryRun(SimpleConfigurePushDialog.java:320)
at org.eclipse.egit.ui.internal.dialogs.AbstractConfigureRemoteDialog.lambda$7(AbstractConfigureRemoteDialog.java:509)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Caused by: com.jcraft.jsch.JSchException: Session.connect: java.net.SocketException: Connection reset
at com.jcraft.jsch.Session.connect(Session.java:565)
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:126)
... 10 more

I don't think that there is any connection problem from my side. Is something at backend changed?
Thanks,
Aparna
Re: Unable to push file to a remote repository [message #1779485 is a reply to message #1779415] Mon, 08 January 2018 14:53 Go to previous message
kelly wood is currently offline kelly woodFriend
Messages: 4
Registered: January 2018
Junior Member
Matthias Sohn wrote on Sat, 06 January 2018 20:28
Did you check if the commit you created looks ok in your local repository ?

try this:

git.push().setRemote("origin").setRefSpecs(new RefSpec("refs/heads/master:refs/heads/master")).call();


You are correct. It turns out the problem is that the new file was not added to the index, and thus not pushed to the remote repo. The problem was solved by changing the line to add a specific file to all files in the current directory:

git.add().addFilePattern( localFilePath ).call();

to:

git.add().addFilePattern( ".").call();

Previous Topic:Authentication problem when connecting to Git in TFS after migrating from JGit 3.2 to 4.1
Next Topic:Pulled conflict file not resolvable
Goto Forum:
  


Current Time: Tue Aug 21 04:04:34 GMT 2018

Powered by FUDForum. Page generated in 0.01680 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top