Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Issue in Using JGit PullCommand

Hi,

I tried out obtaining the results as follows:

             PullResult result = pullCmd.call();
            System.out.println(result.isSuccessful());

            FetchResult fetchResult = result.getFetchResult();
            MergeResult mergeResult = result.getMergeResult();
            MergeResult.MergeStatus status = mergeResult.getMergeStatus();

            System.out.println(status.name());
            System.out.println(fetchResult.getMessages());


I got the results as pull is successful, and the status name as ALREADY_UP_TO_DATE, and nothing from the fetchResult. I'm baffled how the repository doesn't have all the files as the remote repository, but still says that it is already up to date. Let me briefly explain the directory structure that I have in the remote repository as well:

root ____ README file
  |______ directory_1
  |            |__________ file_2 
  |            |__________ file_3
|_______.git

Currently, my local repo only has the README file . After the pull command, the other directory and the files are not updated in it. However, if I delete the complete tree and get a clone, all the files with the directory structure are reflected in the local repo. Any insight on this is greatly appreciated.

On Fri, Nov 16, 2012 at 11:50 AM, Isuru Haththotuwa <isurulucky@xxxxxxxxx> wrote:
Hi Matthias,

Thank you for the reply. Will try out the suggestions asap.


On Fri, Nov 16, 2012 at 2:16 AM, Matthias Sohn <matthias.sohn@xxxxxxxxxxxxxx> wrote:
2012/11/15 Isuru Haththotuwa <isurulucky@xxxxxxxxx>
Hi All,

I'm trying to use jgit PullCommand to get the functionality equal to svn update. When I use CloneCommand
, a clone of the remote repository is made in the local host. However, when I use the PullCommand, I noticed that the changes in the remote repository are not merged in to the local repository. Is there a proper java sample which shows how to use this command? I could not find such a sample in the jgit documentation as well. I have included the code sample that I used below:


private String localPath;
private Repository localRepo;
private Git git;

localPath = "/home/test/git_repo_test";
remotePath = "https://github.com/test/repo_1.git";

try {
    localRepo = new FileRepository(localPath + "/.git");
} catch (IOException e) {
    e.printStackTrace();  
}
git = new Git(localRepo);

PullCommand pullCmd = git.pull();
try {
    pullCmd.call();
} catch (GitAPIException e) {
    e.printStackTrace();  
}

I use this code after the initial cloning, but any additional files added after the initial clone are not updated in the local repository. Please let me know what is the issue here.

have a look at jgit's PullCommandTest [1] or egit's PullOperation [2] which is using PullCommand.

You should check the result returned by the command in order to get more details about
what's going on. From the PullResult you can obtain the FetchResult which should explain
if you got anything new from the other repository. If the receiving repository has no HEAD or
is in detached HEAD state an exception is thrown. If the current branch in the receiving repository
doesn't track a branch of the upstream repository the current branch will not be changed (see
git branch -- track in [3]).



--
Thanks and Regards,
Isuru




--
Thanks and Regards,
Isuru


Back to the top