[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Push Result

Thanks for the answer. Here's the solution:

        for (PushResult r : pc.call()) {           
            for(RemoteRefUpdate rru : r.getRemoteUpdates()) {
            if(rru.getStatus() != RemoteRefUpdate.Status.OK && rru.getStatus() != RemoteRefUpdate.Status.UP_TO_DATE) {
            returnValue = "[PUSH-ERROR]" + rru.getStatus().toString();
            break;
            }
            }
        }


Thanks! =)


2011/12/6 Shawn Pearce <spearce@xxxxxxxxxxx>
2011/12/6 Eduardo Falcão <edu.falcao@xxxxxxxxx>:
> I'm trying to push to a repository that is already updated. If I use
> command-line git a "no fast-forward" error is shown. How can I get this
> message using Jgit Api? My code looks like this:
>
>         PushCommand pc = GetRepository().push();
>         pc.add(GetRepository().getRepository().getBranch());
>         pc.setCredentialsProvider(credential);
>
>         for (PushResult r : pc.call()) {
>         System.out.println(r.getMessages());
>         }
>
> But the method getMessages() is not returning the "no fast-forward" message.
> In fact it is returning an empty string...

Look at the PushResult type. I think there is a getResult() that
returns an enum of some sort, the enum tells you a few different
states. The getMessages() method is only for when the enum is the push
failed other reason enum value. There is are special enum case for non
fast forward, force update, etc.

(This is all from memory, I don't have the code open, so I apologize
if the method names aren't exactly correct...)



--
Atenciosamente,

Eduardo Falcão