Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » JGIt: pulling across directories.(How to for file system operations.)
icon4.gif  JGIt: pulling across directories. [message #1615041] Fri, 13 February 2015 17:12 Go to next message
Pete Kowalsky is currently offline Pete KowalskyFriend
Messages: 2
Registered: February 2015
Junior Member
Guys, I have been checking out some options and its getting a really big headache to do fairly simple operation.

I have a repository A initialized with JGit, all added and commited.

I do same with other repository in directory B.

Now I am trying to pull all changes from A to B.

In command line it is as simple as git pull ../A

With jgit I have set the config:

config.setString("remote", "local", "url", "file://" + uri);

But... it simply fails saying nothing to fetch. CLI normally fetches everything nicely.

Is there any docs explaining what to do? Can anyone help?
Re: JGIt: pulling across directories. [message #1616262 is a reply to message #1615041] Sat, 14 February 2015 12:46 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
Pete,

you can directly specify the URL to repository B in the pull command
like this:
Git git = Git.open( new File( "/path/to/repo-a" ) );
git.pull().setRemote( "/path/to/repo-b" ).call();
git.close();

Does that work for you? Otherwise please share the code that you use to
pull.

- Rüdiger

On 14.02.2015 04:44, Pete Kowalsky wrote:
> Guys, I have been checking out some options and its getting a really big
> headache to do fairly simple operation.
>
> I have a repository A initialized with JGit, all added and commited.
>
> I do same with other repository in directory B.
>
> Now I am trying to pull all changes from A to B.
>
> In command line it is as simple as git pull ../A
>
> With jgit I have set the config:
>
> config.setString("remote", "local", "url", "file://" + uri);
>
> But... it simply fails saying nothing to fetch. CLI normally fetches
> everything nicely.
>
> Is there any docs explaining what to do? Can anyone help?
Re: JGIt: pulling across directories. [message #1619234 is a reply to message #1616262] Mon, 16 February 2015 12:31 Go to previous message
Pete Kowalsky is currently offline Pete KowalskyFriend
Messages: 2
Registered: February 2015
Junior Member
The code that worked was via configuration (no docs to point that out, but luckily git has some):

//uri is absolute FS path
PullCommand p = this.git.pull();
Config config = this.git.getRepository().getConfig();
config.setString("remote", "xxx", "url", "file://" + uri + "");
config.setString("remote", "xxx", "fetch", "+refs/heads/*:refs/remotes/*");
p.setRemote("xxx");
p.setStrategy(MergeStrategy.RECURSIVE).call();


The code I tried is same as you suggested and it was:

PullCommand p = this.git.pull();
p.setRemote(uri);
p.setStrategy(MergeStrategy.RECURSIVE).call();

Exception I receive is:

org.eclipse.jgit.api.errors.InvalidConfigurationException: No value for key remote./Users/peter/bin/repos/out/23423/prod/testrepo.url found in configuration
Fetching and full generating from DB took: 1648ms
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:247)
at versioning.JGit.pull(JGit.java:138)
at Processor.update(Processor.java:139)
at Main.mainCall(Main.java:139)
at Main.main(Main.java:62)

I think much changed from old api which had File option as argument. I like generic config option but... life is easier with default options (that File argument didnt do any harm to have).

Notice that I have two directories, one is initialized and second one too. They dont have remotes and I wanna pull from one to another (very basic). Its not common use case but this practice is useful in some back-end cases.

[Updated on: Mon, 16 February 2015 12:32]

Report message to a moderator

Previous Topic:See the git commands that are executed by the EGit GUI?
Next Topic:Remove project from EGIT
Goto Forum:
  


Current Time: Fri Apr 26 03:26:13 GMT 2024

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

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

Back to the top