Using jgit with gitolite for source control, I have an application that generates certain code on command and which we want to be committed to source control. The goal is to pull with a fast forward, commit the new code, and then push it.
I have the following method:
private void commitToGitRepository(String updateComment, Config config)
throws IOException, NoFilepatternException, GitAPIException
{
if(git == null)
{
git = Git.open(new File(config.getDpuCheckoutDir()));
}
PullCommand pull = git.pull();
pull.call();
}
This method fails on the pull.call() method call, with the following exception:
com.jcraft.jsch.JSchException: UnknownHostKey: www.somehost.com. RSA key fingerprint is 9d:92:a9:c5:5d:cb:5f:dc:57:ff:38:7e:34:31:fe:75
at com.jcraft.jsch.Session.checkHost(Session.java:748)
at com.jcraft.jsch.Session.connect(Session.java:319)
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:116)
at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:121)
at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:248)
at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:147)
at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)
at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1104)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:128)
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:245)
at net.intellidata.dpu.controller.schema.EntityMappingController.commitToGitRepository(EntityMappingController.java:149)
... (truncated where it meets my code)
The way I read this, it seems that it's not finding my known_hosts file in user_home/.git. However, I've been searching for an hour and I'm not finding a way to configure JGit to tell JSch where to look for the known_hosts file.
Suggestions? I know the entry for the origin is present in my known_hosts file
This answer mentions:
jsch.setKnownHosts("C:\\Users\\aUsername\\known_hosts");
But you are using jgit, and not jsch (the Java secure shell) directly, so let's see:
C:\Users\VonC\prog\git>git clone https://github.com/eclipse/jgit
Cloning into 'jgit'...
remote: Counting objects: 37854, done.
remote: Compressing objects: 100% (7743/7743), done.
remote: Total 37854 (delta 22009), reused 34367 (delta 18831)
Receiving objects: 100% (37854/37854), 6.73 MiB | 1.37 MiB/s, done.
Resolving deltas: 100% (22009/22009), done.
C:\Users\VonC\prog\git>cd jgit
C:\Users\VonC\prog\git\jgit>grep -nrHI "setKnownHosts" *
org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java:262: sch.setKnownHosts(in);
Found it!
This comes from JschConfigSessionFactory.java#knownHosts(), and looks like:
new File(new File(home, ".ssh"), "known_hosts");
# with:
home = fs.userHome();
userHome is based on System.getProperty("user.home").
So make sure your java session has a user.home defined, and that you have a %USERPROFILE%/.ssh/known_hosts file in there.
(user.home should be set by java to %USERPROFILE% for Windows, that is, if you are on Windows: in some case, this won't always work).
Now if you do have a %USERPROFILE%/.ssh/known_hosts, then, as mentioned here
Just SSH to the client (using command-line ssh tool), this will add entry to your ~/.ssh/known_hosts file.
In this case, the StormeHawke mentions in the comments:
since I'm running this in Tomcat as a windows service, Jsch (and by extension JGit) was looking not in my user folder but in the SYSTEM account's home folder for the .ssh folder.
In this case I went ahead and just copied the .ssh folder into the SYSTEM home folder since Tomcat only runs on my machine for development and testing purposes (Probably not the best security policy but the risk is minimal in this case).
From this question, this one, that directory for the LocalSystem Account should be:
C:\Documents and Settings\Default User
# or Wind7 / 2008
C:\Windows\System32\Config\systemprofile
The OP mentions:
According to this call:
System.out.println(System.getProperty("user.home"));
the default SYSTEM home directory for Windows7 (and presumably any other NT-based Windows system) is simply C:\.
(so not ideal, but for a quick fix, it works).
Related
I tried running the example command on Mac from the command line, but it fails to run. I'm wondering what file is not found. My desktop directory does, in fact, exist. Am I missing some configuration or something?
I just downloaded all the dcm4che-5.12.0 code and sample scripts and executed the command from the example when using the --help option.
The example command is what I tried, and is shown in the attached screenshot. I'm not sure what is missing, and it's not exactly clear.
Any guidance will be appreciated, thanks!
According to the documentation, you have to provide a file and not a directory name to the --dicomdir option (with two "-" by the way):
--dicomdir <file> specify path to a DICOMDIR file of
a DICOM File-set into which
received objects are stored and
from which requested objects are
retrieved
Actually, the example from the documentation reads as follows:
Example: dcmqrscp -b DCMQRSCP:11112 --dicomdir /media/cdrom/DICOMDIR
=> Starts server listening on port 11112, accepting association requests
with DCMQRSCP as called AE title.
I have a file "myFile.gcode" which contains some G-code commands. As it stands Universal Gcode Sender allows the user to upload a file to be executed. However I would like "myFile.gcode" to be run as soon as the program starts up instead of me having to upload it.
Is this possible with the out-of-the-box .jar file?
.jar available at https://winder.github.io/ugs_website/
If not I have the following idea,
Trace through the code and reverse engineer it to auto run the file. To do this I decompiled the .jar file, but when tracing through the code I'm having trouble finding the starting point (main class) of the code.
In summary, is this possible?
And, what could make tracing this code easier?
Yes there is a new feature for running CLI-commands, download the latest nightly build of Universal G-code Sender Classic and run the follwing:
# java -cp UniversalGcodeSender.jar com.willwinder.ugs.cli.TerminalClient --help
This will print the available parameters and options:
-b,--baud <baudrate> Baud rate to connect with.
-c,--controller <controller> What type of controller firmware we are
connecting to, defaults to "GRBL". These
are the available firmwares: [GRBL, TinyG,
Testing (Delay), Smoothie Board, Testing]
-d,--daemon Starts in daemon mode providing a web
pendant UI
-dr,--driver <driver> Sets and saves the connection driver
setting. These are the available drivers:
[JSERIALCOMM, JSSC, TCP]
-f,--file <filename> Opens a file for streaming to controller
and will exit upon completion.
-h,--help Prints the help information.
-ho,--home If a homing process should be done before
any gcode files are sent to the
controller.
-l,--list Lists all available ports.
-p,--port <port> Which port for the controller to connect
to. I.e /dev/ttyUSB0 (on Unix-like systems
or COM4 (on windows).
-pp,--print-progressbar Prints the progress of the file stream
-ps,--print-stream Prints the streamed lines to console
-r,--reset-alarm Resets any alarm
-v,--version Prints the software version.
-w,--workspace <dir> Sets and saves the workspace directory
setting
Sending a file can be done using the following command:
# java -cp UniversalGcodeSender.jar com.willwinder.ugs.cli.TerminalClient --controller GRBL --port /dev/ttyUSB0 --baud 115200 --print-progressbar --file test.gcode
Connected to "Grbl 0.9z" on baud 115200
Running file "test.gcode"
test.gcode 52% │██████████████████████▉ │ 55/105 (0:00:06 / 0:00:05)
On a particular server (Windows 2012 server R2) I am having trouble creating a temp file. I get the following error everytime I try.
java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createTempFile(Unknown Source)
etc..
The error happens everytime the following code is ran:
InputStream inputStream = portalBean.createPDF( sessionID, foCode );
Things I have tried
Changed the java.io.tmpdir variable on the fly. System.setProperty("java.io.tmpdir", "C:\\");
Added -Djava.io.tmpdir=c:\\temp to the webnetwork lax file to an unrestricted location.
I tried setting the webNetwork service to run as a specified user with rights to temp files e.g. the Administrator.
Made sure I have free disk space and I cleaned out the c:\windows\temp folder.
Made sure the tmp environment variables were set to their default values.
I also tried running the service from a command prompt which was opened with the Run As Administrator option.
And the IOException lingers still. I have another server running the same code without issue (Windows Server 2012).
Does anyone else have any Ideas of what else I can try to resolve this issue? And or any tips on how I can debug the issue more thoroughly to get a grasp of what is going on?
One tool you can use to debug this is process monitor from system internal tool kit. The step is: add a filter to only monitor your process (I think it is javaw.exe in your case), after the error happens, go through the file activities in the process monitor log, you can find how the process is finding files and which directories the process searched. If the process is searching in the wrong directory, you can find it from the log.
I just used this tool to figure out a JVM crash problem today.
Based on the description of your problem, I guess the path variable of the process is changed in the middle of your code, with another tool process explore you can view the path variable of the process, it might help.
Try and create instead a directory somewhere under your home directory:
final Path tmpdir = Paths.get(System.getProperty("user.home"), "tmp");
Files.createDirectories(tmpdir);
System.setProperty("java.io.tmpdir", tmpdir.toAbsolutePath().toString());
Then try and Files.createTempFile() in there.
Note that if Files.createDirectories() refers to an existing file which is not a directory, you'll get a FileAlreadyExistsException.
I am using HawtIo war in my code. When I run this code in local, it works fine, but on unix box I get the following exception:
Failed to pull from remote repo io.hawt.git.RuntimeIOException: org.eclipse.jgit.api.errors.JGitInternalException: Stashing local changes did not successfully complete: io.hawt.git.RuntimeIOException: org.eclipse.jgit.api.errors.JGitInternalException: Stashing local changes did not successfully complete
at io.hawt.git.GitFacade.gitOperation(GitFacade.java:737)
at io.hawt.git.GitFacade$2.run(GitFacade.java:108)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: org.eclipse.jgit.api.errors.JGitInternalException: Stashing local changes did not successfully complete
at org.eclipse.jgit.api.StashCreateCommand.call(StashCreateCommand.java:327)
at io.hawt.git.GitFacade.gitOperation(GitFacade.java:730)
... 3 more
Caused by: org.eclipse.jgit.errors.LockFailedException: Cannot lock /remote/projusers/aptdevjboss/.hawtio/config/.git/index
at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:224)
at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:301)
at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:267)
at org.eclipse.jgit.lib.Repository.lockDirCache(Repository.java:1051)
at org.eclipse.jgit.api.StashCreateCommand.call(StashCreateCommand.java:225)
... 4 more
Please tell me what am I missing?
Also most likely what's happening is your home directory is on an NFS (or other distributed filesystem) share that doesn't support distributed locks, which is common enough.
You may want to set hawtio.config.dir to point to a local filesystem location that your user account has read/write permissions for. You can set this either via a blueprint.properties file or building a custom hawtio-web.war with this parameter set as per our configuration guide.
The configuration guide for hawtio is at http://hawt.io/configuration/index.html
Try with below command:
rm -f ./.git/index.lock
below link might helpful.
Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists
Hawtio tries to copy a git repo for showing things in Dashboards and Wiki tabs. You are probably facing a permissions issue in /remote/projusers/aptdevjboss/.hawtio/config/.git/index.
Also, If you don't want to copy the git repo everytime you start hawtio, there is a offline version you can download: https://oss.sonatype.org/content/repositories/public/io/hawt/hawtio-default-offline/1.2.1/hawtio-default-offline-1.2.1.war
I previously worked on a project in Ruby on Rails using Vagrant as development environment. After I finished the project, I started to work in a project in Java, but when i try to clone the project into my workspace, i'm getting this error on Git Bash console:
git clone git#git.address.com:mari/project.git
Cloning into 'project'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:763:in 'initialize': No route to host - connect(2) (Errno::EHOSUNREACH)
from /usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:763:in 'open'
from /usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:763:in 'block in connect'
from /usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:55:in 'timeout'
from /usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:100:in 'timeout'
from /usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:763:in 'connect'
from /usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:756:in 'do_start'
from /usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:745:in 'start'
from /opt/git/gitlab-shell/lib/gitlab_net.rb:56:in 'get'
from /opt/git/gitlab-shell/lib/gitlab_net.rb:17:in 'allowed?'
from /opt/git/gitlab-shell/lib/gitlab_net.rb:51:in 'validate_access'
from /opt/git/gitlab-shell/lib/gitlab_net.rb:21:in 'exec'
from /opt/git/gitlab-shell/lib/gitlab_net.rb:16:in '<main>'
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
NOTE: I've tried this solution (Change the URI (URL) for a remote Git repository) and didn't work. Any idea what might be happening?
EDIT: I'm using Windows, but the VM used on Vagrant is Linux.
Try adding the protocol to the beginning of the remote url:
ssh://git#git.address.com/mari/project.git
Also don't use a : to seperate path and uri, but use a / instead.
Of course, you can use another protocol as ssh.
try git remote url like this
http://<username>#git.address.com/<path>.git