JGit PullCommand Exception - jgit

We are using git to maintain our source. URL like git#xx.xx.xx.xx:XYZ.git. I'm using JGit to pull the changes.
UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider("xxxx", "xxxx");
localPath = "E:\\murugan\\Test\\GIT_LOCALDEPY";
Git git = new Git(localRepo);
PullCommand pcmd = git.pull();
pcmd.setCredentialsProvider(user);
pcmd.call();
I'm getting the following exception when I execute the code.
org.eclipse.jgit.errors.UnsupportedCredentialItem: ssh://git#xx.xx.xx.xx:22:
org.eclipse.jgit.transport.CredentialItem$StringType:Passphrase for C:\Users\Murugan.SOLVER\.ssh\id_rsa

If username/password security is not an issue, you can specify the credentials as part of the connection in the .git/config file of the local Git repo:
[remote "origin"]
url = ssh://<user>:<pwd>#<host>:22/<remote-path-to-repo>/
fetch = +refs/heads/*:refs/remotes/origin/*

You have to configure your SSH parameters on your machine before using Git. Here is a link, from github, for configuring it.
https://help.github.com/categories/56/articles
especially this one: https://help.github.com/articles/generating-ssh-keys
This will help you set up everything properly (you should adapt everything, since you are probably not connecting to GitHub)

Related

with rstudio and github, issue with renamed repo

I had a repository named tags, I renamed it to tag.
I then created a new repository named tags (the old name of the first one).
Now when commiting from R Studio both projects try to commit to the same repository (tags).
I initiated my projects with :
shell("git remote add origin https://github.com/moodymudskipper/tag.git", intern = TRUE)
shell("git push -u origin master",intern = TRUE)
and
shell("git remote add origin https://github.com/moodymudskipper/tags.git",intern = TRUE)
shell("git push -u origin master",intern = TRUE)
And after this I only committed through Rstudio's API and usethis functions, I don't know much more than that about git.
Links to the packages :
https://github.com/moodymudskipper/tag
https://github.com/moodymudskipper/tags
How can I sort this out ?
I'm hesitant to throw this out as an answer, but: you can manually edit the ./.git/config file to update the [remote ...] section to change the remote URL. I have done this confidently enough with an empty repo ...
Check for presence of the tag with grep -rli tags.git .git/*; if all you get is .git/config, then you're good to edit and move on. If you find other files, though, I don't know for certain that they will be updated as you continue with your git remote work. In that case, it might be helpful to look at https://help.github.com/en/articles/changing-a-remotes-url in order to formally change the URL.

How to “git log -S” in JGit

i want to get the changes of a source file with the git command git log -S'hello world'.
It works, but I don't know how to do the same with JGit. The JGit LogCommand has no such option -S.
Here’s a quick example of how to get some log messages:
Git git = new Git(db);
Iterable<RevCommit> log = git.log().call();
UPDATE
Please try to use a modified version of the JGitUtils from the great http://gitblit.com/:
Look at the source of the method getFilesInCommit to see how this can work (PathChangeModel is just used to hold the data.)
also try to read from this tutorial about gitlog in JGIT and dont forget to check properties of gitlog
https://wiki.eclipse.org/JGit/User_Guide#LogCommand_.28git-log.29

Facing Performance issue with JGit add command with big repository

My local repository already has more than 10,000 objects. I am seeing performance issues while using the git.add() command to add one more file to the index. Below is the JGit code snippet which I am using to interface my Java program with Git:
String absoluteLocalGitPath = "c:\\localGitRepo\\.git"
FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder();
repositoryBuilder.setMustExist(true);
repositoryBuilder.setGitDir(new File(absoluteLocalGitPath));
repository = repositoryBuilder.build();
git = new Git(repository);
AddCommand addCommand = git.add();
addCommand.addFilepattern("folder1/obj10001.obj");
addCommand.call();
Here path passed in file pattern is the relative path to c://gitLocalRepo.

Remove local Git repo when working with JGit

I am building a small tool to propose some Git commands to users not familiar with Git. The commands are not intended to modify the repo, just consult some information.
I am creating the tool in Java, using JGit which seems to be the best match to do this kind of stuff.
The issue I face so far is that I create a temporary folder to host the repo content, but I am unable to delete it automatically at the end of the execution.
Here is the code (I removed the try/catch stuff to simplify the reading):
// Create temporary folder
Path folderPath = Paths.get(System.getProperty("user.dir"));
File localRepoFolder = Files.createTempDirectory(folderPath, "local-repo").toFile();
// Clone the repo
CloneCommand clone = new CloneCommand();
clone.setURI("https://myrepo");
clone.setNoCheckout(true);
clone.setDirectory(localRepoFolder);
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider("user", "password"));
Git gitRepo = clone.call();
// Do some stuff
[...]
// Cleanup before closing
gitRepo.getRepository().close();
gitRepo.close();
localRepoFolder.deleteOnExit();
I searched quite a lot on this topic, but I get everywhere that it should be automatically deleted... Am I missing something?
I would use something like Apache Commons IO (http://commons.apache.org/proper/commons-io/) which has a FileUtils.deleteDirectory

Update solr config files in solrcloud

Hi fellow SOLR developers,
https://cwiki.apache.org/confluence/display/solr/Using+ZooKeeper+to+Manage+Configuration+Files This link says the below
To update or change your SolrCloud configuration files:
1. Download the latest configuration files from ZooKeeper, using the
source control checkout process.
2. Make your changes. Commit your changed file to source control.
3. Push the changes back to ZooKeeper.
4. Reload the collection so that the changes will be in effect.
But I was wondering if there are some examples or articles somewhere which can help me do this. For instance, how would one download the latest config files from zookeeper? Or should I know Zoopkeeper in-and-out to do this?
Version 5.3.1
I updated the synonym file in the "C:\12345\solrcloud\solr-5.3.1\example\example-DIH\solr\db\conf" folder and I'm using the below command
zkcli -zkhost localhost:2181,localhost:2182,localhost:2183 -cmd upconfig -confname db_config -confdir "C:\12345\solrcloud\solr-5.3.1\example\example-DIH\solr\db\conf"
But the file doesn't seem to change nor the query seem to work. I reloaded the core which did not help too. I even tried restarting my solrcloud.
My Brother, you are using upconfig command....
Same way there is a command called downconfig with same parameters.
So your order of execution will be :
Downconfig
Change the config
Upconfig
Downconfig command :
bin/solr zk downconfig -z 111.222.333.444:2181 -n mynewconfig -d /path/to/configset
Upconfig command :
bin/solr zk upconfig -z 111.222.333.444:2181 -n mynewconfig -d /path/to/configset
I think this short code can help to download the configs of solrcloud from zookeeper.
public void exportSynonyms(...) {
try {
final CloudSolrClient cloudSolrClient = ... //Retrieve the Solr client
final String configName = cloudSolrClient.getDefaultCollection();
final Path configPath = ... //Get or create temporary local file path
cloudSolrClient.downloadConfig(configName, configPath);
// Do something
cloudSolrClient.uploadConfig(configPath, configName);
// Reload the collection
} catch (RestClientException | SolrServiceException | IOException var11){
this.handleException(var11);
}
}
And I met the same problem and asked it on
https://cwiki.apache.org/confluence/display/solr/Using+ZooKeeper+to+Manage+Configuration+Files?focusedCommentId=65147407#comment-65147407
Hope it can help you.
After you update the file in Zookeeper, you need to tell solr to reload the collection, this tells solr to get the new configuration from Zookeeper.
See the Reload Solr Collection REST call:
https://cwiki.apache.org/confluence/display/solr/Collections+API#CollectionsAPI-api2

Resources